How to use AI for reverse engineering with Ghidra, IDA, radare2 and Frida
A practical workflow for putting an AI agent to work on binaries: triage, decompiling with Ghidra or IDA through MCP, radare2 from the shell, Frida for runtime, and how to keep the model honest.
· 5 min read
An AI model can make reverse engineering much faster. It can read a thousand lines of decompiler output in seconds, name functions, spot a hand-rolled base64 table or a CRC loop, and write the Frida hook you were about to write. It also gets things wrong with total confidence, and the mainstream assistants refuse a fair share of ordinary reversing work. This guide covers a workflow that keeps the speed and catches the mistakes, with the tools most reversers already use.
The short version: give the model real tools, not pasted snippets. A model that can run strings, query a decompiler and attach Frida checks its own guesses against the binary. A model you paste functions into can only guess.
What AI is good at in reverse engineering
- First-pass triage. Format, architecture, packer, imports, interesting strings, and a list of the functions worth reading first.
- Reading decompiler output. Renaming variables and functions, recovering structs from field offsets, recognizing library code (crypto constants, compression, protobuf, standard parsers).
- Writing glue. Ghidra scripts, r2pipe scripts, Frida hooks, unpackers, and small emulators for one function.
- Explaining protocols and file formats once you've found the parser.
Where it fails
- It trusts the decompiler. Decompiled C is a hypothesis. Wrong calling conventions, missed indirect calls and bad type propagation all produce confident nonsense.
- It invents names. A function that "looks like" license validation gets called
check_licenseand then everything downstream is read through that lens. - It loses track in big binaries. Even with a long context, pasting a whole decompiled binary in is slow and expensive. Let it query instead.
The fix for all three is the same: make the model cite addresses and confirm claims against assembly or runtime behaviour, and keep a notes file of what is confirmed and what is guessed.
Step 1: triage from the shell
Before any decompiler, have the agent run the cheap tools and write down what it finds. On Linux or macOS:
file ./sample
sha256sum ./sample # shasum -a 256 on macOS
strings -n 8 ./sample | head -200
readelf -h -d ./sample # ELF; use otool -hl on Mach-O
rabin2 -I -i -zz ./sample # radare2: info, imports, strings
Work on a copy, record the hash, and note the architecture, entry point, imports and whether it looks packed (high entropy, few imports, a tiny .text). A good prompt at this stage:
Triage ./sample. Record format, architecture, hash, notable imports and strings in notes.md, say whether it looks packed and why, and list the five functions worth decompiling first, with addresses.
Step 2: radare2 for quick answers
radare2 is the fastest way for an agent to answer narrow questions, because every command prints text:
r2 -A ./sample
[0x00401000]> afl # list functions
[0x00401000]> s main; pdf # disassemble main
[0x00401000]> pdc # rough pseudo-C of the current function
[0x00401000]> axt @ sym.imp.strcpy # who calls strcpy
[0x00401000]> iz # strings in data sections
For anything repeated, have the model write an r2pipe script rather than driving the prompt by hand. It is easier to check, and you can run it again.
Step 3: Ghidra, headless or through MCP
Ghidra's decompiler is still the best free one, and it runs without the GUI. To dump every function's pseudo-C to a file an agent can grep, save this as decompile_all.py:
# Run: analyzeHeadless /tmp/ghidra-proj sample -import ./sample \
# -postScript decompile_all.py /tmp/sample.c
from ghidra.app.decompiler import DecompInterface
from ghidra.util.task import ConsoleTaskMonitor
out_path = getScriptArgs()[0]
ifc = DecompInterface()
ifc.openProgram(currentProgram)
with open(out_path, "w") as out:
for f in currentProgram.getFunctionManager().getFunctions(True):
res = ifc.decompileFunction(f, 60, ConsoleTaskMonitor())
if res.decompileCompleted():
out.write("// %s @ %s\n" % (f.getName(), f.getEntryPoint()))
out.write(res.getDecompiledFunction().getC() + "\n")
Pass -scriptPath with its folder if it isn't in one of Ghidra's script directories. The agent can then search /tmp/sample.c for constants and calls, and read only the functions that matter.
For interactive work, an MCP server lets the model query a live Ghidra project: list functions, decompile one, follow cross-references and rename things as it goes. GhidraMCP is the widely used open-source one: a Ghidra plugin plus a small bridge any MCP client can start. Renames made through it land in your project, so your own Ghidra session sees the model's work.
Step 4: IDA Pro through MCP
If you work in IDA Pro, ida-pro-mcp exposes the database to an MCP client: decompile, disassemble, cross-references, renames, comments and types. Hex-Rays now publishes an official MCP server as well. ida-pro-mcp needs IDA Pro rather than IDA Free, and the official server needs a recent IDA, so check each README's requirements before you start.
The workflow is the same as with Ghidra: let the model navigate, but make it leave comments with the evidence for each rename, so you can review its reasoning in the database later.
Step 5: Frida for what static analysis can't settle
When the question is "what does this actually do at runtime", stop reading and hook it. frida-trace is the quickest start:
frida-trace -f ./sample -i "open*" -i "connect" # spawn and trace libc calls
frida-trace -U -f com.example.app -i "SSL_*" # an Android app over USB
For anything specific, a short script. In Frida 17 and later, global exports are found with Module.getGlobalExportByName:
// hook.js — frida -f ./sample -l hook.js
Interceptor.attach(Module.getGlobalExportByName('open'), {
onEnter(args) {
console.log('open', args[0].readUtf8String());
},
});
Models are good at writing these. Ask for the hook together with what you expect it to print, so a wrong guess about a function's arguments shows up straight away.
Keeping the model honest
Put these rules in your project instructions (CLAUDE.md, AGENTS.md or CAVEIRA.md, whichever your agent reads):
- Cite an address for every claim about the binary.
- Mark each finding confirmed (seen in assembly or at runtime) or inferred (from decompiled code or names).
- Never rename a function without a comment saying why.
- Re-check decompiled types against the assembly before building on them.
- Keep
notes.mdcurrent: hashes, findings, open questions.
This costs a little speed and saves hours of chasing a confident wrong turn.
Which assistant to use
Any agent that can run shell commands and speaks MCP can do all of the above: Claude Code, Codex, OpenCode and caveira among them. The differences that matter for reversing:
- Refusals. Mainstream assistants follow their makers' usage policies. Plenty of reversing goes through, but cracking-adjacent work, malware internals, anti-cheat and DRM often get refused or lectured, even when the work is legitimate. Anthropic and OpenAI both run verification programs for security teams that unlock more (compared here).
- Context. Decompiled binaries are big. Models with long context windows, and a workflow that queries instead of pasting, matter more than benchmark scores.
- Local or hosted. If the binary can't leave your machine, run a local model and accept a smaller one. This guide covers the trade-off.
caveira is built for this work: it ships with the rea MCP server for native binaries, JavaScript and Electron apps, .NET assemblies and websites; a reverse-engineering skill that drives Ghidra headless and radare2 when they are installed; and an optional Docker box with radare2, gdb with GEF, pwntools and binutils (Ghidra can be added to the box's image). It speaks MCP, so GhidraMCP or an IDA server you already use can be added, or copied in from Claude Code or Cursor. Its models are abliterated, so it doesn't refuse reversing work. It is not a replacement for knowing the tools: everything in this guide applies whatever agent you use.