From dd744cb64eac804f7c0d6e405363c989c6c87c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 28 Nov 2017 14:50:41 +0100 Subject: [PATCH] Hide Immediate Base menu if not needed --- src/menus/DisassemblyContextMenu.cpp | 96 +++++++++++++++------------- src/menus/DisassemblyContextMenu.h | 8 ++- 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index ded07ffb..982b683e 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -23,41 +23,6 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent) actionSetBaseIPAddr(this), actionSetBaseSyscall(this), actionSetBaseString(this) -{ - init(); -} - -void DisassemblyContextMenu::setOffset(RVA offset) -{ - this->offset = offset; -} - -QKeySequence DisassemblyContextMenu::getCommentSequence() const -{ - return {";"}; -} - -QKeySequence DisassemblyContextMenu::getAddFlagSequence() const -{ - return {}; //TODO insert correct sequence -} - -QKeySequence DisassemblyContextMenu::getRenameSequence() const -{ - return {Qt::Key_N}; -} - -QKeySequence DisassemblyContextMenu::getXRefSequence() const -{ - return {Qt::Key_X}; -} - -QKeySequence DisassemblyContextMenu::getDisplayOptionsSequence() const -{ - return {}; //TODO insert correct sequence -} - -void DisassemblyContextMenu::init() { actionAddComment.setText(tr("Add Comment")); this->addAction(&actionAddComment); @@ -71,23 +36,24 @@ void DisassemblyContextMenu::init() this->addAction(&actionRename); actionAddComment.setShortcut(getRenameSequence()); - QMenu *baseMenu = addMenu(tr("Set Base to...")); + setBaseMenu = new QMenu(tr("Set Immediate Base to..."), this); + setBaseMenuAction = addMenu(setBaseMenu); actionSetBaseBinary.setText(tr("Binary")); - baseMenu->addAction(&actionSetBaseBinary); + setBaseMenu->addAction(&actionSetBaseBinary); actionSetBaseOctal.setText(tr("Octal")); - baseMenu->addAction(&actionSetBaseOctal); + setBaseMenu->addAction(&actionSetBaseOctal); actionSetBaseDecimal.setText(tr("Decimal")); - baseMenu->addAction(&actionSetBaseDecimal); + setBaseMenu->addAction(&actionSetBaseDecimal); actionSetBaseHexadecimal.setText(tr("Hexadecimal")); - baseMenu->addAction(&actionSetBaseHexadecimal); + setBaseMenu->addAction(&actionSetBaseHexadecimal); actionSetBasePort.setText(tr("Network Port")); - baseMenu->addAction(&actionSetBasePort); + setBaseMenu->addAction(&actionSetBasePort); actionSetBaseIPAddr.setText(tr("IP Address")); - baseMenu->addAction(&actionSetBaseIPAddr); + setBaseMenu->addAction(&actionSetBaseIPAddr); actionSetBaseSyscall.setText(tr("Syscall")); - baseMenu->addAction(&actionSetBaseSyscall); + setBaseMenu->addAction(&actionSetBaseSyscall); actionSetBaseString.setText(tr("String")); - baseMenu->addAction(&actionSetBaseString); + setBaseMenu->addAction(&actionSetBaseString); this->addSeparator(); actionXRefs.setText(tr("Show X-Refs")); @@ -140,7 +106,47 @@ void DisassemblyContextMenu::init() connect(&actionSetBaseIPAddr, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseIPAddr_triggered())); connect(&actionSetBaseSyscall, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseSyscall_triggered())); connect(&actionSetBaseString, SIGNAL(triggered(bool)), this, SLOT(on_actionSetBaseString_triggered())); - + + connect(this, SIGNAL(aboutToShow()), this, SLOT(aboutToShowSlot())); +} + +void DisassemblyContextMenu::setOffset(RVA offset) +{ + this->offset = offset; +} + +void DisassemblyContextMenu::aboutToShowSlot() +{ + // check if set immediate base menu makes sense + QJsonObject instObject = Core()->cmdj("aoj @ " + QString::number(offset)).array().first().toObject(); + auto keys = instObject.keys(); + bool immBase = keys.contains("val") || keys.contains("ptr"); + setBaseMenuAction->setVisible(immBase); +} + +QKeySequence DisassemblyContextMenu::getCommentSequence() const +{ + return {";"}; +} + +QKeySequence DisassemblyContextMenu::getAddFlagSequence() const +{ + return {}; //TODO insert correct sequence +} + +QKeySequence DisassemblyContextMenu::getRenameSequence() const +{ + return {Qt::Key_N}; +} + +QKeySequence DisassemblyContextMenu::getXRefSequence() const +{ + return {Qt::Key_X}; +} + +QKeySequence DisassemblyContextMenu::getDisplayOptionsSequence() const +{ + return {}; //TODO insert correct sequence } void DisassemblyContextMenu::on_actionAddComment_triggered() diff --git a/src/menus/DisassemblyContextMenu.h b/src/menus/DisassemblyContextMenu.h index 15283443..18113ed3 100644 --- a/src/menus/DisassemblyContextMenu.h +++ b/src/menus/DisassemblyContextMenu.h @@ -13,10 +13,12 @@ public: DisassemblyContextMenu(QWidget *parent = nullptr); ~DisassemblyContextMenu() = default; - public slots: void setOffset(RVA offset); +private slots: + void aboutToShowSlot(); + void on_actionAddComment_triggered(); void on_actionAddFlag_triggered(); void on_actionRename_triggered(); @@ -33,8 +35,6 @@ public slots: void on_actionSetBaseString_triggered(); private: - void init(); - QKeySequence getCommentSequence() const; QKeySequence getAddFlagSequence() const; QKeySequence getRenameSequence() const; @@ -49,6 +49,8 @@ private: QAction actionXRefs; QAction actionDisplayOptions; + QMenu *setBaseMenu; + QAction *setBaseMenuAction; QAction actionSetBaseBinary; QAction actionSetBaseOctal; QAction actionSetBaseDecimal;