1 #ifndef DISASSEMBLYCONTEXTMENU_H 2 #define DISASSEMBLYCONTEXTMENU_H 3 4 #include "core/Cutter.h" 5 #include "common/IOModesController.h" 6 #include <QMenu> 7 #include <QKeySequence> 8 9 class MainWindow; 10 11 class CUTTER_EXPORT DisassemblyContextMenu : public QMenu 12 { 13 Q_OBJECT 14 15 public: 16 DisassemblyContextMenu(QWidget *parent, MainWindow *mainWindow); 17 ~DisassemblyContextMenu(); 18 19 signals: 20 void copy(); 21 22 public slots: 23 void setOffset(RVA offset); 24 void setCanCopy(bool enabled); 25 26 /** 27 * @brief Sets the value of curHighlightedWord 28 * @param text The current highlighted word 29 */ 30 void setCurHighlightedWord(const QString &text); 31 32 private slots: 33 void aboutToShowSlot(); 34 void aboutToHideSlot(); 35 36 void on_actionEditFunction_triggered(); 37 void on_actionEditInstruction_triggered(); 38 void on_actionNopInstruction_triggered(); 39 void on_actionJmpReverse_triggered(); 40 void on_actionEditBytes_triggered(); 41 void showReverseJmpQuery(); 42 43 void on_actionCopy_triggered(); 44 void on_actionCopyAddr_triggered(); 45 void on_actionAddComment_triggered(); 46 void on_actionAnalyzeFunction_triggered(); 47 void on_actionRename_triggered(); 48 void on_actionSetFunctionVarTypes_triggered(); 49 void on_actionXRefs_triggered(); 50 void on_actionXRefsForVariables_triggered(); 51 void on_actionDisplayOptions_triggered(); 52 53 void on_actionDeleteComment_triggered(); 54 void on_actionDeleteFlag_triggered(); 55 void on_actionDeleteFunction_triggered(); 56 57 void on_actionAddBreakpoint_triggered(); 58 void on_actionAdvancedBreakpoint_triggered(); 59 void on_actionContinueUntil_triggered(); 60 void on_actionSetPC_triggered(); 61 62 void on_actionSetToCode_triggered(); 63 void on_actionSetAsString_triggered(); 64 void on_actionSetAsStringRemove_triggered(); 65 void on_actionSetAsStringAdvanced_triggered(); 66 void on_actionSetToData_triggered(); 67 void on_actionSetToDataEx_triggered(); 68 69 /** 70 * @brief Executed on selecting an offset from the structureOffsetMenu 71 * Uses the applyStructureOffset() function of CutterCore to apply the 72 * structure offset 73 * \param action The action which trigered the event 74 */ 75 void on_actionStructureOffsetMenu_triggered(QAction *action); 76 77 /** 78 * @brief Executed on selecting the "Link Type to Address" option 79 * Opens the LinkTypeDialog box from where the user can link the address 80 * to a type 81 */ 82 void on_actionLinkType_triggered(); 83 84 private: 85 QKeySequence getCopySequence() const; 86 QKeySequence getCommentSequence() const; 87 QKeySequence getCopyAddressSequence() const; 88 QKeySequence getSetToCodeSequence() const; 89 QKeySequence getSetAsStringSequence() const; 90 QKeySequence getSetAsStringAdvanced() const; 91 QKeySequence getSetToDataSequence() const; 92 QKeySequence getSetToDataExSequence() const; 93 QKeySequence getRenameSequence() const; 94 QKeySequence getRetypeSequence() const; 95 QKeySequence getXRefSequence() const; 96 QKeySequence getDisplayOptionsSequence() const; 97 QKeySequence getDefineNewFunctionSequence() const; 98 QKeySequence getUndefineFunctionSequence() const; 99 QKeySequence getEditFunctionSequence() const; 100 QList<QKeySequence> getAddBPSequence() const; 101 102 /** 103 * @return the shortcut key for "Link Type to Address" option 104 */ 105 QKeySequence getLinkTypeSequence() const; 106 107 108 RVA offset; 109 bool canCopy; 110 QString curHighlightedWord; // The current highlighted word 111 MainWindow *mainWindow; 112 IOModesController ioModesController; 113 114 QList<QAction *> anonymousActions; 115 116 QMenu *editMenu; 117 QAction actionEditInstruction; 118 QAction actionNopInstruction; 119 QAction actionJmpReverse; 120 QAction actionEditBytes; 121 122 QAction actionCopy; 123 QAction *copySeparator; 124 QAction actionCopyAddr; 125 126 127 QAction actionAddComment; 128 QAction actionAnalyzeFunction; 129 QAction actionEditFunction; 130 QAction actionRename; 131 QAction actionSetFunctionVarTypes; 132 QAction actionXRefs; 133 QAction actionXRefsForVariables; 134 QAction actionDisplayOptions; 135 136 QAction actionDeleteComment; 137 QAction actionDeleteFlag; 138 QAction actionDeleteFunction; 139 140 QMenu *structureOffsetMenu; 141 142 QAction actionLinkType; 143 144 QMenu *setBaseMenu; 145 QAction actionSetBaseBinary; 146 QAction actionSetBaseOctal; 147 QAction actionSetBaseDecimal; 148 QAction actionSetBaseHexadecimal; 149 QAction actionSetBasePort; 150 QAction actionSetBaseIPAddr; 151 QAction actionSetBaseSyscall; 152 QAction actionSetBaseString; 153 154 QMenu *setBitsMenu; 155 QAction actionSetBits16; 156 QAction actionSetBits32; 157 QAction actionSetBits64; 158 159 QMenu *debugMenu; 160 QAction actionContinueUntil; 161 QAction actionSetPC; 162 163 QMenu *breakpointMenu; 164 QAction actionAddBreakpoint; 165 QAction actionAdvancedBreakpoint; 166 167 QAction actionSetToCode; 168 169 QAction actionSetAsStringAuto; 170 QAction actionSetAsStringRemove; 171 QAction actionSetAsStringAdvanced; 172 173 QMenu *setToDataMenu; 174 QMenu *setAsMenu; 175 QMenu *setAsString; 176 QAction actionSetToDataEx; 177 QAction actionSetToDataByte; 178 QAction actionSetToDataWord; 179 QAction actionSetToDataDword; 180 QAction actionSetToDataQword; 181 182 QAction showInSubmenu; 183 QList<QAction*> showTargetMenuActions; 184 QMenu *pluginMenu = nullptr; 185 QAction *pluginActionMenuAction = nullptr; 186 187 // For creating anonymous entries (that are always visible) 188 QAction *addAnonymousAction(QString name, const char *slot, QKeySequence shortcut); 189 190 void initAction(QAction *action, QString name, const char *slot = nullptr); 191 void initAction(QAction *action, QString name, const char *slot, QKeySequence keySequence); 192 void initAction(QAction *action, QString name, const char *slot, QList<QKeySequence> keySequence); 193 194 void setBase(QString base); 195 void setToData(int size, int repeat = 1); 196 void setBits(int bits); 197 198 void addSetBaseMenu(); 199 void addSetBitsMenu(); 200 void addSetAsMenu(); 201 void addSetToDataMenu(); 202 void addEditMenu(); 203 void addBreakpointMenu(); 204 void addDebugMenu(); 205 206 enum DoRenameAction { 207 RENAME_FUNCTION, 208 RENAME_FLAG, 209 RENAME_ADD_FLAG, 210 RENAME_LOCAL, 211 RENAME_DO_NOTHING, 212 }; 213 struct DoRenameInfo { 214 ut64 addr; 215 QString name; 216 }; 217 DoRenameAction doRenameAction = RENAME_DO_NOTHING; 218 DoRenameInfo doRenameInfo = { }; 219 220 /* 221 * @brief Setups up the "Rename" option in the context menu 222 * 223 * This function takes into account cursor location so it can choose between current address and pointed value 224 * i.e. `0x000040f3 lea rdi, [0x000199b1]` -> does the user want to add a flag at 0x40f3 or at 0x199b1? 225 * and for that we will rely on |curHighlightedWord| which is the currently selected word. 226 */ 227 void setupRenaming(); 228 229 /** 230 * @brief Checks if the currently highlighted word in the disassembly widget 231 * is a local variable or function paramter. 232 * @return Return true if the highlighted word is the name of a local variable or function parameter, 233 * return false otherwise. 234 */ 235 bool isHighlightedWordLocalVar(); 236 struct ThingUsedHere { 237 QString name; 238 RVA offset; 239 enum class Type { 240 Var, 241 Function, 242 Flag, 243 Address 244 }; 245 Type type; 246 }; 247 QVector<ThingUsedHere> getThingUsedHere(RVA offset); 248 249 /* 250 * @brief This function checks if the given address contains a function, 251 * a flag or if it is just an address. 252 */ 253 ThingUsedHere getThingAt(ut64 address); 254 255 /* 256 * @brief This function will set the text for the renaming menu given a ThingUsedHere 257 * and provide information on how to handle the renaming of this specific thing. 258 * Indeed, selected dialogs are different when it comes to adding a flag, renaming an existing function, 259 * renaming a local variable... 260 * 261 * This function handles every possible object. 262 */ 263 void buildRenameMenu(ThingUsedHere* tuh); 264 }; 265 #endif // DISASSEMBLYCONTEXTMENU_H 266