diff --git a/src/widgets/HexWidget.cpp b/src/widgets/HexWidget.cpp index 784528a9..a3e0ae46 100644 --- a/src/widgets/HexWidget.cpp +++ b/src/widgets/HexWidget.cpp @@ -147,7 +147,11 @@ HexWidget::HexWidget(QWidget *parent) connect(actionWrite64, &QAction::triggered, this, &HexWidget::w_write64); actionsWriteString.append(actionWrite64); - actionsWriteOther.reserve(4); + actionsWriteOther.reserve(5); + QAction *actionWriteBytes = new QAction(tr("Write hex bytes"), this); + connect(actionWriteBytes, &QAction::triggered, this, &HexWidget::w_writeBytes); + actionsWriteOther.append(actionWriteBytes); + QAction *actionWriteZeros = new QAction(tr("Write zeros"), this); connect(actionWriteZeros, &QAction::triggered, this, &HexWidget::w_writeZeros); actionsWriteOther.append(actionWriteZeros); @@ -730,6 +734,41 @@ void HexWidget::w_increaseDecrease() refresh(); } +void HexWidget::w_writeBytes() +{ + if (!ioModesController.prepareForWriting()) { + return; + } + bool ok = false; + + int size = INT_MAX; + if (!selection.isEmpty() && selection.size() <= INT_MAX) { + size = static_cast(selection.size()); + } + + QInputDialog d; + d.setInputMode(QInputDialog::InputMode::TextInput); + QByteArray bytes = d.getText(this, tr("Write hex bytes"), tr("Hex byte string:"), + QLineEdit::Normal, "", &ok) + .toUtf8(); + const int offset = bytes.startsWith("\\x") ? 2 : 0; + const int incr = offset + 2; + const int bytes_size = qMin(bytes.size() / incr, size); + if (ok && bytes_size) { + uint8_t *buf = (uint8_t *)malloc(static_cast(bytes_size)); + if (!buf) { + return; + } + for (int i = 0, j = 0, sz = bytes.size(); i < sz; i += incr, j++) { + buf[j] = static_cast(bytes.mid(i + offset, 2).toInt(nullptr, 16)); + } + RzCoreLocked core(Core()); + rz_core_write_at(core, getLocationAddress(), buf, bytes_size); + free(buf); + refresh(); + } +} + void HexWidget::w_writeZeros() { if (!ioModesController.prepareForWriting()) { diff --git a/src/widgets/HexWidget.h b/src/widgets/HexWidget.h index 1489ef85..5a6a15f0 100644 --- a/src/widgets/HexWidget.h +++ b/src/widgets/HexWidget.h @@ -315,6 +315,7 @@ private slots: // Write command slots void w_writeString(); void w_increaseDecrease(); + void w_writeBytes(); void w_writeZeros(); void w_write64(); void w_writeRandom();