def install(self): action_name = self.__class__.__name__ # Read and load the icon file icon_data = str(open(self._icon, "rb").read()) self._icon_id = ida_kernwin.load_custom_icon(data=icon_data) # Create the action descriptor action_desc = ida_kernwin.action_desc_t( self._ACTION_ID, self._text, self._handler, None, self._tooltip, self._icon_id, ) # Register the action using its descriptor result = ida_kernwin.register_action(action_desc) if not result: raise RuntimeError("Failed to register action %s" % action_name) # Attach the action to the chosen menu result = ida_kernwin.attach_action_to_menu( self._menu, self._ACTION_ID, ida_kernwin.SETMENU_APP ) if not result: action_name = self.__class__.__name__ raise RuntimeError("Failed to install action %s" % action_name) self._plugin.logger.debug("Installed action %s" % action_name) return True
def install(self): """ Install the action into the IDA UI. :return: did the install succeed """ # Read and load the icon file iconData = str(open(self._icon, 'rb').read()) self._iconId = ida_kernwin.load_custom_icon(data=iconData) # Create the action description actionDesc = ida_kernwin.action_desc_t(self._ACTION_ID, self._text, self._handler, None, self._tooltip, self._iconId) # Register the action using its description result = ida_kernwin.register_action(actionDesc) if not result: raise RuntimeError("Failed to register action") # Attach the action to the chosen menu result = ida_kernwin.attach_action_to_menu(self._menu, self._ACTION_ID, ida_kernwin.SETMENU_APP) if not result: raise RuntimeError("Failed to attach action") logger.debug("Installed the action") return True
def add_action(action): """ Add an ida-action :param action: action given as the `Action` namedtuple :return: None """ class Handler(ida_kernwin.action_handler_t): def __init__(self): ida_kernwin.action_handler_t.__init__(self) def activate(self, ctx): action.handler() return 1 def update(self, ctx): return ida_kernwin.AST_ENABLE_FOR_WIDGET act_icon = -1 if action.icon_filename: icon_full_filename = \ pkg_resources.resource_filename('fa', os.path.join( 'res', 'icons', action.icon_filename)) with open(icon_full_filename, 'rb') as f: icon_data = f.read() act_icon = ida_kernwin.load_custom_icon(data=icon_data, format="png") act_name = action.name ida_kernwin.unregister_action(act_name) if ida_kernwin.register_action(ida_kernwin.action_desc_t( act_name, # Name. Acts as an ID. Must be unique. action.label, # Label. That's what users see. Handler(), # Handler. Called when activated, and for updating action.hotkey, # Shortcut (optional) None, # Tooltip (optional) act_icon)): # Icon ID (optional) # Insert the action in the menu if not ida_kernwin.attach_action_to_menu( "FA/", act_name, ida_kernwin.SETMENU_APP): print("Failed attaching to menu.") # Insert the action in a toolbar if not ida_kernwin.attach_action_to_toolbar("fa", act_name): print("Failed attaching to toolbar.") class Hooks(ida_kernwin.UI_Hooks): def finish_populating_widget_popup(self, widget, popup): if ida_kernwin.get_widget_type(widget) == \ ida_kernwin.BWN_DISASM: ida_kernwin.attach_action_to_popup(widget, popup, act_name, None) hooks = Hooks() hooks.hook()
def install_icon(): plugin_name = CapaExplorerPlugin.PLUGIN_NAME action_name = "Edit/Plugins/" + plugin_name if action_name not in ida_kernwin.get_registered_actions(): # keep the hook registered return False # resource leak here. need to call `ida_kernwin.free_custom_icon`? # however, since we're not cycling this icon a lot, its probably ok. # expect to leak exactly one icon per application load. icon = ida_kernwin.load_custom_icon(data=ICON) ida_kernwin.update_action_icon(action_name, icon) # uninstall the hook return True
def editor_menuaction(self): action_desc = ida_kernwin.action_desc_t( 'my:editoraction', # The action name. This acts like an ID and must be unique 'Python Editor!', # The action text. MyEditorHandler(), # The action handler. 'Ctrl+H', # Optional: the action shortcut DO IT HERE! 'Script editor', # Optional: the action tooltip (available in menus/toolbar) ida_kernwin.load_custom_icon(":/ico/python.png") # hackish load action icon , if no custom icon use number from 1-150 from internal ida ) # 3) Register the action ida_kernwin.register_action(action_desc) ida_kernwin.attach_action_to_menu( 'Edit/Editor...', # The relative path of where to add the action 'my:editoraction', # The action ID (see above) ida_kernwin.SETMENU_APP) # We want to append the action after the 'Manual instruction... ida_kernwin.get_current_widget() ida_kernwin.attach_action_to_popup(form, None, "my:editoraction", None)
def _install_prev_execution(self): icon_data = self.palette.gen_arrow_icon(self.palette.arrow_prev, 180.0) self._icon_id_prev_execution = ida_kernwin.load_custom_icon( data=icon_data) # describe a custom IDA UI action action_desc = ida_kernwin.action_desc_t( self.ACTION_PREV_EXECUTION, # The action name "Go to previous execution", # The action text IDACtxEntry( self._interactive_prev_execution), # The action handler None, # Optional: action shortcut "Go to the previous execution of the current address", # Optional: tooltip self._icon_id_prev_execution # Optional: the action icon ) # register the action with IDA result = ida_kernwin.register_action(action_desc) assert result, f"Failed to register '{action_desc.name}' action with IDA" logger.info(f"Installed the '{action_desc.name}' menu entry")
def activate(self, ctx): g = globals() idahome = ida_diskio.idadir("plugins\\Code editor") tupac = str(idahome + "\\pyeditor.py") ida_kernwin.load_custom_icon(":/ico/python.png") load_and_run_plugin(tupac, True)
b"\x22\x02\xD0\x40\xE4\x81\x6C\x3B\x76\x37\x56\xE3\x37\x5F\x2F\x62\xE8\x0B\xD3\x66\x19\x7E\x53\xA7\x99\x78\xAE\x1F\x64\x3E\x21\x71\x69\x09\x5F\x20\x98\x2D\x58\x70\x24\x07\x07\x7B", b"\x6F\xB0\x79\x82\x61\x81\x21\xCC\xDE\x21\x54\x16\x02\xD4\x69\x26\x9E\x74\xEE\xCB\xCF\x4D\xC7\x44\xB3\x88\x7C\x81\xC5\x22\xFE\x6C\xB9\xE9\x46\x67\x46\x1A\x8A\x16\x2B\x0A\x5B\x05", b"\x74\x66\x65\xE1\x98\x6F\x00\x31\x32\x87\x9F\x59\x77\x66\x66\x61\x42\xBC\xC0\xF5\x6C\x47\x1A\x36\xD7\xB9\x51\x14\xC5\x1E\xBE\xA0\xC3\x5B\xD9\x98\x99\xE1\xC0\xCE\xBE\x57\x48\xD7", b"\x9A\x63\x68\xEA\x7C\x8A\xF6\x14\x3B\x9F\xF6\xA6\xA4\x60\xEB\xE3\x3E\x9C\x5F\xD6\x5A\x7A\xFA\x71\xBF\xC3\x81\x3D\x4D\x35\x0D\x7C\xC1\xF3\x87\x57\x43\xF9\x87\x8F\x21\x95\x5E\xAB", b"\x41\x83\x4E\x83\x54\xDB\x92\x76\x20\xCA\xBF\xD0\x99\x9D\xBB\x4E\xDB\xBD\xC7\x8E\x2F\x5A\x3D\x74\x3D\x50\x03\x80\x7E\x7A\x7A\x06\x46\x47\xFD\xA0\x33\x6C\x84\x18\x46\x0C\xBD\x1F", b"\x86\x2D\x71\x71\x00\x52\x10\x16\x17\xE6\xC1\xE7\x1B\x61\x9A\x81\x69\x31\x30\xFC\x61\x14\xB4\x3A\x3D\x20\x82\x1E\x58\xA9\x15\x05\x41\x14\x05\xB8\x58\xEE\x82\x7D\xE9\x99\x20\xCB", b"\x32\x94\x95\x95\xC3\xA5\xD2\x53\x00\x51\x09\xAA\x4B\x0B\xA1\xB8\xA4\x0C\x52\x53\x33\x40\xA5\x52\x81\xDB\x5D\x01\xA2\x45\x00\x45\x51\x80\x2A\x36\x12\x8D\x42\x49\x51\x01\x44\xE5", b"\x18\x90\x22\x0A\x98\x8C\x46\xF0\x54\x14\x42\x6D\x7D\x3B\xE4\x1C\x75\x41\xAD\xB7\x1D\x3C\x55\x85\x60\x32\x19\x41\x8A\x2A\xDC\x57\x5C\x74\x12\x28\x47\xA5\x8E\x44\xE4\xF0\x76\x5B", b"\x82\xA6\xCD\x5B\x0D\xB2\x12\xE6\xE4\x06\xB5\x1A\x66\xA7\x26\x41\x92\xC2\xA0\xD5\x6A\x60\x67\x92\x19\xAE\x7B\xCE\x70\x4D\x15\xAB\x01\xAD\xC1\x08\x3F\x46\x64\x6E\x8E\x9D\xF9\x13", b"\xE8\x1A\xFF\xE4\x63\x8A\x0E\xE6\x02\x41\xF8\x3F\x18\x82\x40\x28\x04\xFD\xDD\x75\xF0\xB6\xFF\x2E\x75\x9A\x89\x27\x9D\xFB\xC8\x4F\x39\xBE\xE0\xB4\xAB\xCE\x35\xFE\x71\x00\x16\x17", b"\x25\x76\x50\x26\x76\x6B\x61\x86\x08\xE4\x1D\xAF\x81\xBC\x13\x97\xA9\xD3\x4C\x3C\xE9\xDC\x47\x7E\xCA\xF1\x05\x0C\x5F\x7D\xFE\xEF\x35\x03\xAF\x9F\x00\xB0\x73\x30\x9A\xE2\x81\x0E", b"\xF6\xC1\xED\x52\xB8\x77\xAB\x98\x3A\xCD\xC4\x73\x9D\x7C\x6F\xDE\xF9\xCF\x53\x0E\xFE\xA9\xCD\xAE\xB3\x87\xCE\x75\x35\x54\xE1\xD0\xCB\x47\x38\x39\x36\x88\xFF\x4D\xF8\x57\x41\x33", b"\xF1\xA4\x93\x0F\x00\x36\xAD\x3E\x4C\x6B\xC5\xC9\x5D\x77\x6A\x2F\xB4\x31\xA3\xC4\x40\x4F\x21\x0F\xD1\x4C\x3C\xE9\x2B\xE1\xF5\x0B\xD6\x90\xC8\x90\x4C\xE6\x35\xD0\xCC\x79\x5E\xFF", b"\x2E\xF8\x0B\x2F\x3D\xE5\xC3\x97\x06\xCF\xCF\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82" ]) act_icon = ida_kernwin.load_custom_icon(data=icon_data, format="png") hooks = None act_name = "example:add_action" if ida_kernwin.register_action( ida_kernwin.action_desc_t( act_name, # Name. Acts as an ID. Must be unique. "Say hi!", # Label. That's what users see. SayHi("developer" ), # Handler. Called when activated, and for updating "Ctrl+F12", # Shortcut (optional) "Greets the user", # Tooltip (optional) act_icon)): # Icon ID (optional) print("Action registered. Attaching to menu.")