Created
May 16, 2024 13:32
-
-
Save plowsec/1366a06366594b0e7ac57707d091b850 to your computer and use it in GitHub Desktop.
Simple IDA script to add a right-click handler in hexrays and get the EA of the current decompiled function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ida_kernwin | |
import ida_hexrays | |
class MyRightClickHandler(ida_kernwin.action_handler_t): | |
def __init__(self): | |
ida_kernwin.action_handler_t.__init__(self) | |
def activate(self, ctx): | |
# Get the current decompiled function | |
vu = ida_hexrays.get_widget_vdui(ctx.widget) | |
if vu: | |
ea = vu.cfunc.entry_ea | |
print("EA of the currently decompiled function: %x" % ea) | |
return 1 | |
def update(self, ctx): | |
return ida_kernwin.AST_ENABLE_ALWAYS | |
# Define the action | |
ACTION_NAME = "my:right_click_handler222" | |
ACTION_LABEL = "Get EA of Decompiled Function" | |
ACTION_SHORTCUT = "" | |
action_desc = ida_kernwin.action_desc_t( | |
ACTION_NAME, | |
ACTION_LABEL, | |
MyRightClickHandler(), | |
ACTION_SHORTCUT, | |
"Get the EA of the currently decompiled function", | |
-1 | |
) | |
print(action_desc) | |
# Register the action | |
res = ida_kernwin.register_action(action_desc) | |
print("Register action", res) | |
class my_hooks_t(ida_kernwin.UI_Hooks): | |
def populating_widget_popup(self, widget, popup): | |
if ida_kernwin.get_widget_type(widget) == ida_kernwin.BWN_PSEUDOCODE: | |
ida_kernwin.attach_action_to_popup(widget, popup, ACTION_NAME) | |
res = ida_kernwin.attach_action_to_popup( widget,popup,ACTION_NAME) | |
print("Attach popup", res) | |
my_hooks = my_hooks_t() | |
my_hooks.hook() | |
# Attach the action to the Hex-Rays decompiler view | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment