Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a hotkey for toggling immediate base (#2420) #2429

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
21 changes: 15 additions & 6 deletions src/menus/DisassemblyContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
plaets marked this conversation as resolved.
Show resolved Hide resolved
return Core()->cmdj("aoj @ " + QString::number(
offset)).array().first().toObject();
}

// check if set immediate base menu makes sense
plaets marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
14 changes: 14 additions & 0 deletions src/menus/DisassemblyContextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ private slots:
};
QVector<ThingUsedHere> 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();
plaets marked this conversation as resolved.
Show resolved Hide resolved

void updateTargetMenuActions(const QVector<ThingUsedHere> &targets);
};
#endif // DISASSEMBLYCONTEXTMENU_H