Skip to content

Instantly share code, notes, and snippets.

@alexander-hanel
Created August 21, 2021 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexander-hanel/d3d756d1f6bea51065fad298ae7f6406 to your computer and use it in GitHub Desktop.
Save alexander-hanel/d3d756d1f6bea51065fad298ae7f6406 to your computer and use it in GitHub Desktop.
IconExample IDAPYTHON
import ida_kernwin
"""
mostly stolen from https://github.com/idapython/ examples/ex_actions.py
"""
class IconExample(ida_kernwin.action_handler_t):
def __init__(self, passed):
ida_kernwin.action_handler_t.__init__(self)
self.passed = passed
def activate(self, ctx):
print(self.passed)
print(dir(ctx))
print(" cur_ea %08X" % ctx.cur_ea)
print(" cur_value: %08X" % ctx.cur_value)
print(" cur_extracted_ea %08X" % ctx.cur_extracted_ea)
return 1
def update(self, ctx):
if ctx.widget_type == ida_kernwin.BWN_DISASM:
return ida_kernwin.AST_ENABLE_FOR_WIDGET
else:
return ida_kernwin.AST_DISABLE_FOR_WIDGET
icon_data = open("cat.png", "rb").read()
act_icon = ida_kernwin.load_custom_icon(data=icon_data, format="png")
hooks = None
act_name = "example:IconExample"
if ida_kernwin.register_action(ida_kernwin.action_desc_t(
act_name, # Name. Acts as an ID. Must be unique.
"Print Function Addresses", # Label. That's what users see.
IconExample("Icon Example"), # Handler. Called when activated, and for updating
"Ctrl+F12", # Shortcut (optional)
"Prints Function Data", # Tooltip (optional)
act_icon)): # Icon ID (optional)
if ida_kernwin.attach_action_to_toolbar("AnalysisToolBar", act_name):
print("Attached to toolbar.")
else:
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()
else:
print("Action found; unregistering.")
if ida_kernwin.unregister_action(act_name):
print("Unregistered.")
else:
print("Failed to unregister action.")
if hooks is not None:
hooks.unhook()
hooks = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment