/ida-scripts:ida-scriptsfrom ida-scripts
Provides ida_scripts, a Python library for IDA Pro 9.x, enabling concise reverse engineering and debugging calls instead of raw IDAPython. Covers function/pseudocode analysis, memory/struct reads, bulk renames/comments, database migration, and a debugger with breakpoint handlers, registers, and call stacks.
Ships in ida-scripts. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
ida_scripts is a Python library over IDAPython for IDA 9.x. It turns the daily moves of reverse engineering into short calls (print(func('update').outline()), show(f.callers), StrucT.find('Player').instance_at(addr).to_dict(), Breakpoint.add(..., handler=...)), and it already steps around the traps of IDA 9.4, where much of the older API is deprecated or gone. Reach for it first, and drop to raw IDAPython only for what it does not cover.
Read references/api.md once before the first call. It is one page, and it is the whole library. Sessions that skipped it wrote by hand, again and again, what one name there already did.
The library is the repository this skill ships in. ${CLAUDE_SKILL_DIR} is the folder this file is in (when you see that placeholder unfilled, put the folder's path in its place), and the repository is two folders above it: that folder holds the ida_scripts package. It is called REPO below.
Nothing here keeps state in the conversation. The open database, its unsaved edits, your variables, the debugged process, its breakpoints and their handlers all live inside one IDA process. So choose the host by how long that process has to live.
| Host | The process lives | Use it for |
|---|---|---|
The IDA MCP's execute_python | From open_database until close_database | Interactive work, and debugging step by step |
| A script run with IDA's Python (idalib) | For one run of the script | Batch jobs, a debugging run that goes the same way every time, and anything that should be repeatable |
IDA's GUI, File > Script file on REPO/load.py | As long as IDA is open | When the user works in IDA themself |
Run this once after open_database:
import os, sys
repo = os.path.dirname(os.path.dirname(os.path.realpath(r'${CLAUDE_SKILL_DIR}'))) # through a link first, then up
assert os.path.isdir(os.path.join(repo, 'ida_scripts')), f'{repo} is not the ida_scripts repository'
if repo not in sys.path:
sys.path.insert(0, repo)
from ida_scripts import *
jsonable({'repo': repo, 'database': Database.current(), 'ignore': sorted(Func.ignore)})
The first lines only find the repository. repo in the result is a plain path, and after another open_database two lines with that path written out do the same: import sys; sys.path.insert(0, '/that/path'), then from ida_scripts import *.
From then on every execute_python call on that database runs in the same namespace, on IDA's main thread. This is what makes stateful work possible, so use it:
f = func('update'), player = ...) and reuse them in later calls. Imports, variables, dbg, breakpoints and handlers all stay until close_database.close_database costs the namespace, and a session that closes after each step spends its calls on setting up again.Func.ignore are saved with it and are there the next time. A dict in the namespace is gone at close_database.show(f.callers) prints a line for each object, print(f.outline()) and show_code(f) print text that is already cut to size. The value of the last expression comes back too, and it has to be JSON. Library objects are not, so wrap them in jsonable(...), which takes any nesting of objects, lists and dicts, when you want data rather than a listing.timeout), is cut off where it stands. The namespace survives, with whatever the call had assigned before that point.db (an ida-domain database) and its reference tool are still there and mix freely with the library. Do not reuse the name db.close_database saves the database and ends the process, and a program being debugged dies with it. Opening the database again gives an empty namespace, so run the lines above again. That is also the sure way to pick up an edit to the library itself. exec(open(os.path.join(repo, 'load.py')).read()) reloads it in place where the worker allows it (it did in an idalib worker on Windows and failed in an idat worker on macOS), and leaves a new dbg with no handlers.instance_id), and data moves between them as JSON, through your reply or a file.import sys
sys.path.insert(0, REPO)
from ida_scripts import *
with Database.open('/path/to/target.i64') as db: # a binary works too, with analyze=True
...
db.save() # leaving the block closes without saving
Run it with the Python that has idalib: ~/.idapro/venv/bin/python3, on Windows %APPDATA%\Hex-Rays\IDA Pro\venv\Scripts\python.exe. Never pass -W error, which crashes idalib while it starts. A process hosts one database at a time, and a database that is open in IDA's GUI cannot be opened by a script at the same moment.
The database of a binary is <binary>.i64 beside it, written only by db.save(). A script that is killed leaves IDA's working files there instead (.id0, .id1, .id2, .nam, .til), and the next open carries on from them without a word, with whatever the dead run had changed. Delete them after a crash.
int, a '0x…' string, a symbol name, a Pointer or a Func. So func('update'), ptr('g_config') and Breakpoint.add('update') all work without a lookup first.Pointer wherever one is handed to you (ptr(...), dbg.pc, event.address, StringRef.address, an Xref's frm and to). .addr is the int, p + 8 is another Pointer, and a Pointer equals another Pointer or an int with the same address. Func.start, Call.site and Module.addr are plain ints. references/api.md gives the type of every property._main), and a lookup that finds no main tries _main, so either spelling works. A C++ name is mangled. A name the database lacks raises LookupError. When unsure of the spelling, search: Func.search(r'main$'), search_names(r'config') (Pointers, each with its .name). Func.find(name) and find_symbol(name) return None instead of raising._add is add there, and a character C does not allow becomes _, so a name made of such characters is a row of underscores. f.outline(), f.calls and the first line show_code prints have IDA's names.Pointer and struct reads come from the debugged process while there is one and from the database otherwise, so the same line works in both. Writes go to the process only.IDAError, with DecompileError and DebuggerError as its kinds. Do not wrap calls in try/except to be safe. What finds nothing says so plainly (Func.at and Func.find return None, call.target is None for an indirect call), and the one failure to expect in a loop over functions, a DecompileError, is handled by show_code and grep themselves.help(Func.search) in the session prints the full docstring. references/api.md lists every public name with its signature and one line, and is the place to look before writing a helper of your own.show, show_code and f.outline() cut what they print unless told otherwise. For the rest, cap it (max_lines, start, limit), leave the runtime's noise out (ignore=True, hide=), grep instead of dumping, and write anything large to a file (CFunc.save(path), json.dump) that you then search.f = func('update') # by name or address. Func.at(ea): the function containing ea
print(f.outline()) # the calls it makes, in order, each with its comment, then the strings it uses
show_code(f, max_lines=60) # its pseudocode under its name in IDA. show_code(f, g, h) prints several
print(f.pseudocode(start=60, max_lines=60, shorten=40)) # the next 60 lines, long identifiers cut
print(f.decompile().grep(r'hp|health', context=1)) # like grep -n over the pseudocode
print(grep(r'\+ 568\) = ', Func.search(r'^Player::'))) # the same over many functions: who writes that field?
show(f.callers, f.callees) # a line for each: address, name, comment
show(f.decompile().calls) # each call with its arguments, as the pseudocode has them
show(f.calls) # each call instruction: 'direct', 'tail' or 'indirect'. c.target is the Func, c.site the address
show(f.xrefs_to) # each use of f: 'call', 'jump' (a tail call) or 'offset' (its address is taken)
f.name, f.prototype, f.comment # read them, or assign to change them
Func.search(r'^Player::', limit=50) # regex over every name. search_comments(r'…') is the same over comments
show(strings(r'(?i)password')) # s.funcs are the functions that use the string. f.strings: the strings of one function
p = ptr('g_count')
p.name, p.comment, p.segment, p.rva # Database.current().image_base is what rva counts from
p.u32(), ptr('g_name').ptr().string(), ptr('g_table').array('i', 4)
show(p.xrefs_to()) # Xref: frm, to, kind ('call', 'read', 'write', …), func
print(f.disasm()) # every instruction of f. [i.text for i in ptr(0x401000).disasm(8)] for a few
show(ptr(0x401060).disasm(1, before=10)) # a call and the ten instructions that lead up to it, where the pseudocode lost the arguments
f.is_thunk, f.thunk_target # whether f only jumps to another function, and to which
IDA 9.4 prints argument names inside calls, as in compute(a1: argc). That is the decompiler's hint style, not part of the code.
A runtime's helpers drown every list: a null check, a lazy initialiser, a reference count. Say once which callees are noise, and they are gone from f.calls, f.callees, f.outline() and f.decompile().calls:
Func.ignore.update([r'^rt_check', r'_init_once$']) # regular expressions over callee names, kept in the database
show_code(f, ignore=True) # also leaves out the statements that only call one of them
show_code(f, ignore=True, hide=r'guard_\w+ = 1;') # and the lines a pattern of your own matches
ignore and hide take a statement out together with what it would leave empty, such as the if around a null check, and keep it where the rest would read differently without it. A last line says how many lines went.
Structs are declared from C text and then read at any address:
StrucT.parse('struct Vec2 { float x; float y; }; struct Player { int id; const char *title; struct Vec2 pos; struct Player *next; };')
player = StrucT.find('Player').instance_at('g_player')
player['id'], player.to_dict() # one value, or all of them, nested structs included
ptr(player['title']).string() # a pointer member is an address: follow it yourself
after = StrucT.find('Player').instance_at(player['next'])
StrucT.find('Player').add_member_auto('int hp', 0x40) # takes its room out of a gap, the rest stays in place
Rename, comment and type in bulk. Each of these refreshes the decompiler once at the end, where f.name = … in a loop refreshes every time:
rename_all({0x401000: 'parse_header', 'sub_401200': 'read_chunk'})
comment_all({'parse_header': 'validates the magic, then reads the chunk table'})
annotate_all({0x401400: ('free_chunk', 'the caller owns the buffer')}) # {address: (name, comment)}
apply_prototypes({'parse_header': 'int __fastcall parse_header(Header *h, int size)'})
Each returns how many entries it changed. Two quiet outcomes are worth a check afterwards. rename_all uses a numbered variant (name_0) when a name is taken, which Func.find(name) or find_symbol(name) shows. apply_prototypes skips a prototype IDA refuses, and the count is short then.
Knowledge that comes from outside the binary goes in the same way, once: a symbol list, or the signatures another tool wrote out. As comments it is in f.comment, in f.outline() beside every call, and in reach of search_comments, in every later session. A table rebuilt in the namespace at each open is none of that.
Edits stay in memory until the database is saved: save_database through the MCP, db.save() in a script. Database.current().save('/path/snapshot.i64') writes a copy and keeps working on the original, a cheap checkpoint before a large change, since closing through the MCP saves whatever is there.
Work moves between copies of a binary, and between builds of a program, as JSON:
data = export_annotations() # names, comments, prototypes and types that people or scripts added
import_annotations(data) # in another copy of the same binary
prints = export_fingerprints() # {fingerprint: name}, in the build that has the names
rename_all(match_functions(prints)) # in the other build: only functions whose code matches exactly one
A fingerprint is a hash of the function's mnemonics, in order. It ignores operands, so two functions that differ only in a constant, a global or a call target share one, as every small getter of the same shape does. Both steps leave out what is not unique: export_fingerprints drops a fingerprint that several functions of its build have, and match_functions drops one that several functions of the other build have. So a match is strong for a function of some size and weak for a tiny one, where the callers and callees that already matched are the evidence to check. f.fingerprint on both sides tells why a function was left out. When you name something on evidence other than a unique match, say so in your report.
There is one debugger, dbg, and it lives in the same process as everything else. Through the MCP a session therefore spans as many calls as you like: start the process in one call, look around in the next. Read references/debugging.md before the first session. The shape of it:
dbg.start(r'C:\games\target.exe') # suspended at the process start
seen = []
Breakpoint.add('update') # no handler: the process stops here
Breakpoint.add(0x4de0, module='Engine.dll', # Engine.dll may load later
handler=lambda event: seen.append(dbg.regs('RCX', 'RDX'))) # returns None: log and run on
event = dbg.resume(timeout=120) # runs until something stops it
jsonable({'event': event, 'pc': dbg.pc, 'stack': dbg.stack(8), 'seen': len(seen)})
Five things carry most of the weight:
dbg.resume, dbg.wait, dbg.run_to. Each returns the Event that suspended the process. Always give a timeout, shorter than the execute_python call's own: without one the call waits as long as the process runs. When nothing stopped the process in that time, the call raises a DebuggerError you can catch and the process keeps running, which beats a call cut off in the middle of its wait. dbg.wait(timeout=…) in a later call picks it up again, and dbg.suspend() stops it.handler(event) with the process suspended. Returning something falsy lets the process run on, which is how to trace thousands of hits into a list without a round trip for each. Returning something truthy stops there. An exception in a handler stops too, and is kept in dbg.handler_error.dbg.resume, dbg.wait or dbg.run_to is waiting, so wait with those and not with time.sleep.dbg.state instead of assuming it ('none', 'running', 'suspended') at the start of a call that depends on it. The process may have stopped or exited since the last call, and registers, dbg.pc and dbg.stack() need it suspended.dbg.stop() kills the process, dbg.detach() lets it live, and close_database kills whatever is still attached. IDA moves the database to where the process is loaded and leaves it there afterwards, and the breakpoints you added stay in it too. close_database saves all of that. So before the first start, write a copy with Database.current().save(path) and tell the user where it is. references/debugging.md says how to put the database back afterwards, and what that does not undo.All of this has run for real on Windows (IDA 9.4, the win32 debugger, x64), in scripts and as sessions spread over many MCP calls. macOS refuses to let IDA debug without elevated permissions: dbg.start then raises with IDA's message, which is to be reported, not worked around.
Raw IDAPython runs in the same namespace (import ida_bytes), and the library's objects hand you what it needs: f.start, ptr.addr, StrucT.tif, Breakpoint.bpt(). Two cautions for IDA 9.4. The func_t and segment_t API is deprecated (ida_funcs.get_func, ida_segment.getseg, ida_hexrays.decompile_func, even idautils.Functions), and ida_struct and ida_enum are gone. ida_scripts.compat (from ida_scripts import compat) has spellings that work across 9.x (compat.func_start(ea), compat.func_chunks(start), compat.segment_name(ea), compat.decompile(start)). And never guess an IDAPython name: look it up in the stubs of the installation (python/ida_*.py in IDA's folder) or with the MCP's reference tool.
When you needed something twice that the library lacks, say so in your report. The library grows from exactly such findings.
references/api.md Every public class, method and function with its signature and a one-line description. Search it before guessing a name.references/debugging.md A debugging session from start to end: waiting and timeouts, tracing with handlers, modules and address translation, calls into the process, events, and what the Windows debugger was seen to do.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub zeruic/ida_scripts --plugin ida-scriptsOther plugins' skills for the same job