cutter/src/menus/DisassemblyContextMenu.h

263 lines
7.9 KiB
C
Raw Normal View History

#ifndef DISASSEMBLYCONTEXTMENU_H
#define DISASSEMBLYCONTEXTMENU_H
#include "core/Cutter.h"
#include "common/IOModesController.h"
#include <QMenu>
#include <QKeySequence>
class MainWindow;
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
public:
DisassemblyContextMenu(QWidget *parent, MainWindow *mainWindow);
~DisassemblyContextMenu();
2017-12-02 15:43:21 +00:00
signals:
void copy();
public slots:
void setOffset(RVA offset);
2017-12-02 15:43:21 +00:00
void setCanCopy(bool enabled);
2019-03-06 20:30:39 +00:00
/**
* @brief Sets the value of curHighlightedWord
* @param text The current highlighted word
*/
void setCurHighlightedWord(const QString &text);
2017-11-28 13:50:41 +00:00
private slots:
void aboutToShowSlot();
void aboutToHideSlot();
2017-11-28 13:50:41 +00:00
void on_actionEditFunction_triggered();
void on_actionEditInstruction_triggered();
void on_actionNopInstruction_triggered();
void on_actionJmpReverse_triggered();
void on_actionEditBytes_triggered();
void showReverseJmpQuery();
2017-12-02 15:43:21 +00:00
void on_actionCopy_triggered();
void on_actionCopyAddr_triggered();
void on_actionAddComment_triggered();
void on_actionAnalyzeFunction_triggered();
void on_actionRename_triggered();
void on_actionSetFunctionVarTypes_triggered();
void on_actionXRefs_triggered();
void on_actionXRefsForVariables_triggered();
void on_actionDisplayOptions_triggered();
void on_actionDeleteComment_triggered();
void on_actionDeleteFlag_triggered();
void on_actionDeleteFunction_triggered();
2018-06-12 08:43:14 +00:00
void on_actionAddBreakpoint_triggered();
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();
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
* 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
* Opens the LinkTypeDialog box from where the user can link the address
* to a type
*/
void on_actionLinkType_triggered();
private:
2017-12-02 15:43:21 +00:00
QKeySequence getCopySequence() const;
QKeySequence getCommentSequence() const;
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;
QKeySequence getSetAsStringAdvanced() const;
2018-08-04 18:05:56 +00:00
QKeySequence getSetToDataSequence() const;
QKeySequence getSetToDataExSequence() const;
QKeySequence getRenameSequence() const;
QKeySequence getRetypeSequence() const;
QKeySequence getXRefSequence() const;
QKeySequence getDisplayOptionsSequence() const;
QKeySequence getDefineNewFunctionSequence() const;
QKeySequence getUndefineFunctionSequence() const;
QKeySequence getEditFunctionSequence() const;
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
*/
QKeySequence getLinkTypeSequence() const;
RVA offset;
2017-12-02 15:43:21 +00:00
bool canCopy;
QString curHighlightedWord; // The current highlighted word
MainWindow *mainWindow;
IOModesController ioModesController;
2017-12-02 15:43:21 +00:00
2018-03-21 20:32:32 +00:00
QList<QAction *> anonymousActions;
QMenu *editMenu;
QAction actionEditInstruction;
QAction actionNopInstruction;
QAction actionJmpReverse;
QAction actionEditBytes;
2017-12-02 15:43:21 +00:00
QAction actionCopy;
QAction *copySeparator;
QAction actionCopyAddr;
QAction actionAddComment;
QAction actionAnalyzeFunction;
QAction actionEditFunction;
QAction actionRename;
QAction actionSetFunctionVarTypes;
QAction actionXRefs;
QAction actionXRefsForVariables;
QAction actionDisplayOptions;
QAction actionDeleteComment;
QAction actionDeleteFlag;
QAction actionDeleteFunction;
QMenu *structureOffsetMenu;
QAction actionLinkType;
2017-11-28 13:50:41 +00:00
QMenu *setBaseMenu;
QAction actionSetBaseBinary;
QAction actionSetBaseOctal;
QAction actionSetBaseDecimal;
QAction actionSetBaseHexadecimal;
QAction actionSetBasePort;
QAction actionSetBaseIPAddr;
QAction actionSetBaseSyscall;
QAction actionSetBaseString;
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;
QAction actionSetPC;
QMenu *breakpointMenu;
2018-06-12 08:43:14 +00:00
QAction actionAddBreakpoint;
QAction actionAdvancedBreakpoint;
2018-06-12 08:43:14 +00:00
2018-08-04 18:05:56 +00:00
QAction actionSetToCode;
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;
QMenu *setAsString;
2018-08-04 18:05:56 +00:00
QAction actionSetToDataEx;
QAction actionSetToDataByte;
QAction actionSetToDataWord;
QAction actionSetToDataDword;
QAction actionSetToDataQword;
QAction showInSubmenu;
2021-01-24 14:50:13 +00:00
QList<QAction *> showTargetMenuActions;
QMenu *pluginMenu = nullptr;
QAction *pluginActionMenuAction = nullptr;
// 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();
void addBreakpointMenu();
2018-08-04 18:05:56 +00:00
void addDebugMenu();
enum DoRenameAction {
RENAME_FUNCTION,
RENAME_FLAG,
RENAME_ADD_FLAG,
RENAME_LOCAL,
RENAME_DO_NOTHING,
};
2021-01-24 14:50:13 +00:00
struct DoRenameInfo
{
ut64 addr;
QString name;
};
DoRenameAction doRenameAction = RENAME_DO_NOTHING;
2021-01-24 14:50:13 +00:00
DoRenameInfo doRenameInfo = {};
/*
* @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.
*/
void setupRenaming();
/**
* @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.
*/
bool isHighlightedWordLocalVar();
2021-01-24 14:50:13 +00:00
struct ThingUsedHere
{
QString name;
RVA offset;
2021-01-24 14:50:13 +00:00
enum class Type { Var, Function, Flag, Address };
Type type;
};
QVector<ThingUsedHere> getThingUsedHere(RVA offset);
/*
* @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...
*
* This function handles every possible object.
*/
2021-01-24 14:50:13 +00:00
void buildRenameMenu(ThingUsedHere *tuh);
};
#endif // DISASSEMBLYCONTEXTMENU_H