ida_scripts
This is a collection of IDA Python scripts, which hope to make IDAPython much more user-friendly and enjoyable :D.
It works on IDA 9.x (tested on 9.4), with or without a debugger: inside IDA, in a headless script through idalib, or driven by an AI agent through an IDA MCP server.
Features
This is just an overview, please check the documentations below for the full set of features.
memory
Pointer (shorthand ptr), from an address or a symbol name
- RW
bytes, int, float, pointer, string, wide string, array
- Reads the debugged process when there is one, the database otherwise
- Name, comment, segment, containing function and module
- Cross references to and from, as
Xref
- Hex dump
- Arithmetics ( + - == < ), hashable
Insn and disasm(start, end)
func
Func (shorthand func)
- Find by name, address, or regex over all names
- Rename, comment, C prototype
- Callers, callees, and every call it makes (direct, tail or indirect)
- An outline: its calls in order, each with the callee's comment, and the strings it uses
- A list of callee names to ignore, kept in the database, for the runtime helpers that drown every list
- Strings and data it refers to, instructions, chunks
- Thunks and where they jump, also the single jumps IDA does not mark
- Fingerprint, to find the same function in another build
- Decompile to yield
CFunc
CFunc
- Get pseudocode, cut to a length or to a window, with long identifiers shortened, with or without the local declarations
- Leave out the statements that only call an ignored function, or the lines a pattern matches, together with the
if they would leave empty
- Every call with its arguments
grep inside it, save it to a file
grep over the pseudocode of many functions, show_code to print several functions
- Get body represented as a networkx.DiGraph (really just a tree)
CItem
- Property accessors
- Customised convenient accessors such as
- Getting the struct / member being accessed
- Getting the number
- DFS search for node with lambda condition
- Subtree query for more complex searches
struc
- Types (the type defs, not instances)
StrucT
- Find by name
- Declare from C text or a header file
- Get
id, name, members, size, declaration
- Subscript access for member
MemberT
- Get
StrucI instance from Pointer
- Create struct
- Add & delete member
- Add member, automatically managing gaps
MemberT
- Get
id, name, type, offset, size
- Instance (instances with memory addresses)
StrucI
- Get
members
- Subscript access for member value, read and write
- Apply C prototypes to many functions
debugger
dbg
- Start, attach, resume, run to, suspend, stop
- Every call waits until the process is suspended again and returns the
Event
- Registers, program counter, stack pointer, call stack
- Call a function in the process
- Events recorded as they happen, handlers per kind of event
Breakpoint
- By address, by name, or by offset into a module that has not loaded yet
- A handler per breakpoint, which can log and let the process run on
module
Module
- Enumerate all modules
- Find module by name, or by an address inside it
- Translate addresses between the process and the database
misc
- Search names, comments and strings by regex
show prints any list of the library's objects, a line for each
- Name and comment many addresses at once
- Export every annotation of a database, import it into another copy
session
Database
- Open, save a snapshot, close, also as a context manager
- All classes are pretty-printed when evaluated, and turn into JSON with
to_dict(), or with jsonable() for any nesting of them!
Usage
In IDA Pro, select File > Script File and choose the load.py script. Run it again to reload the scripts after changing them.
Anywhere else that has IDA's Python (idalib, or the Python of an IDA MCP server), put this folder on sys.path and import everything:
from ida_scripts import *
with Database.open('target.i64'):
f = func('main')
print(f.outline())
print(f.pseudocode(max_lines=40))
show(f.callers, f.decompile().calls)
for found in Func.search(r'^Player::'):
print(found, found.strings)
While debugging:
dbg.start('target.exe') # suspended at the process start
Breakpoint.add('update')
event = dbg.resume() # suspended at update, its thread selected
print(dbg.regs('RCX', 'RDX'), dbg.stack())
state = StrucT.find('GameState').instance_at(dbg.reg('RCX'))
print(state['frame'], state.to_dict())