Xrefs action for references (#2352)

* X-Refs for references (functions, global variables, constant variables with addresses) in the decompiler.
This commit is contained in:
NIRMAL MANOJ C 2020-08-05 00:33:39 +05:30
parent b42a19e995
commit 6ed32d5d1d
2 changed files with 34 additions and 8 deletions

View File

@ -3,6 +3,7 @@
#include "MainWindow.h" #include "MainWindow.h"
#include "dialogs/BreakpointsDialog.h" #include "dialogs/BreakpointsDialog.h"
#include "dialogs/CommentsDialog.h" #include "dialogs/CommentsDialog.h"
#include "dialogs/XrefsDialog.h"
#include "common/Configuration.h" #include "common/Configuration.h"
#include <QtCore> #include <QtCore>
@ -28,6 +29,7 @@ DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWi
actionDeleteComment(tr("Delete comment"), this), actionDeleteComment(tr("Delete comment"), this),
actionRenameThingHere(tr("Rename function at cursor"), this), actionRenameThingHere(tr("Rename function at cursor"), this),
actionDeleteName(tr("Delete <name>"), this), actionDeleteName(tr("Delete <name>"), this),
actionXRefs(tr("Show X-Refs"), this),
actionToggleBreakpoint(tr("Add/remove breakpoint"), this), actionToggleBreakpoint(tr("Add/remove breakpoint"), this),
actionAdvancedBreakpoint(tr("Advanced breakpoint"), this), actionAdvancedBreakpoint(tr("Advanced breakpoint"), this),
breakpointsInLineMenu(new QMenu(this)), breakpointsInLineMenu(new QMenu(this)),
@ -43,6 +45,8 @@ DecompilerContextMenu::DecompilerContextMenu(QWidget *parent, MainWindow *mainWi
setActionAddComment(); setActionAddComment();
setActionDeleteComment(); setActionDeleteComment();
setActionXRefs();
setActionRenameThingHere(); setActionRenameThingHere();
setActionDeleteName(); setActionDeleteName();
@ -129,6 +133,7 @@ void DecompilerContextMenu::aboutToHideSlot()
actionAddComment.setVisible(true); actionAddComment.setVisible(true);
actionRenameThingHere.setVisible(true); actionRenameThingHere.setVisible(true);
actionDeleteName.setVisible(false); actionDeleteName.setVisible(false);
actionXRefs.setVisible(true);
} }
void DecompilerContextMenu::aboutToShowSlot() void DecompilerContextMenu::aboutToShowSlot()
@ -202,13 +207,7 @@ void DecompilerContextMenu::aboutToShowSlot()
} }
actionCopyInstructionAddress.setText(tr("Copy instruction address (%1)").arg(RAddressString( actionCopyInstructionAddress.setText(tr("Copy instruction address (%1)").arg(RAddressString(
offset))); offset)));
bool isReference = false; if (annotationHere && r_annotation_is_reference(annotationHere)) {
if (annotationHere) {
isReference = (annotationHere->type == R_CODE_ANNOTATION_TYPE_GLOBAL_VARIABLE
|| annotationHere->type == R_CODE_ANNOTATION_TYPE_CONSTANT_VARIABLE
|| annotationHere->type == R_CODE_ANNOTATION_TYPE_FUNCTION_NAME);
}
if (isReference) {
actionCopyReferenceAddress.setVisible(true); actionCopyReferenceAddress.setVisible(true);
RVA referenceAddr = annotationHere->reference.offset; RVA referenceAddr = annotationHere->reference.offset;
RFlagItem *flagDetails = r_flag_get_i(Core()->core()->flags, referenceAddr); RFlagItem *flagDetails = r_flag_get_i(Core()->core()->flags, referenceAddr);
@ -222,6 +221,7 @@ void DecompilerContextMenu::aboutToShowSlot()
actionCopyReferenceAddress.setText(tr("Copy address (%1)").arg(RAddressString(referenceAddr))); actionCopyReferenceAddress.setText(tr("Copy address (%1)").arg(RAddressString(referenceAddr)));
} }
} else { } else {
actionXRefs.setVisible(false);
actionCopyReferenceAddress.setVisible(false); actionCopyReferenceAddress.setVisible(false);
} }
if (actionShowInSubmenu.menu() != nullptr) { if (actionShowInSubmenu.menu() != nullptr) {
@ -270,6 +270,13 @@ void DecompilerContextMenu::setActionDeleteComment()
addAction(&actionDeleteComment); addAction(&actionDeleteComment);
} }
void DecompilerContextMenu::setActionXRefs()
{
connect(&actionXRefs, &QAction::triggered, this, &DecompilerContextMenu::actionXRefsTriggered);
addAction(&actionXRefs);
actionXRefs.setShortcut(Qt::Key_X);
}
void DecompilerContextMenu::setActionRenameThingHere() void DecompilerContextMenu::setActionRenameThingHere()
{ {
actionRenameThingHere.setShortcut({Qt::Key_N}); actionRenameThingHere.setShortcut({Qt::Key_N});
@ -392,6 +399,18 @@ void DecompilerContextMenu::actionDeleteNameTriggered()
Core()->delFlag(annotationHere->reference.offset); Core()->delFlag(annotationHere->reference.offset);
} }
void DecompilerContextMenu::actionXRefsTriggered()
{
if (!annotationHere || !r_annotation_is_reference(annotationHere)) {
return;
}
XrefsDialog dialog(mainWindow, nullptr);
QString displayString = (annotationHere->type == R_CODE_ANNOTATION_TYPE_FUNCTION_NAME) ? QString(
annotationHere->reference.name) : RAddressString(annotationHere->reference.offset);
dialog.fillRefsForAddress(annotationHere->reference.offset, displayString, false);
dialog.exec();
}
void DecompilerContextMenu::actionToggleBreakpointTriggered() void DecompilerContextMenu::actionToggleBreakpointTriggered()
{ {
if (!this->availableBreakpoints.isEmpty()) { if (!this->availableBreakpoints.isEmpty()) {
@ -473,7 +492,8 @@ void DecompilerContextMenu::updateTargetMenuActions()
QMenu *menu; QMenu *menu;
if (annotationHere->type == R_CODE_ANNOTATION_TYPE_GLOBAL_VARIABLE if (annotationHere->type == R_CODE_ANNOTATION_TYPE_GLOBAL_VARIABLE
|| annotationHere->type == R_CODE_ANNOTATION_TYPE_CONSTANT_VARIABLE) { || annotationHere->type == R_CODE_ANNOTATION_TYPE_CONSTANT_VARIABLE) {
menu = mainWindow->createShowInMenu(this, annotationHere->reference.offset, MainWindow::AddressTypeHint::Data); menu = mainWindow->createShowInMenu(this, annotationHere->reference.offset,
MainWindow::AddressTypeHint::Data);
RVA var_addr = annotationHere->reference.offset; RVA var_addr = annotationHere->reference.offset;
RFlagItem *flagDetails = r_flag_get_i(core->flags, var_addr); RFlagItem *flagDetails = r_flag_get_i(core->flags, var_addr);
if (flagDetails) { if (flagDetails) {

View File

@ -42,6 +42,8 @@ private slots:
void actionRenameThingHereTriggered(); void actionRenameThingHereTriggered();
void actionDeleteNameTriggered(); void actionDeleteNameTriggered();
void actionXRefsTriggered();
void actionToggleBreakpointTriggered(); void actionToggleBreakpointTriggered();
void actionAdvancedBreakpointTriggered(); void actionAdvancedBreakpointTriggered();
@ -73,6 +75,8 @@ private:
QAction actionRenameThingHere; QAction actionRenameThingHere;
QAction actionDeleteName; QAction actionDeleteName;
QAction actionXRefs;
QMenu *breakpointMenu; QMenu *breakpointMenu;
QAction actionToggleBreakpoint; QAction actionToggleBreakpoint;
QAction actionAdvancedBreakpoint; QAction actionAdvancedBreakpoint;
@ -96,6 +100,8 @@ private:
void setActionAddComment(); void setActionAddComment();
void setActionDeleteComment(); void setActionDeleteComment();
void setActionXRefs();
void setActionRenameThingHere(); void setActionRenameThingHere();
void setActionDeleteName(); void setActionDeleteName();