Fix #2958 - Add checkbox to fill remaining bytes with nops. (#2974)

This commit is contained in:
Giovanni 2022-06-23 01:44:25 +02:00 committed by GitHub
parent e60ba18e43
commit f99ffc3dbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 8 deletions

View File

@ -762,10 +762,14 @@ QString CutterCore::getInstructionOpcode(RVA addr)
return fromOwnedCharPtr(ret);
}
void CutterCore::editInstruction(RVA addr, const QString &inst)
void CutterCore::editInstruction(RVA addr, const QString &inst, bool fillWithNops)
{
CORE_LOCK();
rz_core_write_assembly(core, addr, inst.trimmed().toStdString().c_str());
if (fillWithNops) {
rz_core_write_assembly_fill(core, addr, inst.trimmed().toStdString().c_str());
} else {
rz_core_write_assembly(core, addr, inst.trimmed().toStdString().c_str());
}
emit instructionChanged(addr);
}

View File

@ -259,7 +259,7 @@ public:
/* Edition functions */
QString getInstructionBytes(RVA addr);
QString getInstructionOpcode(RVA addr);
void editInstruction(RVA addr, const QString &inst);
void editInstruction(RVA addr, const QString &inst, bool fillWithNops = false);
void nopInstruction(RVA addr);
void jmpReverse(RVA addr);
void editBytes(RVA addr, const QString &inst);

View File

@ -2,12 +2,20 @@
#include "ui_EditInstructionDialog.h"
#include "core/Cutter.h"
#include <QCheckBox>
EditInstructionDialog::EditInstructionDialog(InstructionEditMode editMode, QWidget *parent)
: QDialog(parent), ui(new Ui::EditInstructionDialog), editMode(editMode)
{
ui->setupUi(this);
ui->lineEdit->setMinimumWidth(400);
ui->instructionLabel->setWordWrap(true);
if (editMode == EDIT_TEXT) {
ui->fillWithNops->setVisible(true);
ui->fillWithNops->setCheckState(Qt::Checked);
} else {
ui->fillWithNops->setVisible(false);
}
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
connect(ui->lineEdit, &QLineEdit::textEdited, this, &EditInstructionDialog::updatePreview);
@ -22,6 +30,15 @@ void EditInstructionDialog::on_buttonBox_rejected()
close();
}
bool EditInstructionDialog::needsNops() const
{
if (editMode != EDIT_TEXT) {
return false;
}
return ui->fillWithNops->checkState() == Qt::Checked;
}
QString EditInstructionDialog::getInstruction() const
{
return ui->lineEdit->text();

View File

@ -20,18 +20,18 @@ public:
QString getInstruction() const;
void setInstruction(const QString &instruction);
bool needsNops() const;
private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void updatePreview(const QString &input);
private:
std::unique_ptr<Ui::EditInstructionDialog> ui;
InstructionEditMode
editMode; // true if editing intruction **bytes**; false if editing instruction **text**
// defines if the user is editing bytes or asm
InstructionEditMode editMode;
};
#endif // EDITINSTRUCTIONDIALOG_H

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>118</height>
<height>151</height>
</rect>
</property>
<property name="windowTitle">
@ -37,6 +37,18 @@
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
@ -82,6 +94,16 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="fillWithNops">
<property name="text">
<string>Fill all remaining bytes with NOP opcodes</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_1">
<property name="orientation">

View File

@ -708,9 +708,10 @@ void DisassemblyContextMenu::on_actionEditInstruction_triggered()
e.setInstruction(oldInstructionOpcode);
if (e.exec()) {
bool fillWithNops = e.needsNops();
QString userInstructionOpcode = e.getInstruction();
if (userInstructionOpcode != oldInstructionOpcode) {
Core()->editInstruction(offset, userInstructionOpcode);
Core()->editInstruction(offset, userInstructionOpcode, fillWithNops);
}
}
}