From 84049e8ae0cfaa4fe707f02c5ec614fb83988d07 Mon Sep 17 00:00:00 2001 From: plaets Date: Tue, 22 Sep 2020 20:45:55 +0200 Subject: [PATCH 1/8] Add a "Toggle immediate base" hotkey --- src/core/Cutter.cpp | 6 ++++++ src/core/Cutter.h | 1 + src/menus/DisassemblyContextMenu.cpp | 20 ++++++++++++++++++++ src/menus/DisassemblyContextMenu.h | 4 ++++ 4 files changed, 31 insertions(+) diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 6ade8e806..6f53f833d 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -842,6 +842,12 @@ void CutterCore::setImmediateBase(const QString &r2BaseName, RVA offset) emit instructionChanged(offset); } +int CutterCore::getImmediateBase(RVA offset) +{ + QJsonValue result = this->cmdj(QString("ahj %1").arg(offset)).array().first(); + return result["immbase"].toInt(); +} + void CutterCore::setCurrentBits(int bits, RVA offset) { if (offset == RVA_INVALID) { diff --git a/src/core/Cutter.h b/src/core/Cutter.h index 790a648f9..604a696d6 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -232,6 +232,7 @@ class CUTTER_EXPORT CutterCore: public QObject void delComment(RVA addr); QString getCommentAt(RVA addr); void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID); + int getImmediateBase(RVA offset = RVA_INVALID); void setCurrentBits(int bits, RVA offset = RVA_INVALID); /** diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index f5fc4da3a..60a9ac3cd 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -125,6 +125,10 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *main addSetBaseMenu(); + initAction(&actionToggleBase, tr("Toggle Immediate Base (Hex/Dec)"), + SLOT(on_actionToggleBase_triggered()), getToggleBaseSequence()); + addAction(&actionToggleBase); + addSetBitsMenu(); structureOffsetMenu = addMenu(tr("Structure offset")); @@ -674,6 +678,11 @@ QKeySequence DisassemblyContextMenu::getUndefineFunctionSequence() const return {Qt::Key_U}; } +QKeySequence DisassemblyContextMenu::getToggleBaseSequence() const +{ + return {Qt::Key_H}; +} + void DisassemblyContextMenu::on_actionEditInstruction_triggered() { @@ -803,6 +812,17 @@ void DisassemblyContextMenu::on_actionAnalyzeFunction_triggered() } } +// TODO: requires the user to trigger the action twice if the number is in decimals +void DisassemblyContextMenu::on_actionToggleBase_triggered() +{ + int base = Core()->getImmediateBase(offset); + if (base == 10) { + setBase("h"); + } else { + setBase("d"); + } +} + void DisassemblyContextMenu::on_actionAddFlag_triggered() { FlagDialog dialog(offset, this->parentWidget()); diff --git a/src/menus/DisassemblyContextMenu.h b/src/menus/DisassemblyContextMenu.h index bfffe9128..6bd034c53 100644 --- a/src/menus/DisassemblyContextMenu.h +++ b/src/menus/DisassemblyContextMenu.h @@ -68,6 +68,8 @@ private slots: void on_actionSetToData_triggered(); void on_actionSetToDataEx_triggered(); + void on_actionToggleBase_triggered(); + /** * @brief Executed on selecting an offset from the structureOffsetMenu * Uses the applyStructureOffset() function of CutterCore to apply the @@ -101,6 +103,7 @@ private slots: QKeySequence getDefineNewFunctionSequence() const; QKeySequence getUndefineFunctionSequence() const; QKeySequence getEditFunctionSequence() const; + QKeySequence getToggleBaseSequence() const; QList getAddBPSequence() const; /** @@ -156,6 +159,7 @@ private slots: QAction actionSetBaseIPAddr; QAction actionSetBaseSyscall; QAction actionSetBaseString; + QAction actionToggleBase; QMenu *setBitsMenu; QAction actionSetBits16; From 1473d2f2bab98cfcf2107d5985808473d4e538c0 Mon Sep 17 00:00:00 2001 From: plaets Date: Wed, 23 Sep 2020 12:49:14 +0200 Subject: [PATCH 2/8] Move the toggle immediate base handling to DisassemblyWidget.cpp (Removes the entry from the context menu) --- src/menus/DisassemblyContextMenu.cpp | 20 -------------------- src/menus/DisassemblyContextMenu.h | 4 ---- src/widgets/DisassemblyWidget.cpp | 23 +++++++++++++++++++++++ src/widgets/DisassemblyWidget.h | 2 ++ 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index 60a9ac3cd..f5fc4da3a 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -125,10 +125,6 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *main addSetBaseMenu(); - initAction(&actionToggleBase, tr("Toggle Immediate Base (Hex/Dec)"), - SLOT(on_actionToggleBase_triggered()), getToggleBaseSequence()); - addAction(&actionToggleBase); - addSetBitsMenu(); structureOffsetMenu = addMenu(tr("Structure offset")); @@ -678,11 +674,6 @@ QKeySequence DisassemblyContextMenu::getUndefineFunctionSequence() const return {Qt::Key_U}; } -QKeySequence DisassemblyContextMenu::getToggleBaseSequence() const -{ - return {Qt::Key_H}; -} - void DisassemblyContextMenu::on_actionEditInstruction_triggered() { @@ -812,17 +803,6 @@ void DisassemblyContextMenu::on_actionAnalyzeFunction_triggered() } } -// TODO: requires the user to trigger the action twice if the number is in decimals -void DisassemblyContextMenu::on_actionToggleBase_triggered() -{ - int base = Core()->getImmediateBase(offset); - if (base == 10) { - setBase("h"); - } else { - setBase("d"); - } -} - void DisassemblyContextMenu::on_actionAddFlag_triggered() { FlagDialog dialog(offset, this->parentWidget()); diff --git a/src/menus/DisassemblyContextMenu.h b/src/menus/DisassemblyContextMenu.h index 6bd034c53..bfffe9128 100644 --- a/src/menus/DisassemblyContextMenu.h +++ b/src/menus/DisassemblyContextMenu.h @@ -68,8 +68,6 @@ private slots: void on_actionSetToData_triggered(); void on_actionSetToDataEx_triggered(); - void on_actionToggleBase_triggered(); - /** * @brief Executed on selecting an offset from the structureOffsetMenu * Uses the applyStructureOffset() function of CutterCore to apply the @@ -103,7 +101,6 @@ private slots: QKeySequence getDefineNewFunctionSequence() const; QKeySequence getUndefineFunctionSequence() const; QKeySequence getEditFunctionSequence() const; - QKeySequence getToggleBaseSequence() const; QList getAddBPSequence() const; /** @@ -159,7 +156,6 @@ private slots: QAction actionSetBaseIPAddr; QAction actionSetBaseSyscall; QAction actionSetBaseString; - QAction actionToggleBase; QMenu *setBitsMenu; QAction actionSetBits16; diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index f76917a1b..63695576a 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -202,6 +202,10 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main) ADD_ACTION(QKeySequence::MoveToPreviousPage, Qt::WidgetWithChildrenShortcut, [this]() { moveCursorRelative(true, true); }) + + ADD_ACTION(Qt::Key_H, Qt::WidgetWithChildrenShortcut, [this]() { + toggleBase(); + }) #undef ADD_ACTION } @@ -623,6 +627,25 @@ void DisassemblyWidget::jumpToOffsetUnderCursor(const QTextCursor &cursor) seekable->seekToReference(offset); } +// TODO: requires the user to trigger the action twice if the number is in decimals +void DisassemblyWidget::toggleBase() +{ + RVA offset = readCurrentDisassemblyOffset(); + QJsonObject instObject = Core()->cmdj("aoj @ " + QString::number( + offset)).array().first().toObject(); + auto keys = instObject.keys(); + bool immBase = keys.contains("val") || keys.contains("ptr"); + + if(immBase) { + int base = Core()->getImmediateBase(offset); + if (base == 10) { + Core()->setImmediateBase("h", offset); + } else { + Core()->setImmediateBase("d", offset); + } + } +} + bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::MouseButtonDblClick diff --git a/src/widgets/DisassemblyWidget.h b/src/widgets/DisassemblyWidget.h index 36aaf3ec1..9b9f7e0a6 100644 --- a/src/widgets/DisassemblyWidget.h +++ b/src/widgets/DisassemblyWidget.h @@ -88,6 +88,8 @@ protected slots: void moveCursorRelative(bool up, bool page); void jumpToOffsetUnderCursor(const QTextCursor&); + + void toggleBase(); }; class DisassemblyScrollArea : public QAbstractScrollArea From e16ac0f8d362b10e80591b32947342f1d239a0ad Mon Sep 17 00:00:00 2001 From: plaets Date: Wed, 23 Sep 2020 15:48:25 +0200 Subject: [PATCH 3/8] Revert "Move the toggle immediate base handling to DisassemblyWidget.cpp" This reverts commit 1473d2f2bab98cfcf2107d5985808473d4e538c0. --- src/menus/DisassemblyContextMenu.cpp | 20 ++++++++++++++++++++ src/menus/DisassemblyContextMenu.h | 4 ++++ src/widgets/DisassemblyWidget.cpp | 23 ----------------------- src/widgets/DisassemblyWidget.h | 2 -- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index f5fc4da3a..60a9ac3cd 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -125,6 +125,10 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *main addSetBaseMenu(); + initAction(&actionToggleBase, tr("Toggle Immediate Base (Hex/Dec)"), + SLOT(on_actionToggleBase_triggered()), getToggleBaseSequence()); + addAction(&actionToggleBase); + addSetBitsMenu(); structureOffsetMenu = addMenu(tr("Structure offset")); @@ -674,6 +678,11 @@ QKeySequence DisassemblyContextMenu::getUndefineFunctionSequence() const return {Qt::Key_U}; } +QKeySequence DisassemblyContextMenu::getToggleBaseSequence() const +{ + return {Qt::Key_H}; +} + void DisassemblyContextMenu::on_actionEditInstruction_triggered() { @@ -803,6 +812,17 @@ void DisassemblyContextMenu::on_actionAnalyzeFunction_triggered() } } +// TODO: requires the user to trigger the action twice if the number is in decimals +void DisassemblyContextMenu::on_actionToggleBase_triggered() +{ + int base = Core()->getImmediateBase(offset); + if (base == 10) { + setBase("h"); + } else { + setBase("d"); + } +} + void DisassemblyContextMenu::on_actionAddFlag_triggered() { FlagDialog dialog(offset, this->parentWidget()); diff --git a/src/menus/DisassemblyContextMenu.h b/src/menus/DisassemblyContextMenu.h index bfffe9128..6bd034c53 100644 --- a/src/menus/DisassemblyContextMenu.h +++ b/src/menus/DisassemblyContextMenu.h @@ -68,6 +68,8 @@ private slots: void on_actionSetToData_triggered(); void on_actionSetToDataEx_triggered(); + void on_actionToggleBase_triggered(); + /** * @brief Executed on selecting an offset from the structureOffsetMenu * Uses the applyStructureOffset() function of CutterCore to apply the @@ -101,6 +103,7 @@ private slots: QKeySequence getDefineNewFunctionSequence() const; QKeySequence getUndefineFunctionSequence() const; QKeySequence getEditFunctionSequence() const; + QKeySequence getToggleBaseSequence() const; QList getAddBPSequence() const; /** @@ -156,6 +159,7 @@ private slots: QAction actionSetBaseIPAddr; QAction actionSetBaseSyscall; QAction actionSetBaseString; + QAction actionToggleBase; QMenu *setBitsMenu; QAction actionSetBits16; diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index 63695576a..f76917a1b 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -202,10 +202,6 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main) ADD_ACTION(QKeySequence::MoveToPreviousPage, Qt::WidgetWithChildrenShortcut, [this]() { moveCursorRelative(true, true); }) - - ADD_ACTION(Qt::Key_H, Qt::WidgetWithChildrenShortcut, [this]() { - toggleBase(); - }) #undef ADD_ACTION } @@ -627,25 +623,6 @@ void DisassemblyWidget::jumpToOffsetUnderCursor(const QTextCursor &cursor) seekable->seekToReference(offset); } -// TODO: requires the user to trigger the action twice if the number is in decimals -void DisassemblyWidget::toggleBase() -{ - RVA offset = readCurrentDisassemblyOffset(); - QJsonObject instObject = Core()->cmdj("aoj @ " + QString::number( - offset)).array().first().toObject(); - auto keys = instObject.keys(); - bool immBase = keys.contains("val") || keys.contains("ptr"); - - if(immBase) { - int base = Core()->getImmediateBase(offset); - if (base == 10) { - Core()->setImmediateBase("h", offset); - } else { - Core()->setImmediateBase("d", offset); - } - } -} - bool DisassemblyWidget::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::MouseButtonDblClick diff --git a/src/widgets/DisassemblyWidget.h b/src/widgets/DisassemblyWidget.h index 9b9f7e0a6..36aaf3ec1 100644 --- a/src/widgets/DisassemblyWidget.h +++ b/src/widgets/DisassemblyWidget.h @@ -88,8 +88,6 @@ protected slots: void moveCursorRelative(bool up, bool page); void jumpToOffsetUnderCursor(const QTextCursor&); - - void toggleBase(); }; class DisassemblyScrollArea : public QAbstractScrollArea From f012486004437f929b6ed2036d0f62b23edfae58 Mon Sep 17 00:00:00 2001 From: plaets Date: Wed, 23 Sep 2020 16:05:37 +0200 Subject: [PATCH 4/8] Add toggle immediate base shortcut to the docs --- docs/source/user-docs/shortcuts.rst | 2 ++ src/menus/DisassemblyContextMenu.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/source/user-docs/shortcuts.rst b/docs/source/user-docs/shortcuts.rst index 9f95a1856..e6f06a576 100644 --- a/docs/source/user-docs/shortcuts.rst +++ b/docs/source/user-docs/shortcuts.rst @@ -76,6 +76,8 @@ Disassembly View Shortcuts +-------------+----------------------------------+ | Ctrl/Cmd+= | Reset zoom | +-------------+----------------------------------+ +| H | Toggle immediate base | ++-------------+----------------------------------+ Graph View Shortcuts -------------------- diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index 60a9ac3cd..187d39d68 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -817,9 +817,9 @@ void DisassemblyContextMenu::on_actionToggleBase_triggered() { int base = Core()->getImmediateBase(offset); if (base == 10) { - setBase("h"); + setBase("h"); } else { - setBase("d"); + setBase("d"); } } From 7223760e2e24dad74b2ad574ac803360ad7f7ac5 Mon Sep 17 00:00:00 2001 From: plaets Date: Thu, 24 Sep 2020 12:22:38 +0200 Subject: [PATCH 5/8] Attempt to fix failed Ubuntu 16.04 build --- src/core/Cutter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 6f53f833d..78b6fd781 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -845,7 +845,7 @@ void CutterCore::setImmediateBase(const QString &r2BaseName, RVA offset) int CutterCore::getImmediateBase(RVA offset) { QJsonValue result = this->cmdj(QString("ahj %1").arg(offset)).array().first(); - return result["immbase"].toInt(); + return result.toObject()["immbase"].toInt(); } void CutterCore::setCurrentBits(int bits, RVA offset) From b3efeca2fbae146305293bd0d47f5c95ad38133f Mon Sep 17 00:00:00 2001 From: plaets Date: Sat, 26 Sep 2020 16:06:27 +0200 Subject: [PATCH 6/8] Hide Toggle immediate base when it's not needed --- src/menus/DisassemblyContextMenu.cpp | 21 +++++++++++++++------ src/menus/DisassemblyContextMenu.h | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index 187d39d68..f77e859b8 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -404,6 +404,7 @@ void DisassemblyContextMenu::setOffset(RVA offset) this->offset = offset; this->actionSetFunctionVarTypes.setVisible(true); + actionToggleBase.setVisible(checkImmediateBaseMenu(getInstObject())); } void DisassemblyContextMenu::setCanCopy(bool enabled) @@ -416,14 +417,22 @@ void DisassemblyContextMenu::setCurHighlightedWord(const QString &text) this->curHighlightedWord = text; } -void DisassemblyContextMenu::aboutToShowSlot() -{ - // check if set immediate base menu makes sense - QJsonObject instObject = Core()->cmdj("aoj @ " + QString::number( +QJsonObject DisassemblyContextMenu::getInstObject() { + return Core()->cmdj("aoj @ " + QString::number( offset)).array().first().toObject(); +} + +// check if set immediate base menu makes sense +bool DisassemblyContextMenu::checkImmediateBaseMenu(const QJsonObject& instObject) { auto keys = instObject.keys(); - bool immBase = keys.contains("val") || keys.contains("ptr"); - setBaseMenu->menuAction()->setVisible(immBase); + return keys.contains("val") || keys.contains("ptr"); +} + +void DisassemblyContextMenu::aboutToShowSlot() +{ + QJsonObject instObject = getInstObject(); + + setBaseMenu->menuAction()->setVisible(checkImmediateBaseMenu(instObject)); setBitsMenu->menuAction()->setVisible(true); // Create structure offset menu if it makes sense diff --git a/src/menus/DisassemblyContextMenu.h b/src/menus/DisassemblyContextMenu.h index 6bd034c53..67f91e0e3 100644 --- a/src/menus/DisassemblyContextMenu.h +++ b/src/menus/DisassemblyContextMenu.h @@ -233,6 +233,20 @@ private slots: }; QVector getThingUsedHere(RVA offset); + /** + * @brief Checks if it makes sense to display the immediate base menu + * @param instObject Object with instruction data + * @returns Return true if the it makes sense to display the set immediate base menu + * return false otherwise. + */ + bool checkImmediateBaseMenu(const QJsonObject& instObject); + + /** + * @brief Returns json data of the current instruction + * @returns Instruction data + */ + QJsonObject getInstObject(); + void updateTargetMenuActions(const QVector &targets); }; #endif // DISASSEMBLYCONTEXTMENU_H From 102a3413218702d55d2b49015f87be23176d5fff Mon Sep 17 00:00:00 2001 From: plaets Date: Sat, 26 Sep 2020 16:32:09 +0200 Subject: [PATCH 7/8] Fix getImmediateBase for cases when `ahj` returns more than one object --- src/core/Cutter.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 78b6fd781..dc397542f 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -844,8 +844,14 @@ void CutterCore::setImmediateBase(const QString &r2BaseName, RVA offset) int CutterCore::getImmediateBase(RVA offset) { - QJsonValue result = this->cmdj(QString("ahj %1").arg(offset)).array().first(); - return result.toObject()["immbase"].toInt(); + QJsonArray result = this->cmdj(QString("ahj %1").arg(offset)).array(); + for (const auto& n: result) { + QJsonValue immbase = n.toObject()["immbase"]; + if (immbase.isDouble()) { + return immbase.toInt(); + } + } + return 0; } void CutterCore::setCurrentBits(int bits, RVA offset) From 8fad566f50a0bf46a6157ff5a72ced63a4abc93d Mon Sep 17 00:00:00 2001 From: plaets Date: Sun, 27 Sep 2020 11:11:47 +0200 Subject: [PATCH 8/8] Implement requested changes --- src/core/Cutter.cpp | 12 ++++++++---- src/core/Cutter.h | 8 ++++++++ src/menus/DisassemblyContextMenu.cpp | 11 +++-------- src/menus/DisassemblyContextMenu.h | 6 ------ 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index dc397542f..5ee722dfa 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -699,14 +699,19 @@ void CutterCore::delFlag(const QString &name) emit flagsChanged(); } +QJsonObject CutterCore::getInstructionObject(RVA addr) +{ + return Core()->cmdj("aoj @ " + QString::number(addr)).array().first().toObject(); +} + QString CutterCore::getInstructionBytes(RVA addr) { - return cmdj("aoj @ " + RAddressString(addr)).array().first().toObject()[RJsonKey::bytes].toString(); + return getInstructionObject(addr)[RJsonKey::bytes].toString(); } QString CutterCore::getInstructionOpcode(RVA addr) { - return cmdj("aoj @ " + RAddressString(addr)).array().first().toObject()[RJsonKey::opcode].toString(); + return getInstructionObject(addr)[RJsonKey::opcode].toString(); } void CutterCore::editInstruction(RVA addr, const QString &inst) @@ -1241,8 +1246,7 @@ QJsonDocument CutterCore::getRegistersInfo() RVA CutterCore::getOffsetJump(RVA addr) { bool ok; - RVA value = cmdj("aoj @" + QString::number( - addr)).array().first().toObject().value(RJsonKey::jump).toVariant().toULongLong(&ok); + RVA value = getInstructionObject(addr).value(RJsonKey::jump).toVariant().toULongLong(&ok); if (!ok) { return RVA_INVALID; diff --git a/src/core/Cutter.h b/src/core/Cutter.h index 604a696d6..2568df9e5 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -191,9 +191,17 @@ class CUTTER_EXPORT CutterCore: public QObject QString nearestFlag(RVA offset, RVA *flagOffsetOut); void triggerFlagsChanged(); + /** + * @brief Returns json data of an instruction + * @param addr Address of the instruction + * @returns Instruction data + */ + QJsonObject getInstructionObject(RVA addr); + /* Edition functions */ QString getInstructionBytes(RVA addr); QString getInstructionOpcode(RVA addr); + void editInstruction(RVA addr, const QString &inst); void nopInstruction(RVA addr); void jmpReverse(RVA addr); diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index f77e859b8..ddfd81d29 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -404,7 +404,7 @@ void DisassemblyContextMenu::setOffset(RVA offset) this->offset = offset; this->actionSetFunctionVarTypes.setVisible(true); - actionToggleBase.setVisible(checkImmediateBaseMenu(getInstObject())); + actionToggleBase.setVisible(checkImmediateBaseMenu(Core()->getInstructionObject(offset))); } void DisassemblyContextMenu::setCanCopy(bool enabled) @@ -417,12 +417,7 @@ void DisassemblyContextMenu::setCurHighlightedWord(const QString &text) this->curHighlightedWord = text; } -QJsonObject DisassemblyContextMenu::getInstObject() { - return Core()->cmdj("aoj @ " + QString::number( - offset)).array().first().toObject(); -} - -// check if set immediate base menu makes sense +// Check if it makes sense to show the immediate base menu bool DisassemblyContextMenu::checkImmediateBaseMenu(const QJsonObject& instObject) { auto keys = instObject.keys(); return keys.contains("val") || keys.contains("ptr"); @@ -430,7 +425,7 @@ bool DisassemblyContextMenu::checkImmediateBaseMenu(const QJsonObject& instObjec void DisassemblyContextMenu::aboutToShowSlot() { - QJsonObject instObject = getInstObject(); + QJsonObject instObject = Core()->getInstructionObject(offset); setBaseMenu->menuAction()->setVisible(checkImmediateBaseMenu(instObject)); setBitsMenu->menuAction()->setVisible(true); diff --git a/src/menus/DisassemblyContextMenu.h b/src/menus/DisassemblyContextMenu.h index 67f91e0e3..d113ce1fd 100644 --- a/src/menus/DisassemblyContextMenu.h +++ b/src/menus/DisassemblyContextMenu.h @@ -241,12 +241,6 @@ private slots: */ bool checkImmediateBaseMenu(const QJsonObject& instObject); - /** - * @brief Returns json data of the current instruction - * @returns Instruction data - */ - QJsonObject getInstObject(); - void updateTargetMenuActions(const QVector &targets); }; #endif // DISASSEMBLYCONTEXTMENU_H