2017-10-10 10:17:05 +00:00
|
|
|
#ifndef DISASSEMBLYCONTEXTMENU_H
|
|
|
|
#define DISASSEMBLYCONTEXTMENU_H
|
|
|
|
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/Cutter.h"
|
2020-03-19 09:36:36 +00:00
|
|
|
#include "common/IOModesController.h"
|
2017-10-10 10:17:05 +00:00
|
|
|
#include <QMenu>
|
2017-11-03 11:31:20 +00:00
|
|
|
#include <QKeySequence>
|
2017-10-10 10:17:05 +00:00
|
|
|
|
2020-08-14 18:30:51 +00:00
|
|
|
class MainWindow;
|
|
|
|
|
2020-08-01 14:14:30 +00:00
|
|
|
class CUTTER_EXPORT DisassemblyContextMenu : public QMenu
|
2017-11-19 17:49:29 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
Q_OBJECT
|
2017-11-19 17:49:29 +00:00
|
|
|
|
2017-10-10 10:17:05 +00:00
|
|
|
public:
|
2019-08-14 18:47:30 +00:00
|
|
|
DisassemblyContextMenu(QWidget *parent, MainWindow *mainWindow);
|
2017-12-10 20:40:15 +00:00
|
|
|
~DisassemblyContextMenu();
|
2017-11-03 11:31:20 +00:00
|
|
|
|
2017-12-02 15:43:21 +00:00
|
|
|
signals:
|
|
|
|
void copy();
|
|
|
|
|
2017-11-03 11:31:20 +00:00
|
|
|
public slots:
|
|
|
|
void setOffset(RVA offset);
|
2017-12-02 15:43:21 +00:00
|
|
|
void setCanCopy(bool enabled);
|
2017-11-03 11:31:20 +00:00
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Sets the value of curHighlightedWord
|
|
|
|
* @param text The current highlighted word
|
2019-03-04 21:45:17 +00:00
|
|
|
*/
|
|
|
|
void setCurHighlightedWord(const QString &text);
|
|
|
|
|
2017-11-28 13:50:41 +00:00
|
|
|
private slots:
|
|
|
|
void aboutToShowSlot();
|
2020-07-28 19:49:50 +00:00
|
|
|
void aboutToHideSlot();
|
2017-11-28 13:50:41 +00:00
|
|
|
|
2018-10-22 09:16:56 +00:00
|
|
|
void on_actionEditFunction_triggered();
|
2018-02-12 20:12:13 +00:00
|
|
|
void on_actionEditInstruction_triggered();
|
2018-03-05 14:20:55 +00:00
|
|
|
void on_actionNopInstruction_triggered();
|
2018-03-10 07:27:09 +00:00
|
|
|
void on_actionJmpReverse_triggered();
|
2018-02-12 20:12:13 +00:00
|
|
|
void on_actionEditBytes_triggered();
|
2018-09-14 17:20:54 +00:00
|
|
|
void showReverseJmpQuery();
|
2018-02-12 20:12:13 +00:00
|
|
|
|
2017-12-02 15:43:21 +00:00
|
|
|
void on_actionCopy_triggered();
|
2018-05-03 07:53:01 +00:00
|
|
|
void on_actionCopyAddr_triggered();
|
2017-11-03 11:31:20 +00:00
|
|
|
void on_actionAddComment_triggered();
|
2018-08-18 19:28:04 +00:00
|
|
|
void on_actionAnalyzeFunction_triggered();
|
2017-11-03 11:31:20 +00:00
|
|
|
void on_actionRename_triggered();
|
2018-10-03 20:10:53 +00:00
|
|
|
void on_actionSetFunctionVarTypes_triggered();
|
2017-11-03 11:31:20 +00:00
|
|
|
void on_actionXRefs_triggered();
|
2020-07-28 19:49:50 +00:00
|
|
|
void on_actionXRefsForVariables_triggered();
|
2017-11-03 11:31:20 +00:00
|
|
|
void on_actionDisplayOptions_triggered();
|
2017-10-10 10:17:05 +00:00
|
|
|
|
2017-12-11 13:07:12 +00:00
|
|
|
void on_actionDeleteComment_triggered();
|
|
|
|
void on_actionDeleteFlag_triggered();
|
|
|
|
void on_actionDeleteFunction_triggered();
|
|
|
|
|
2018-06-12 08:43:14 +00:00
|
|
|
void on_actionAddBreakpoint_triggered();
|
2020-01-04 18:05:49 +00:00
|
|
|
void on_actionAdvancedBreakpoint_triggered();
|
2018-06-12 08:43:14 +00:00
|
|
|
void on_actionContinueUntil_triggered();
|
|
|
|
void on_actionSetPC_triggered();
|
2018-02-12 09:48:06 +00:00
|
|
|
|
2018-08-04 18:05:56 +00:00
|
|
|
void on_actionSetToCode_triggered();
|
2018-11-16 21:27:07 +00:00
|
|
|
void on_actionSetAsString_triggered();
|
2019-12-18 14:26:51 +00:00
|
|
|
void on_actionSetAsStringRemove_triggered();
|
|
|
|
void on_actionSetAsStringAdvanced_triggered();
|
2018-08-04 18:05:56 +00:00
|
|
|
void on_actionSetToData_triggered();
|
|
|
|
void on_actionSetToDataEx_triggered();
|
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Executed on selecting an offset from the structureOffsetMenu
|
2019-02-24 17:25:38 +00:00
|
|
|
* Uses the applyStructureOffset() function of CutterCore to apply the
|
|
|
|
* structure offset
|
|
|
|
* \param action The action which trigered the event
|
|
|
|
*/
|
|
|
|
void on_actionStructureOffsetMenu_triggered(QAction *action);
|
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Executed on selecting the "Link Type to Address" option
|
2019-03-04 21:45:17 +00:00
|
|
|
* Opens the LinkTypeDialog box from where the user can link the address
|
|
|
|
* to a type
|
|
|
|
*/
|
|
|
|
void on_actionLinkType_triggered();
|
|
|
|
|
2017-11-03 11:31:20 +00:00
|
|
|
private:
|
2017-12-02 15:43:21 +00:00
|
|
|
QKeySequence getCopySequence() const;
|
2017-11-03 11:31:20 +00:00
|
|
|
QKeySequence getCommentSequence() const;
|
2019-04-25 11:38:53 +00:00
|
|
|
QKeySequence getCopyAddressSequence() const;
|
2018-08-04 18:05:56 +00:00
|
|
|
QKeySequence getSetToCodeSequence() const;
|
2018-11-16 21:27:07 +00:00
|
|
|
QKeySequence getSetAsStringSequence() const;
|
2020-08-25 03:44:33 +00:00
|
|
|
QKeySequence getSetAsStringAdvanced() const;
|
2018-08-04 18:05:56 +00:00
|
|
|
QKeySequence getSetToDataSequence() const;
|
|
|
|
QKeySequence getSetToDataExSequence() const;
|
2017-11-03 11:31:20 +00:00
|
|
|
QKeySequence getRenameSequence() const;
|
2018-10-03 20:10:53 +00:00
|
|
|
QKeySequence getRetypeSequence() const;
|
2017-11-03 11:31:20 +00:00
|
|
|
QKeySequence getXRefSequence() const;
|
|
|
|
QKeySequence getDisplayOptionsSequence() const;
|
2019-09-25 13:58:58 +00:00
|
|
|
QKeySequence getDefineNewFunctionSequence() const;
|
|
|
|
QKeySequence getUndefineFunctionSequence() const;
|
|
|
|
QKeySequence getEditFunctionSequence() const;
|
2018-07-17 07:26:20 +00:00
|
|
|
QList<QKeySequence> getAddBPSequence() const;
|
2017-11-19 17:49:29 +00:00
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @return the shortcut key for "Link Type to Address" option
|
2019-03-04 21:45:17 +00:00
|
|
|
*/
|
|
|
|
QKeySequence getLinkTypeSequence() const;
|
|
|
|
|
2017-10-10 10:17:05 +00:00
|
|
|
RVA offset;
|
2017-12-02 15:43:21 +00:00
|
|
|
bool canCopy;
|
2019-03-04 21:45:17 +00:00
|
|
|
QString curHighlightedWord; // The current highlighted word
|
2019-08-14 18:47:30 +00:00
|
|
|
MainWindow *mainWindow;
|
2020-03-19 09:36:36 +00:00
|
|
|
IOModesController ioModesController;
|
2017-12-02 15:43:21 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
QList<QAction *> anonymousActions;
|
2017-12-10 20:40:15 +00:00
|
|
|
|
2018-02-12 20:12:13 +00:00
|
|
|
QMenu *editMenu;
|
|
|
|
QAction actionEditInstruction;
|
2018-03-05 14:20:55 +00:00
|
|
|
QAction actionNopInstruction;
|
2018-03-10 07:27:09 +00:00
|
|
|
QAction actionJmpReverse;
|
2018-02-12 20:12:13 +00:00
|
|
|
QAction actionEditBytes;
|
|
|
|
|
2017-12-02 15:43:21 +00:00
|
|
|
QAction actionCopy;
|
|
|
|
QAction *copySeparator;
|
2018-05-03 07:53:01 +00:00
|
|
|
QAction actionCopyAddr;
|
2017-12-10 20:40:15 +00:00
|
|
|
|
2017-10-10 10:17:05 +00:00
|
|
|
QAction actionAddComment;
|
2018-08-18 19:28:04 +00:00
|
|
|
QAction actionAnalyzeFunction;
|
2018-10-22 09:16:56 +00:00
|
|
|
QAction actionEditFunction;
|
2017-10-10 10:17:05 +00:00
|
|
|
QAction actionRename;
|
2018-10-03 20:10:53 +00:00
|
|
|
QAction actionSetFunctionVarTypes;
|
2017-10-10 10:17:05 +00:00
|
|
|
QAction actionXRefs;
|
2020-07-28 19:49:50 +00:00
|
|
|
QAction actionXRefsForVariables;
|
2017-10-10 10:17:05 +00:00
|
|
|
QAction actionDisplayOptions;
|
2017-11-28 13:13:22 +00:00
|
|
|
|
2017-12-11 13:07:12 +00:00
|
|
|
QAction actionDeleteComment;
|
|
|
|
QAction actionDeleteFlag;
|
|
|
|
QAction actionDeleteFunction;
|
|
|
|
|
2019-02-24 17:25:38 +00:00
|
|
|
QMenu *structureOffsetMenu;
|
|
|
|
|
2019-03-04 21:45:17 +00:00
|
|
|
QAction actionLinkType;
|
|
|
|
|
2017-11-28 13:50:41 +00:00
|
|
|
QMenu *setBaseMenu;
|
2017-11-28 13:13:22 +00:00
|
|
|
QAction actionSetBaseBinary;
|
|
|
|
QAction actionSetBaseOctal;
|
|
|
|
QAction actionSetBaseDecimal;
|
|
|
|
QAction actionSetBaseHexadecimal;
|
|
|
|
QAction actionSetBasePort;
|
|
|
|
QAction actionSetBaseIPAddr;
|
|
|
|
QAction actionSetBaseSyscall;
|
|
|
|
QAction actionSetBaseString;
|
2017-12-10 20:40:15 +00:00
|
|
|
|
2018-02-12 09:48:06 +00:00
|
|
|
QMenu *setBitsMenu;
|
|
|
|
QAction actionSetBits16;
|
|
|
|
QAction actionSetBits32;
|
|
|
|
QAction actionSetBits64;
|
|
|
|
|
2018-06-12 08:43:14 +00:00
|
|
|
QMenu *debugMenu;
|
|
|
|
QAction actionContinueUntil;
|
2020-01-29 16:58:05 +00:00
|
|
|
QAction actionSetPC;
|
|
|
|
|
|
|
|
QMenu *breakpointMenu;
|
2018-06-12 08:43:14 +00:00
|
|
|
QAction actionAddBreakpoint;
|
2020-01-04 18:05:49 +00:00
|
|
|
QAction actionAdvancedBreakpoint;
|
2018-06-12 08:43:14 +00:00
|
|
|
|
2018-08-04 18:05:56 +00:00
|
|
|
QAction actionSetToCode;
|
2019-12-18 14:26:51 +00:00
|
|
|
|
|
|
|
QAction actionSetAsStringAuto;
|
|
|
|
QAction actionSetAsStringRemove;
|
|
|
|
QAction actionSetAsStringAdvanced;
|
2018-08-04 18:05:56 +00:00
|
|
|
|
|
|
|
QMenu *setToDataMenu;
|
2019-06-12 07:08:15 +00:00
|
|
|
QMenu *setAsMenu;
|
2019-12-18 14:26:51 +00:00
|
|
|
QMenu *setAsString;
|
2018-08-04 18:05:56 +00:00
|
|
|
QAction actionSetToDataEx;
|
|
|
|
QAction actionSetToDataByte;
|
|
|
|
QAction actionSetToDataWord;
|
|
|
|
QAction actionSetToDataDword;
|
|
|
|
QAction actionSetToDataQword;
|
|
|
|
|
2019-07-19 19:21:12 +00:00
|
|
|
QAction showInSubmenu;
|
2021-01-24 14:50:13 +00:00
|
|
|
QList<QAction *> showTargetMenuActions;
|
2020-02-04 09:02:34 +00:00
|
|
|
QMenu *pluginMenu = nullptr;
|
|
|
|
QAction *pluginActionMenuAction = nullptr;
|
2019-07-19 19:21:12 +00:00
|
|
|
|
2017-12-10 20:40:15 +00:00
|
|
|
// For creating anonymous entries (that are always visible)
|
2018-08-04 18:05:56 +00:00
|
|
|
QAction *addAnonymousAction(QString name, const char *slot, QKeySequence shortcut);
|
|
|
|
|
|
|
|
void initAction(QAction *action, QString name, const char *slot = nullptr);
|
|
|
|
void initAction(QAction *action, QString name, const char *slot, QKeySequence keySequence);
|
2021-01-24 14:50:13 +00:00
|
|
|
void initAction(QAction *action, QString name, const char *slot,
|
|
|
|
QList<QKeySequence> keySequence);
|
2018-08-04 18:05:56 +00:00
|
|
|
|
|
|
|
void setBase(QString base);
|
|
|
|
void setToData(int size, int repeat = 1);
|
|
|
|
void setBits(int bits);
|
|
|
|
|
|
|
|
void addSetBaseMenu();
|
|
|
|
void addSetBitsMenu();
|
2019-06-12 07:08:15 +00:00
|
|
|
void addSetAsMenu();
|
2018-08-04 18:05:56 +00:00
|
|
|
void addSetToDataMenu();
|
|
|
|
void addEditMenu();
|
2020-01-29 16:58:05 +00:00
|
|
|
void addBreakpointMenu();
|
2018-08-04 18:05:56 +00:00
|
|
|
void addDebugMenu();
|
2019-08-14 18:47:30 +00:00
|
|
|
|
2020-12-04 17:08:56 +00:00
|
|
|
enum DoRenameAction {
|
|
|
|
RENAME_FUNCTION,
|
|
|
|
RENAME_FLAG,
|
|
|
|
RENAME_ADD_FLAG,
|
|
|
|
RENAME_LOCAL,
|
|
|
|
RENAME_DO_NOTHING,
|
|
|
|
};
|
2021-01-24 14:50:13 +00:00
|
|
|
struct DoRenameInfo
|
|
|
|
{
|
2020-12-04 17:08:56 +00:00
|
|
|
ut64 addr;
|
|
|
|
QString name;
|
|
|
|
};
|
|
|
|
DoRenameAction doRenameAction = RENAME_DO_NOTHING;
|
2021-01-24 14:50:13 +00:00
|
|
|
DoRenameInfo doRenameInfo = {};
|
2020-12-04 17:08:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Setups up the "Rename" option in the context menu
|
|
|
|
*
|
2021-01-24 14:50:13 +00:00
|
|
|
* This function takes into account cursor location so it can choose between current address and
|
|
|
|
* pointed value i.e. `0x000040f3 lea rdi, [0x000199b1]` -> does the user want to add a flag at
|
|
|
|
* 0x40f3 or at 0x199b1? and for that we will rely on |curHighlightedWord| which is the
|
|
|
|
* currently selected word.
|
2020-12-04 17:08:56 +00:00
|
|
|
*/
|
|
|
|
void setupRenaming();
|
|
|
|
|
2020-07-28 19:49:50 +00:00
|
|
|
/**
|
|
|
|
* @brief Checks if the currently highlighted word in the disassembly widget
|
|
|
|
* is a local variable or function paramter.
|
2021-01-24 14:50:13 +00:00
|
|
|
* @return Return true if the highlighted word is the name of a local variable or function
|
|
|
|
* parameter, return false otherwise.
|
2020-07-28 19:49:50 +00:00
|
|
|
*/
|
|
|
|
bool isHighlightedWordLocalVar();
|
2021-01-24 14:50:13 +00:00
|
|
|
struct ThingUsedHere
|
|
|
|
{
|
2019-08-14 18:47:30 +00:00
|
|
|
QString name;
|
|
|
|
RVA offset;
|
2021-01-24 14:50:13 +00:00
|
|
|
enum class Type { Var, Function, Flag, Address };
|
2019-08-14 18:47:30 +00:00
|
|
|
Type type;
|
|
|
|
};
|
|
|
|
QVector<ThingUsedHere> getThingUsedHere(RVA offset);
|
|
|
|
|
2020-12-04 17:08:56 +00:00
|
|
|
/*
|
|
|
|
* @brief This function checks if the given address contains a function,
|
|
|
|
* a flag or if it is just an address.
|
|
|
|
*/
|
|
|
|
ThingUsedHere getThingAt(ut64 address);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief This function will set the text for the renaming menu given a ThingUsedHere
|
|
|
|
* and provide information on how to handle the renaming of this specific thing.
|
2021-01-24 14:50:13 +00:00
|
|
|
* Indeed, selected dialogs are different when it comes to adding a flag, renaming an existing
|
|
|
|
* function, renaming a local variable...
|
2020-12-04 17:08:56 +00:00
|
|
|
*
|
|
|
|
* This function handles every possible object.
|
|
|
|
*/
|
2021-01-24 14:50:13 +00:00
|
|
|
void buildRenameMenu(ThingUsedHere *tuh);
|
2017-10-10 10:17:05 +00:00
|
|
|
};
|
|
|
|
#endif // DISASSEMBLYCONTEXTMENU_H
|