Skip to content

Instantly share code, notes, and snippets.

@hasherezade
Created September 29, 2025 22:53
Show Gist options
  • Save hasherezade/3a492e48244ad8420d0afe8dcc2b8295 to your computer and use it in GitHub Desktop.
Save hasherezade/3a492e48244ad8420d0afe8dcc2b8295 to your computer and use it in GitHub Desktop.
IDA script - disasm current function
# Walk current function and print its disassembly
import ida_funcs
import ida_kernwin
import idautils
import ida_lines
import idc
def print_func_disasm(ea=None):
"""
Walks from the beginning to the end of the function containing `ea`
(or the cursor if None) and prints disassembly lines for code items.
"""
if ea is None:
ea = ida_kernwin.get_screen_ea()
f = ida_funcs.get_func(ea)
if not f:
print(f"[!] No function found at 0x{ea:X}")
return
name = ida_funcs.get_func_name(f.start_ea)
print(f"[+] Function: {name} @ 0x{f.start_ea:X} .. 0x{f.end_ea:X}")
# Iterate over defined items between start and end; print only code
for head in idautils.Heads(f.start_ea, f.end_ea):
if idc.is_code(idc.get_full_flags(head)):
# Prefer ida_lines.generate_disasm_line (then strip IDA color tags);
# fall back to idc.GetDisasm if needed.
line = ida_lines.generate_disasm_line(head, 0) or idc.GetDisasm(head)
line = ida_lines.tag_remove(line)
print(f"{head:08X}: {line}")
if __name__ == "__main__":
print_func_disasm()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment