Hide Immediate Base menu if not needed

This commit is contained in:
Florian Märkl 2017-11-28 14:50:41 +01:00
parent 7f378d66c3
commit dd744cb64e
2 changed files with 56 additions and 48 deletions

View File

@ -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"));
@ -141,6 +107,46 @@ void DisassemblyContextMenu::init()
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()

View File

@ -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;