def init(self):
global initialized
if initialized == False:
initialized = True
# menu = idaapi.add_menu_item("Edit/x64dbgida/", "About", "", 0,
# self.about, None)
# if menu is not None:
idaapi.attach_action_to_menu("Edit/x64dbgida/", 'my:exportdb', idaapi.SETMENU_APP)
idaapi.attach_action_to_menu("Edit/x64dbgida/", 'my:importdb', idaapi.SETMENU_APP)
# idaapi.add_menu_item("Edit/x64dbgida/",
# "Import (uncompressed) database", "", 0,
# self.importdb, None)
# elif idaapi.IDA_SDK_VERSION < 680:
# idaapi.add_menu_item("File/Produce file/",
# "Export x64dbg database", "", 0,
# self.exportdb, None)
# idaapi.add_menu_item("File/Load file/",
# "Import x64dbg database", "", 0,
# self.importdb, None)
return idaapi.PLUGIN_OK
python类attach_action_to_menu()的实例源码
def ui_init(self):
"""Initializes the plugins interface extensions."""
# Register menu entry.
# @HR: I really preferred the pre-6.5 mechanic.
zelf = self
class MenuEntry(idaapi.action_handler_t):
def activate(self, ctx):
zelf.open_proj_creation_dialog()
return 1
def update(self, ctx):
return idaapi.AST_ENABLE_ALWAYS
action = idaapi.action_desc_t(
'continuum_new_project',
"New continuum project...",
MenuEntry(),
)
idaapi.register_action(action)
idaapi.attach_action_to_menu("File/Open...", 'continuum_new_project', 0)
# Alright, is an IDB loaded? Pretend IDB open event as we miss the callback
# when it was loaded before our plugin was staged.
if GetIdbPath():
self.core.handle_open_idb(None, None)
# Register hotkeys.
idaapi.add_hotkey('Shift+F', self.core.follow_extern)
# Sign up for events.
self.core.project_opened.connect(self.create_proj_explorer)
self.core.project_closing.connect(self.close_proj_explorer)
self.core.client_created.connect(self.subscribe_client_events)
# Project / client already open? Fake events.
if self.core.project:
self.create_proj_explorer(self.core.project)
if self.core.client:
self.subscribe_client_events(self.core.client)
def _install_load_file(self):
"""
Install the 'File->Load->Code coverage file...' menu entry.
"""
# create a custom IDA icon
icon_path = plugin_resource(os.path.join("icons", "load.png"))
icon_data = str(open(icon_path, "rb").read())
self._icon_id_file = idaapi.load_custom_icon(data=icon_data)
# describe a custom IDA UI action
action_desc = idaapi.action_desc_t(
self.ACTION_LOAD_FILE, # The action name.
"~C~ode coverage file...", # The action text.
IDACtxEntry(self.interactive_load_file), # The action handler.
None, # Optional: action shortcut
"Load individual code coverage file(s)", # Optional: tooltip
self._icon_id_file # Optional: the action icon
)
# register the action with IDA
result = idaapi.register_action(action_desc)
if not result:
RuntimeError("Failed to register load_file action with IDA")
# attach the action to the File-> dropdown menu
result = idaapi.attach_action_to_menu(
"File/Load file/", # Relative path of where to add the action
self.ACTION_LOAD_FILE, # The action ID (see above)
idaapi.SETMENU_APP # We want to append the action after ^
)
if not result:
RuntimeError("Failed action attach load_file")
logger.info("Installed the 'Code coverage file' menu entry")
def _install_load_batch(self):
"""
Install the 'File->Load->Code coverage batch...' menu entry.
"""
# create a custom IDA icon
icon_path = plugin_resource(os.path.join("icons", "batch.png"))
icon_data = str(open(icon_path, "rb").read())
self._icon_id_batch = idaapi.load_custom_icon(data=icon_data)
# describe a custom IDA UI action
action_desc = idaapi.action_desc_t(
self.ACTION_LOAD_BATCH, # The action name.
"~C~ode coverage batch...", # The action text.
IDACtxEntry(self.interactive_load_batch), # The action handler.
None, # Optional: action shortcut
"Load and aggregate code coverage files", # Optional: tooltip
self._icon_id_batch # Optional: the action icon
)
# register the action with IDA
result = idaapi.register_action(action_desc)
if not result:
RuntimeError("Failed to register load_batch action with IDA")
# attach the action to the File-> dropdown menu
result = idaapi.attach_action_to_menu(
"File/Load file/", # Relative path of where to add the action
self.ACTION_LOAD_BATCH, # The action ID (see above)
idaapi.SETMENU_APP # We want to append the action after ^
)
if not result:
RuntimeError("Failed action attach load_batch")
logger.info("Installed the 'Code coverage batch' menu entry")
def _install_open_coverage_overview(self):
"""
Install the 'View->Open subviews->Coverage Overview' menu entry.
"""
# create a custom IDA icon
icon_path = plugin_resource(os.path.join("icons", "overview.png"))
icon_data = str(open(icon_path, "rb").read())
self._icon_id_overview = idaapi.load_custom_icon(data=icon_data)
# describe a custom IDA UI action
action_desc = idaapi.action_desc_t(
self.ACTION_COVERAGE_OVERVIEW, # The action name.
"~C~overage Overview", # The action text.
IDACtxEntry(self.open_coverage_overview), # The action handler.
None, # Optional: action shortcut
"Open database code coverage overview", # Optional: tooltip
self._icon_id_overview # Optional: the action icon
)
# register the action with IDA
result = idaapi.register_action(action_desc)
if not result:
RuntimeError("Failed to register open coverage overview action with IDA")
# attach the action to the View-> dropdown menu
result = idaapi.attach_action_to_menu(
"View/Open subviews/Hex dump", # Relative path of where to add the action
self.ACTION_COVERAGE_OVERVIEW, # The action ID (see above)
idaapi.SETMENU_INS # We want to insert the action before ^
)
if not result:
RuntimeError("Failed action attach to 'View/Open subviews' dropdown")
logger.info("Installed the 'Coverage Overview' menu entry")
def init():
if not idaapi.init_hexrays_plugin():
print "[ERROR] Failed to initialize Hex-Rays SDK"
return idaapi.PLUGIN_SKIP
Helper.temporary_structure = TemporaryStructureModel()
# Actions.register(Actions.CreateVtable)
Actions.register(Actions.ShowGraph)
Actions.register(Actions.ShowClasses)
Actions.register(Actions.GetStructureBySize)
Actions.register(Actions.RemoveArgument)
Actions.register(Actions.AddRemoveReturn)
Actions.register(Actions.ConvertToUsercall)
Actions.register(Actions.ShallowScanVariable, Helper.temporary_structure)
Actions.register(Actions.DeepScanVariable, Helper.temporary_structure)
Actions.register(Actions.DeepScanReturn, Helper.temporary_structure)
Actions.register(Actions.DeepScanFunctions, Helper.temporary_structure)
Actions.register(Actions.RecognizeShape)
Actions.register(Actions.CreateNewField)
Actions.register(Actions.SelectContainingStructure, potential_negatives)
Actions.register(Actions.ResetContainingStructure)
Actions.register(Actions.RecastItemRight)
Actions.register(Actions.RecastItemLeft)
Actions.register(Actions.RenameOther)
Actions.register(Actions.RenameInside)
Actions.register(Actions.RenameOutside)
Actions.register(Actions.SwapThenElse)
idaapi.attach_action_to_menu('View/Open subviews/Local types', Actions.ShowClasses.name, idaapi.SETMENU_APP)
idaapi.install_hexrays_callback(hexrays_events_callback)
Helper.touched_functions.clear()
Const.init()
return idaapi.PLUGIN_KEEP
def init(self):
self.lines = set()
self.settings = IDASettings('HighlightCalls')
try:
self.set_color(self.settings['color'])
except KeyError:
self.settings.user['color'] = HIGHLIGHT_COLOR
self.set_color(HIGHLIGHT_COLOR)
self.ui_hooks = UiHooks(self.lines)
self.toggle_action_desc = idaapi.action_desc_t('HighlightCalls:Toggle',
'Toggle call highlighting',
ToggleHighlightHandler(self.enable_highlights,
self.disable_highlights),
'',
'Toggle call highlighting',
-1)
idaapi.register_action(self.toggle_action_desc)
self.color_selector = idaapi.action_desc_t('HighlightCalls:SelectColor',
'Select highlight color',
SelectColorHandler(set_color=self.set_color),
'',
'Select highlight color',
-1)
idaapi.register_action(self.color_selector)
idaapi.attach_action_to_menu('Edit/', self.toggle_action_desc.name, idaapi.SETMENU_APP)
idaapi.attach_action_to_menu('Edit/', self.color_selector.name, idaapi.SETMENU_APP)
return idaapi.PLUGIN_KEEP
def registerAction(self):
action_desc = idaapi.action_desc_t(
self.id,
self.name,
self,
self.shortcut,
self.tooltip,
0
)
if not idaapi.register_action(action_desc):
return False
if not idaapi.attach_action_to_menu(self.menuPath, self.id, 0):
return False
return True
def register_actions():
AncestorGraphHandler = OpenGraphHandler()
def type_of_current_var(vdui):
var = vdui.item.get_lvar()
if var is None:
return None
return get_type_by_tinfo(var.type())
def graph_callback(event, *args):
if event == idaapi.hxe_curpos:
vdui = args[0]
type = type_of_current_var(vdui)
AncestorGraphHandler.target_type = type
elif event == idaapi.hxe_populating_popup:
form, popup, vdui = args
if AncestorGraphHandler.target_type is None:
return 0
action_desc = idaapi.action_desc_t(
None,
'Open Ancestor Type Graph',
AncestorGraphHandler)
idaapi.attach_dynamic_action_to_popup(form, popup, action_desc, None)
return 0
action_desc = idaapi.action_desc_t(
'devirtualize:open_ancestor_type_graph',
'Open Ancestor Type Graph',
AncestorGraphHandler,
None,
'Open Ancestor Type Graph',
199)
idaapi.register_action(action_desc)
idaapi.attach_action_to_menu(
'View/Graphs/User xrefs char...',
'devirtualize:open_ancestor_type_graph',
idaapi.SETMENU_APP)
idaapi.install_hexrays_callback(graph_callback)
#TODO: Show diamond inheritance as a diamond