mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Hexeditor: add option to write hex bytes
This commit is contained in:
parent
72ab12a23d
commit
15282d9bc5
@ -147,7 +147,11 @@ HexWidget::HexWidget(QWidget *parent)
|
|||||||
connect(actionWrite64, &QAction::triggered, this, &HexWidget::w_write64);
|
connect(actionWrite64, &QAction::triggered, this, &HexWidget::w_write64);
|
||||||
actionsWriteString.append(actionWrite64);
|
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);
|
QAction *actionWriteZeros = new QAction(tr("Write zeros"), this);
|
||||||
connect(actionWriteZeros, &QAction::triggered, this, &HexWidget::w_writeZeros);
|
connect(actionWriteZeros, &QAction::triggered, this, &HexWidget::w_writeZeros);
|
||||||
actionsWriteOther.append(actionWriteZeros);
|
actionsWriteOther.append(actionWriteZeros);
|
||||||
@ -730,6 +734,41 @@ void HexWidget::w_increaseDecrease()
|
|||||||
refresh();
|
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<int>(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<size_t>(bytes_size));
|
||||||
|
if (!buf) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0, j = 0, sz = bytes.size(); i < sz; i += incr, j++) {
|
||||||
|
buf[j] = static_cast<uint8_t>(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()
|
void HexWidget::w_writeZeros()
|
||||||
{
|
{
|
||||||
if (!ioModesController.prepareForWriting()) {
|
if (!ioModesController.prepareForWriting()) {
|
||||||
|
@ -315,6 +315,7 @@ private slots:
|
|||||||
// Write command slots
|
// Write command slots
|
||||||
void w_writeString();
|
void w_writeString();
|
||||||
void w_increaseDecrease();
|
void w_increaseDecrease();
|
||||||
|
void w_writeBytes();
|
||||||
void w_writeZeros();
|
void w_writeZeros();
|
||||||
void w_write64();
|
void w_write64();
|
||||||
void w_writeRandom();
|
void w_writeRandom();
|
||||||
|
Loading…
Reference in New Issue
Block a user