Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/menus/DisassemblyContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *main
connect(structureOffsetMenu, &QMenu::triggered, this,
&DisassemblyContextMenu::on_actionStructureOffsetMenu_triggered);

addSetCallingConventionMenu();

addSetAsMenu();

addSeparator();
Expand Down Expand Up @@ -582,6 +584,30 @@ void DisassemblyContextMenu::aboutToShowSlot()
// Note: This might be useless if we consider setCurrentHighlightedWord is always called before
setupRenaming();

if (isHighlightedWordCC()) {
setCallingConventionMenu->menuAction()->setVisible(true);
setCallingConventionMenu->clear();

RzCoreLocked core(Core());
RzList *list = rz_analysis_calling_conventions(core->analysis);
if (list) {
RzListIter *iter;
const char *cc;
CutterRzListForeach (list, iter, const char, cc) {
QString ccStr(cc);
QAction *action = setCallingConventionMenu->addAction(ccStr);
action->setData(ccStr);
if (ccStr == curHighlightedWord) {
action->setCheckable(true);
action->setChecked(true);
}
}
rz_list_free(list);
}
} else {
setCallingConventionMenu->menuAction()->setVisible(false);
}

// Only show retype for local vars if in a function
RzAnalysisFunction *in_fcn = Core()->functionIn(offset);
if (in_fcn) {
Expand Down Expand Up @@ -1069,3 +1095,48 @@ bool DisassemblyContextMenu::isHighlightedWordLocalVar()
}
return false;
}

void DisassemblyContextMenu::addSetCallingConventionMenu()
{
setCallingConventionMenu = addMenu(tr("Set calling convention"));
connect(setCallingConventionMenu, &QMenu::triggered, this,
&DisassemblyContextMenu::on_actionSetCallingConvention_triggered);
}

void DisassemblyContextMenu::on_actionSetCallingConvention_triggered(QAction *action)
{
QString newCC = action->data().toString();
if (newCC.isEmpty()) {
return;
}
RzCoreLocked core(Core());
RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, offset, 0);
if (!fcn) {
return;
}
QByteArray newCCBytes = newCC.toUtf8();
if (rz_analysis_cc_exist(core->analysis, newCCBytes.constData())) {
fcn->cc = rz_str_constpool_get(&core->analysis->constpool, newCCBytes.constData());
emit Core()->functionsChanged();
}
}

bool DisassemblyContextMenu::isHighlightedWordCC()
{
RzCoreLocked core(Core());
RzList *list = rz_analysis_calling_conventions(core->analysis);
if (!list) {
return false;
}
bool found = false;
RzListIter *iter;
const char *cc;
CutterRzListForeach (list, iter, const char, cc) {
if (curHighlightedWord == QString(cc)) {
found = true;
break;
}
}
rz_list_free(list);
return found;
}
4 changes: 4 additions & 0 deletions src/menus/DisassemblyContextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private slots:
* \param action The action which trigered the event
*/
void on_actionStructureOffsetMenu_triggered(QAction *action);
void on_actionSetCallingConvention_triggered(QAction *action);

private:
RVA offset;
Expand Down Expand Up @@ -140,6 +141,7 @@ private slots:
QAction actionSetAsStringAdvanced;

QMenu *setToDataMenu;
QMenu *setCallingConventionMenu;
QMenu *setAsMenu;
QMenu *setAsString;
QAction actionSetToDataEx;
Expand Down Expand Up @@ -173,6 +175,7 @@ private slots:
void addSetBitsMenu();
void addSetAsMenu();
void addSetToDataMenu();
void addSetCallingConventionMenu();
void addEditMenu();
void addAddAtMenu();
void addBreakpointMenu();
Expand Down Expand Up @@ -210,6 +213,7 @@ private slots:
* parameter, return false otherwise.
*/
bool isHighlightedWordLocalVar();
bool isHighlightedWordCC();
struct ThingUsedHere
{
QString name;
Expand Down