|
| 1 | +import idaapi |
| 2 | +import inspect |
| 3 | + |
| 4 | +from hexforge_modules import crypto, encoding, misc |
| 5 | + |
| 6 | + |
| 7 | +CRYPTO_MODULE_PATH = "HexForge/crypto/" |
| 8 | +ENCODING_MODULE_PATH = "HexForge/encoding/" |
| 9 | +MISC_MODULE_PATH = "HexForge/misc/" |
| 10 | + |
| 11 | +g_crypto_modules = [cls() for _, cls in inspect.getmembers(crypto, inspect.isclass)] |
| 12 | +g_encoding_modules = [cls() for _, cls in inspect.getmembers(encoding, inspect.isclass)] |
| 13 | +g_misc_modules = [cls() for _, cls in inspect.getmembers(misc, inspect.isclass)] |
| 14 | + |
| 15 | + |
| 16 | +class hexforge_plugin_t(idaapi.plugin_t): |
| 17 | + flags = idaapi.PLUGIN_KEEP |
| 18 | + comment = "" |
| 19 | + help = "" |
| 20 | + wanted_name = "HexForge" |
| 21 | + |
| 22 | + def init(self): |
| 23 | + idaapi.msg("init() called!\n") |
| 24 | + self._init_actions() |
| 25 | + self._init_hooks() |
| 26 | + return idaapi.PLUGIN_KEEP |
| 27 | + |
| 28 | + def run(self, arg): |
| 29 | + idaapi.msg("run() called with %d!\n" % arg) |
| 30 | + |
| 31 | + def term(self): |
| 32 | + self._del_action() |
| 33 | + idaapi.msg("term() called!\n") |
| 34 | + |
| 35 | + # -------------------------------------------------------------------------- |
| 36 | + # Initializations |
| 37 | + # -------------------------------------------------------------------------- |
| 38 | + |
| 39 | + def _init_actions(self) -> None: |
| 40 | + for module in g_crypto_modules + g_encoding_modules + g_misc_modules: |
| 41 | + module.init_action() |
| 42 | + |
| 43 | + def _del_action(self) -> None: |
| 44 | + for module in g_crypto_modules + g_encoding_modules + g_misc_modules: |
| 45 | + module.del_action() |
| 46 | + |
| 47 | + # -------------------------------------------------------------------------- |
| 48 | + # Initialize Hooks |
| 49 | + # -------------------------------------------------------------------------- |
| 50 | + |
| 51 | + def _init_hooks(self) -> None: |
| 52 | + """ |
| 53 | + Install plugin hooks into IDA. |
| 54 | + """ |
| 55 | + self._hooks = Hooks() |
| 56 | + self._hooks.hook() |
| 57 | + |
| 58 | + |
| 59 | +# Plugin Hooks |
| 60 | + |
| 61 | + |
| 62 | +class Hooks(idaapi.UI_Hooks): |
| 63 | + def finish_populating_widget_popup(self, widget, popup): |
| 64 | + """ |
| 65 | + A right click menu is about to be shown. (IDA 7) |
| 66 | + """ |
| 67 | + inject_actions(widget, popup, idaapi.get_widget_type(widget)) |
| 68 | + return 0 |
| 69 | + |
| 70 | + |
| 71 | +# Prefix Wrappers |
| 72 | + |
| 73 | + |
| 74 | +def inject_actions(form, popup, form_type) -> int: |
| 75 | + """ |
| 76 | + Inject actions to popup menu(s) based on context. |
| 77 | + """ |
| 78 | + |
| 79 | + if (form_type == idaapi.BWN_DISASMS) or (form_type == idaapi.BWN_DUMP): |
| 80 | + for module in g_crypto_modules: |
| 81 | + idaapi.attach_action_to_popup( |
| 82 | + form, |
| 83 | + popup, |
| 84 | + module.ACTION_NAME, |
| 85 | + CRYPTO_MODULE_PATH, |
| 86 | + idaapi.SETMENU_APP, |
| 87 | + ) |
| 88 | + |
| 89 | + for module in g_misc_modules: |
| 90 | + idaapi.attach_action_to_popup( |
| 91 | + form, |
| 92 | + popup, |
| 93 | + module.ACTION_NAME, |
| 94 | + MISC_MODULE_PATH, |
| 95 | + idaapi.SETMENU_APP, |
| 96 | + ) |
| 97 | + |
| 98 | + for module in g_encoding_modules: |
| 99 | + idaapi.attach_action_to_popup( |
| 100 | + form, |
| 101 | + popup, |
| 102 | + module.ACTION_NAME, |
| 103 | + ENCODING_MODULE_PATH, |
| 104 | + idaapi.SETMENU_APP, |
| 105 | + ) |
| 106 | + |
| 107 | + return 0 |
| 108 | + |
| 109 | + |
| 110 | +# Register IDA plugin |
| 111 | +def PLUGIN_ENTRY() -> hexforge_plugin_t: |
| 112 | + return hexforge_plugin_t() |
| 113 | + |
| 114 | + |
| 115 | +PLUGIN_ENTRY() |
0 commit comments