Decompiling With Ghidra
ASecurityUse when reading a compiled binary as C with Ghidra - decompiling a function, checking how a game or program branches, or answering "what does this function do" from a binary. Built for large binaries that ship debug info (DWARF), such as Factorio's Linux headless builds, where Ghidra's default analysis runs for hours. Also use when Ghidra, analyzeHeadless, PyGhidra, Jython, REA or a Ghidra skill or MCP comes up, when a Ghidra run is slow or its C is full of undefined/param_N/in_RDI, or when ...
- 5 stars
- 0 votes
- 0 copies
- 1 view
- Added November 20, 2026
Works with
Security analysis
100/100Pro scans all 2 files and shows the line behind each finding
npx -y skills add wormeyman/wormeyman-skills --skill decompiling-with-ghidra --agent claude-codeAre you the author of Decompiling With Ghidra?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/wormeyman-decompiling-with-ghidra)---
name: decompiling-with-ghidra
description: Use when reading a compiled binary as C with Ghidra - decompiling a function, checking how a game or program branches, or answering "what does this function do" from a binary. Built for large binaries that ship debug info (DWARF), such as Factorio's Linux headless builds, where Ghidra's default analysis runs for hours. Also use when Ghidra, analyzeHeadless, PyGhidra, Jython, REA or a Ghidra skill or MCP comes up, when a Ghidra run is slow or its C is full of undefined/param_N/in_RDI, or when an objdump address does not match Ghidra's. Covers the 4-minute debug-info-only import, the PIE address shift, argument types from C++ mangled names, compiler clones, calls that never return, the GUI steps, and when objdump is the better tool.
---
# Decompiling with Ghidra
Turn a function in a big binary into readable C in minutes, not hours. The numbers
come from Factorio's 257 MB Linux headless binary (free to download, ships DWARF)
and from small test programs built with GCC 16 and clang, on Linux desktops with 8
and 16 threads, 2026-11-12 and 2026-11-13.
## First: is Ghidra the right tool?
- **For constants and data, use `objdump` + the debug info instead.** `objdump -d -l -C
--start-address --stop-address` plus `llvm-symbolizer --inlining` found every noise
constant in about 2 minutes. Ghidra adds nothing there.
- **For control flow - "which branch wins", "what order are checks done" - use Ghidra.**
Reading branches out of raw assembly is slow and error-prone. The C shows them directly.
## What it covers
Nothing here is specific to Factorio. What matters is the binary. Check it with
`file <bin>` (`with debug_info, not stripped`) or `readelf -S <bin> | grep debug_info`.
- A 64-bit Linux ELF with DWARF (C or C++) is the case this was built for.
- A stripped binary gives no names or types: pass addresses from objdump.
- Windows PE and macOS Mach-O are not covered.
Before importing anything other than a 64-bit Linux ELF with DWARF, read the binary
table in `references/setup.md`.
## The one setting that matters
Ghidra's default analysis runs about 30 analyzers over every function. On the Factorio
binary that ran **past 2 hours without finishing** (16 GB heap). The script turns off
everything except **DWARF**, **Demangler GNU** and **Apply Data Archives** (which gives
`strlen`, `printf` and other C library calls their arguments). That finished in **4-6
minutes** on an 8-core i7-6700 and in about 2.5 on a 16-thread i5-14400F, with about
3 GB of heap. Skipping analysis entirely (`-noanalysis`) is fast but gives useless C: no
names, no types, 9,522 lines for a 2.7 KB function.
## Command line (preferred): `scripts/ghidra_decompile.py`
A PyGhidra script run by uv. It needs Ghidra 12.x (Arch package `ghidra`, which ships
PyGhidra), Java 25 or newer, and `llvm-dwarfdump` (package `llvm`) for one check. The
script's header pins the pyghidra wheel from `/opt/ghidra`. Edit it if Ghidra lives
elsewhere.
If Ghidra, Java 25 or `llvm-dwarfdump` is missing, the wrong Java starts, or uv fails
building JPype, read `references/setup.md`. Installing Ghidra needs sudo: use the
`getting-command-output` skill.
```bash
S=~/.claude/skills/decompiling-with-ghidra/scripts/ghidra_decompile.py
$S import <binary> <project_dir> # once per binary version, ~2.5-6 min
$S find <project_dir> 'Surface::collide' # names -> file + Ghidra addresses
$S decompile <project_dir> 0x18eea40 'Surface::collideWithEntity' --out <dir>
```
- **Import into a new, empty folder**, one per binary, named after the version (for
example `~/ghidra-projects/factorio-2.1.23`). Keep it: it is about 1.1 GB, and every
later `find` or `decompile` opens it in about 15 s. Import refuses a folder that
already holds a project, and a file that is not ELF. If import fails, it removes the
folder it made.
- **One run per project at a time.** Ghidra locks the project, and an open Ghidra GUI
counts. A second run stops with "is locked". Wait for the first, then retry.
- `decompile` takes **file addresses** (what objdump and readelf print), names as
`find` prints them, or mangled names. It shifts addresses for you. Namespaces can be
left off when the short name is unique (`pick` for `(anonymous_namespace)::pick`).
Several targets in one call share one start-up.
- **Bad targets are skipped, not guessed.** An address in the middle of a function is
refused with the real start ("inside X, which starts at file 0x..."). So is an
address outside code (for example in `.rodata`), bad hex, an unknown name, and a name
that fits several functions (overloads, thunks), which lists them all. The rest of the
batch still runs, and the exit code is 1. Read the `SKIPPED` lines.
- **A function whose signature step fails is still decompiled**, with the header
`none (signature step failed: ...)`, and reads like a stripped function: `param_1..N`.
- **A large batch is cheap**: hundreds of functions take well under a minute. Reading
the C is the cost, not producing it.
- Each output is `<name>@<file address>.c`, so overloads do not overwrite each other.
- `find` lists functions in the binary only. Marks: `[clone .isra.0]`, `[thunk]`,
`[PLT stub for an import]` and `[arguments changed by clang]`. Each line ends with the
mangled name, which tells overloads apart. With no match it says so.
- `--save` keeps the disassembly and signature changes in the project, which helps
if someone will open it in the GUI later. Without it the project is not changed.
- Run it from a scratch directory, and send `--out` there too.
### The header of each `.c` file
Read it before the C. It holds both addresses, the prototype, how many callees had
their signatures set, and where the signature came from:
- `debug info` - DWARF had a real prototype. GCC builds and clang test builds did.
- `mangled name (debug info was empty)` - DWARF came through as `void f(void)`, as on
Factorio, so the script used the C++ name. `` `this` assumed `` means it added a
`this` pointer, which is wrong for a static method. Mangled names have no return
type, so a struct returned by value shows up as an extra first pointer argument (the
hidden return slot), and the names after it are shifted. On Factorio,
`Surface::collide` starts `(Surface *this, Surface *param_1, ...)`: that `this` is
really the return slot, and `param_1` is the real `this`.
- `inferred (compiler clone)`, `inferred (thunk)` or `inferred (clang changed the
arguments: DW_CC_nocall)` - the declared arguments are wrong for this code, so the
decompiler worked them out. These read as `param_1..N`. Map them to the source by hand.
`arguments in registers (__regparm3)` is the 32-bit case (`references/traps.md`,
item 4).
- `none (...)` - no debug info and no C++ name, as in a stripped binary or plain C.
## What the script fixes
The script already handles the PIE address shift, functions left as raw bytes,
`void f(void)` signatures, compiler clones, and PLT and no-return calls. Read
`references/traps.md` when the C is full of `in_RDI`, `in_RSI`, `extraout_RAX` or
unexplained `param_N`, when the C runs on past a `throw`, when an objdump address lands
in the wrong function, or before changing the script.
## Reading the C
- **Calibrate first.** Before trusting C for an open question, decompile one function
whose behaviour is already known (from notes, a test, or the source) and check that
the C says the same. On 2026-11-12, `generateEntities` showed exactly the compare the
notes had read by hand, which is what made `Surface::collide` worth reading.
- The C is evidence about the code, not about which path the program takes. Confirm
with a measurement where it matters.
- **`printf`-style calls can show too few arguments.** GCC sometimes keeps a value in
a register across a call to its own function, and the decompiler then drops it. The
format string is in the C, so count its `%` codes against the arguments.
- **`catch` blocks do not show.** A `try`/`catch` reads as the `try` part only.
- **Do not read float width (f32 or f64) off the C.** When the width matters, as in
porting numeric code bit for bit, read the instructions with objdump: `mulss` and
`addss` work in f32, `mulsd` and `addsd` in f64, and `cvtss2sd` or `cvtsd2ss` marks a
widening or a narrowing.
- **Do not read float order or NaN branches off the C either.** Float addition is not
associative, and Ghidra drops the grouping. It can also rewrite a compare so that
NaN seems to take the other branch. For bit-exact work the C is a map, and objdump is
the evidence. Worked examples of each float trap are in `references/traps.md`.
- Harmless noise: `DuplicateNameException: codecvt already exists` while importing,
a `DWARFImportSummary` ERROR list of unrecoverable location expressions, and
`Unresolved local var` comments.
- **"Control flow encountered bad instruction data" is not noise.** It meant a fake
function start or a call that never returns but was not marked. Check the address,
and check which call comes just before the cut.
- Offsets like `this + 0x24` are struct fields Ghidra has no layout for. The debug info
often lacks class layouts too. Name what you learn in your notes, not by guessing types.
## Finding callers
DWARF-only analysis does not disassemble function bodies, so Ghidra has no list of
who calls what. Use objdump with the mangled name from `find`:
```bash
objdump --disassemble --no-show-raw-insn <bin> | grep 'call.*<_ZN7Surface21collideWithTileCommon'
```
Each hit is a call address. On the Factorio binary this took 6 s and found 4 callers.
## GUI
If a person will use the Ghidra GUI, read `references/gui.md` and walk them through it.
The GUI does not get the clone and no-return fixes by itself. The command line is
faster for the agent itself.
## Ruled out
Do not use REA, the skills.sh Ghidra skills, Jython, or Java GhidraScripts through
analyzeHeadless: each was tried on 2026-11-12 and was slower or failed. Read
`references/ruled-out.md` before suggesting any other Ghidra tool or MCP.
Files in this skill
- SKILL.md
- scripts/ghidra_decompile.py
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.