Added option to swap conditional jmps (#373)

This commit is contained in:
fcasal 2018-03-10 07:27:09 +00:00 committed by xarkes
parent 742690afd0
commit 3ef8218e49
4 changed files with 45 additions and 1 deletions

View File

@ -335,6 +335,12 @@ void CutterCore::nopInstruction(RVA addr)
emit instructionChanged(addr);
}
void CutterCore::jmpReverse(RVA addr)
{
cmd("wao recj @ " + RAddressString(addr));
emit instructionChanged(addr);
}
void CutterCore::editBytes(RVA addr, const QString &bytes)
{
cmd("wx " + bytes + " @ " + RAddressString(addr));

View File

@ -296,6 +296,7 @@ public:
void editInstruction(RVA addr, const QString &inst);
void nopInstruction(RVA addr);
void jmpReverse(RVA addr);
void editBytes(RVA addr, const QString &inst);

View File

@ -15,6 +15,7 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
canCopy(false),
actionEditInstruction(this),
actionNopInstruction(this),
actionJmpReverse(this),
actionEditBytes(this),
actionCopy(this),
actionAddComment(this),
@ -92,10 +93,13 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
editMenu->addAction(&actionNopInstruction);
actionEditBytes.setText(tr("Bytes"));
editMenu->addAction(&actionEditBytes);
actionJmpReverse.setText(tr("Reverse Jump"));
editMenu->addAction(&actionJmpReverse);
connect(&actionEditInstruction, SIGNAL(triggered(bool)), this, SLOT(on_actionEditInstruction_triggered()));
connect(&actionNopInstruction, SIGNAL(triggered(bool)), this, SLOT(on_actionNopInstruction_triggered()));
connect(&actionEditBytes, SIGNAL(triggered(bool)), this, SLOT(on_actionEditBytes_triggered()));
connect(&actionJmpReverse, SIGNAL(triggered(bool)), this, SLOT(on_actionJmpReverse_triggered()));
connect(&actionSetBaseBinary, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseBinary_triggered()));
connect(&actionSetBaseOctal, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseOctal_triggered()));
@ -202,6 +206,10 @@ void DisassemblyContextMenu::aboutToShowSlot()
{
actionRenameUsedHere.setVisible(false);
}
// decide to show Reverse jmp option
showReverseJmpQuery();
}
QKeySequence DisassemblyContextMenu::getCopySequence() const
@ -262,6 +270,32 @@ void DisassemblyContextMenu::on_actionNopInstruction_triggered()
Core()->nopInstruction(offset);
}
void DisassemblyContextMenu::showReverseJmpQuery()
{
QString type;
QJsonArray array = Core()->cmdj("pdj 1 @ " + RAddressString(offset)).array();
if (array.isEmpty())
{
return;
}
type = array.first().toObject()["type"].toString();
if (type == "cjmp")
{
actionJmpReverse.setVisible(true);
}
else
{
actionJmpReverse.setVisible(false);
}
}
void DisassemblyContextMenu::on_actionJmpReverse_triggered()
{
Core()->jmpReverse(offset);
}
void DisassemblyContextMenu::on_actionEditBytes_triggered()
{
EditInstructionDialog *e = new EditInstructionDialog(this);

View File

@ -25,6 +25,8 @@ private slots:
void on_actionEditInstruction_triggered();
void on_actionNopInstruction_triggered();
void on_actionJmpReverse_triggered();
void showReverseJmpQuery();
void on_actionEditBytes_triggered();
void on_actionCopy_triggered();
@ -72,6 +74,7 @@ private:
QAction *editMenuAction;
QAction actionEditInstruction;
QAction actionNopInstruction;
QAction actionJmpReverse;
QAction actionEditBytes;
QAction actionCopy;