ida
# IDA ↔ DSH deep integration
[中文说明](README.zh-CN.md)
Give an AI agent real, scriptable control of IDA Pro 9.x: headless analysis through
`idalib`, or a live session through a bridge plugin inside the GUI. The same
analysis core and the same 36 tools work through either path.
## Layout
```
dsh_ida/
api.py analysis core — IDAPython only, runs inside an IDA kernel
worker.py headless kernel in a child process (imports idapro; owns the IDB)
client.py transports: worker subprocess or TCP to the GUI bridge
server.py MCP server, newline-delimited JSON-RPC over stdio, zero deps
cli.py dsh-ida probe|call|selftest|install-plugin
plugin/
dsh_ida_bridge.py IDA GUI plugin — TCP bridge, executes on IDA's main thread
cordis.patch.yml registers the MCP server in a DSH profile
tests/mcp_probe.py scripted MCP client; full tool-surface verification
```
The kernel lives in a child process so a crash, a bad loader or a long analysis
never takes the MCP server down. Calls are sequential (idalib is single-threaded);
`ida_open` accepts `timeout_s` for large databases such as `libUE4.so`.
## Install
Prerequisites: IDA Pro 9.0+ (must have been licensed once), Python 3.9+, and
`idapro` installed from your IDA directory:
```powershell
pip install "C:\Program Files\IDA\idalib\python\idapro-*.whl"
python "C:\Program Files\IDA\idalib\python\py-activate-idalib.py" -d "C:\Program Files\IDA"
pip install -e .
python -m dsh_ida.cli install-plugin # copies the bridge into IDA's user plugins dir
```
Then add this checkout to your DSH profile's `package.json`:
```json
"dependencies": { "@local/ida-mcp": "link:C:/Users/x/Desktop/IDA-agent" },
"dsh": { "profile": { "bundles": [ "...", "@local/ida-mcp" ] } }
```
and run `pnpm install` in the profile. Restart DSH to load the new tools. The MCP
server name is `ida`, so tools appear as `ida_status`, `ida_decompile`, etc.
## Two ways in
**Headless (default).** No GUI needed. The server picks this automatically when
no bridge is listening:
```
ida_open(path, analyze=true, timeout_s=900) → ida_status → ida_functions →
ida_decompile / ida_string_refs / ida_search_bytes / ida_xrefs_to ...
```
**Live GUI.** Load `dsh_ida_bridge.py` as an IDA plugin (Alt-F7 or place it in
the user plugins dir). It listens on `127.0.0.1:13371`; the MCP server prefers it
when present, so the agent and the human look at the same database. `ida_gui_state`
reads the cursor position and `ida_gui_jump` / `ida_gui_mark` move the view and
highlight findings for the analyst. `open`/`close` stay headless-only — in GUI
mode you open the database in IDA itself.
Set `DSH_IDA_BACKEND=idalib` or `gui` to force one, `DSH_IDA_GUI_PORT` to change
the port, and `DSH_IDA_TIMEOUT` for the default per-call timeout.
## Tools (36)
| Group | Tools |
|---|---|
| Database | `ida_status`, `ida_open`, `ida_close`, `ida_save` |
| Navigate | `ida_segments`, `ida_functions`, `ida_function`, `ida_disasm`, `ida_decompile`, `ida_read_bytes` |
| Cross-refs | `ida_xrefs_to`, `ida_xrefs_from`, `ida_call_graph` |
| Find things | `ida_strings`, `ida_string_refs`, `ida_names`, `ida_imports`, `ida_entries`, `ida_search_bytes`, `ida_search_text`, `ida_search_immediate` |
| Cheat workflow | `ida_sig`, `ida_sig_verify`, `ida_lua_bindings`, `ida_import_sdk` |
| Types | `ida_structs`, `ida_struct`, `ida_enums` |
| Write | `ida_rename`, `ida_comment`, `ida_set_type`, `ida_patch_bytes` |
| GUI | `ida_gui_state`, `ida_gui_jump`, `ida_gui_mark` |
| Escape hatch | `ida_exec` — arbitrary IDAPython with captured stdout |
`ida_string_refs` is the offset-hunting workhorse: give it a string fragment and
it returns the addresses and functions that reference it.
## Cheat workflow
The four tools that turn analysis into shippable offsets:
**`ida_sig`** builds the shortest unique AOB signature for a function. It walks
the instructions and wildcards exactly the operands that move when the game is
rebuilt — call/jump targets, RIP-relative globals, absolute immediates, true
imm64 — while keeping opcodes, stack sizes and struct offsets (`[rsi+0xC8]`
stays literal, because a field offset is what you want to pin). It never reads
past `end_ea`, so alignment padding and the next function's prologue are not
part of the pattern, and it grows the pattern until it matches once.
**`ida_sig_verify`** runs a saved signature against the open database. That is
the update loop: dump sigs from the old build, open the new `libUE4.so`, verify,
and every offset that broke is reported with its hit count before it ships.
**`ida_lua_bindings`** recovers `luaL_Reg` tables — `{name, lua_CFunction}`
arrays terminated by `{NULL, NULL}`. Games built on Lua inside UE4 (BGMI, PUBG
Mobile) register their whole scripting surface this way, so this maps a name
from a Lua dump straight onto the native implementation address.
**`ida_import_sdk`** parses a Dumper-7 (or any) C++ header into the local type
library. Dumper-7 writes real offsets as `char pad_XXXX[0x10]` members, so the
structs land byte-exact and field names appear in the decompiler as soon as a
pointer is retyped.
## Verification
```
python tests/mcp_probe.py # protocol: 5 checks
python tests/mcp_probe.py <binary> # full surface: 35 checks
python tests/gui_probe.py # live GUI bridge: 14 checks
python tests/cheat_probe.py # sig + lua + sdk: 12 checks
python -m dsh_ida.cli selftest <binary> # open + analyse + decompile
```
Headless, on IDA Pro 9.5.261026 with `repak.exe` (9,138 functions, Hex-Rays
available): **35 passed, 0 failed** — decompilation, masked AOB search, immediate
search, string xrefs, writes, save, and clean errors for bad addresses and for
GUI-only tools.
`tests/cheat_probe.py` runs against `tests/fixtures/lua_reg_sample.exe`, a real
PE built from the `.c` beside it with two genuine `luaL_Reg` tables:
**12 passed, 0 failed** — both tables recovered with all 8 names and their
addresses, a 24-byte signature that is unique and stable across runs, and a
Dumper-7 header imported with `UObject` at 0x30 and `AActor.RootComponent` at
0x38.
Rebuild survival was checked separately: the fixture was recompiled with an
extra function inserted ahead of `l_teleport` so every address shifted. The
26-byte signature taken from the first build matched exactly once in the second,
at the new address.
Live GUI, with `ida.exe` open on a 9,956-function binary: **14 passed, 0 failed** —
`gui_state` reports `IDA View-A` / `BWN_DISASM`, `gui_jump` moves the cursor,
`gui_mark` colours the line, and `open`/`close` are refused with a clear message
instead of touching the open database.
`gui_state`'s widget fields depend on IDA having keyboard focus; from a
background shell they can come back empty while `screen_ea` stays correct.
## Host notes (this machine)
* IDA 9.5 needed `HKCU\Software\Hex-Rays\IDA\EULA 95` as **REG_DWORD 1** before
`idalib` would run batch analysis; `REG_SZ` values are ignored. That acceptance
is now set on this host.
* The GUI was dying on startup with *"Errors while processing idagui.cfg"* then a
fatal *"MENUS_LAYOUT directive ... missing or wrong format"*. This install was an
in-place upgrade from 9.3, so `cfg\` had no `idagui.cfg` at all — IDA cannot
synthesise one on first run and quits. Restoring the 9.3 file as
`cfg\idagui.cfg` (kept as `idagui.cfg.ida93.bak`) makes 9.5 start cleanly with no
dialog; the old layout is accepted as-is. If the GUI ever stops starting again,
that file is the first thing to check.
* The GUI only loads Python plugins once `idapyswitch` has a target: it points at
`Python314\python314.dll` here. Without that, `.py` plugins are skipped silently.
`plugin/dsh_ida_bridge.py` logs every step to `%TEMP%\dsh_ida_bridge.log`
(override with `DSH_IDA_LOG`) — check it first if the bridge is not listening.
* The plugin is copied, not linked: re-run `python -m dsh_ida.cli install-plugin`
after editing it, and restart IDA.
* IDA 9.5 API differences handled here: `open_database` returns **0** on success;
structs/enums are enumerated through numbered `tinfo_t` types rather than
`ida_typeinf.get_struc_qty`; `bin_search` takes a compiled pattern vector with
4 arguments; `find_imm` returns `(ea, operand)`; `parse_binpat_str` returns an
empty string on success, so the vector size is checked instead; there is no
`get_widget_type_name` (the `BWN_*` constants are mapped back manually) and
`set_item_color` lives in `ida_nalt`, not `ida_bytes`.
MIT licensed. No IDA binaries, licence material or credentials are included.
TDQS
Scored across 36 tools
Most tools have a clear resource+action identity: read_bytes vs patch_bytes vs disasm, xrefs_to vs xrefs_from, structs vs struct, GUI vs headless operations are all distinguishable. A few boundaries blur: ida_strings vs ida_search_text both do substring string lookup, ida_names vs ida_functions both enumerate symbols by name filter, and ida_sig_verify vs ida_search_bytes both test byte patterns, so an agent could pick the wrong one without reading closely.
A uniform ida_ prefix makes the toolset easy to scan, and most names are verb_noun or clear single nouns. The convention is mixed, though: verbs (ida_open, ida_close, ida_save, ida_rename), verb_noun (ida_read_bytes, ida_set_type, ida_search_bytes), and bare plurals (ida_segments, ida_strings, ida_names, ida_structs, ida_enums) coexist, and ida_sig vs ida_sig_verify breaks the pattern of the rest.
Reverse engineering is a genuinely broad domain, and most of the 36 tools map to distinct IDA capabilities, but 36 is on the heavy side and a few could be consolidated (strings/search_text, names/functions, sig_verify/search_bytes). The three GUI-only tools and the headless-only open/close split also add surface that many agents will never use in a given session.
The surface covers the full workflow: open/close/save/status, memory map, function listing and detail, disassembly, decompilation, xrefs both ways, strings, imports, entries, structs, enums, multiple search modes, renaming, typing, commenting and patching. Gap areas (creating/deleting structs and enums, undefining functions, instruction-level edits) are explicitly covered by the ida_exec escape hatch and ida_set_type/ida_import_sdk.