From 3ef8218e4968e195f872d938970bd6b9548e3efd Mon Sep 17 00:00:00 2001 From: fcasal Date: Sat, 10 Mar 2018 07:27:09 +0000 Subject: [PATCH] Added option to swap conditional jmps (#373) --- src/Cutter.cpp | 6 +++++ src/Cutter.h | 1 + src/menus/DisassemblyContextMenu.cpp | 36 +++++++++++++++++++++++++++- src/menus/DisassemblyContextMenu.h | 3 +++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 5b66eca8..0af28336 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -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)); diff --git a/src/Cutter.h b/src/Cutter.h index b6eb0b02..db988b27 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -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); diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index 8564516c..78a9633d 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -14,7 +14,8 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent) offset(0), canCopy(false), actionEditInstruction(this), - actionNopInstruction(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); diff --git a/src/menus/DisassemblyContextMenu.h b/src/menus/DisassemblyContextMenu.h index 4c3e3dfc..302881ef 100644 --- a/src/menus/DisassemblyContextMenu.h +++ b/src/menus/DisassemblyContextMenu.h @@ -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;