Skip to main content

ghidra-decomp

Bulk-decompile binaries into browsable source trees using Ghidra.

Takes a binary, runs Ghidra's decompiler on every function, and produces a directory of .c files and JSON indexes — ready for grep, code review, or AI-assisted analysis.

Why

Reverse engineering through Ghidra's GUI (or MCP) means looking at one function at a time. This tool dumps everything upfront so you can treat the binary like a normal codebase: grep for patterns, read call graphs, search strings — all without waiting for decompilation round-trips.

Install

Requires Ghidra 12.0+ and PyGhidra 3.0+.

make install

Or manually: pip install -e .

Set GHIDRA_INSTALL_DIR to your Ghidra installation, or pass --ghidra-path.

Usage

ghidra-decomp ./firmware.bin -o ./firmware_decomp
Flag Description Default
-o, --output Output directory <binary>_decomp/
--timeout Per-function decompilation timeout (seconds) 60
--combined Also emit all_functions.c off
--pcode Also emit <function>.pcode.json per function: SSA high-pcode ops, def-use, block CFG, varnode storage, and resolved call arguments off
--ghidra-path Path to Ghidra install $GHIDRA_INSTALL_DIR
--base-addr Rebase binary to this address before analysis none
--entry Mark address as entry point before analysis none
--language Force Ghidra language ID (e.g. ARM:LE:32:v7) auto
--compiler Force compiler spec ID. Requires --language. auto
--list-languages List all available language/compiler IDs, then exit
--workers Decompiler threads min(4, CPU count)
--resume Reuse hash-valid per-function artifacts from existing output off
--include / --exclude Function name regexes. Repeatable. all
--function Export function at this address. Repeatable.
--gdt Apply a Ghidra data type archive. Repeatable. none
--pdb PDB source: auto (fetch from symbol server), none, or local path detect+prompt
--gzf Also export program.gzf off
--semgrep-config Scan pseudocode with semgrep, write semgrep.sarif off
--verbose-analysis Attach console monitor to Ghidra auto-analysis off
--mermaid Render call graphs as Mermaid flowcharts in callgraphs/ off
--cpp-export Export single .c + .h via Ghidra's CppExporter off
--max-ram-percent JVM MaxRAMPercentage for heap sizing (1.0–100.0) 50.0
--print-jvm-flags Print JVM flag values at startup off
--callgraph-depth Neighborhood hops for per-function Mermaid (1–10) 1
--condense-threshold Collapse whole-graph Mermaid when edges exceed N none
--reachable FROM TO Check if FROM can reach TO in the call graph none
--no-polish Skip the readability post-processing pipeline; emit raw Ghidra output polish on
--aggressive Enable Ghidra's off-by-default Decompiler Parameter ID analyzer for better parameter/return types (slower) off
--max-payload-mb Raise Ghidra's per-function decompiler payload cap (MB) to rescue very large functions Ghidra default (~50MB)

Polish

By default, decompiled pseudocode is run through a post-processing pipeline that rewrites Ghidra's output into more readable C without changing semantics — while→for loops, x = x + 1→x += 1, if (c) { return 1; } return 0;→ return c;, struct-field and vtable synthesis on stripped binaries, and more. Pass --no-polish to get Ghidra's raw output instead. Each function's sidecar records whether it was polished.

See docs/polish.md for the full transform list and guarantees.

Output

firmware_decomp/
├── manifest.json
├── functions/
│   ├── 00010000_<digest>_main.c
│   ├── 00010000_<digest>_main.json
│   ├── 00010000_<digest>_main.pcode.json   # --pcode
│   └── ...
├── assembly/
│   ├── 00010000_<digest>_main.s
│   └── ...
├── xrefs.jsonl
├── all_functions.c     # --combined
├── program.gzf         # --gzf
├── semgrep.sarif       # --semgrep-config
├── types.json
├── functions.json
├── callgraph.json
├── callgraphs/          # --mermaid
│   ├── callgraph.md
│   ├── endpoints.json
│   ├── reachability.json  # --reachable
│   ├── paths.md           # --reachable --mermaid
│   └── <function>.md
├── export.c             # --cpp-export
├── export.h             # --cpp-export
├── strings.json
├── imports.json
├── exports.json
├── symbols.json
├── sections.json
└── metadata.json

See docs/output-format.md for the full artifact contract, sidecar structure, type records, and manifest semantics.

Callgraph Queries (no Ghidra needed)

Query a previous export's callgraph.json without starting Ghidra:

# Find root and leaf functions
ghidra-decomp-query endpoints ./firmware_decomp

# Check if main can reach encrypt_data
ghidra-decomp-query reachable ./firmware_decomp main encrypt_data

# Find all paths between two functions
ghidra-decomp-query paths ./firmware_decomp main encrypt_data --max-depth 50

Docker

docker compose run --rm ghidra-decomp ./firmware.bin -o /output/firmware_decomp

Workflow

  1. Dump the binary with ghidra-decomp
  2. Analyze the output like source code — grep, glob, read
  3. Re-run with --resume, or narrow with --include/--function
  4. Write back renames/annotations to Ghidra via MCP (separate tool, not yet built)

Docs

  • Output format — artifact contract, sidecars, types, manifest
  • Polish — the readability post-processing pipeline and its transforms
  • Raw binaries — language/compiler selection, rebasing, entry points
  • Development — testing, CI, fixture regeneration

License

MIT

Metadata

Release files for ghidra-decomp 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ghidra-decomp 1.1.0
File Size Uploaded Provenance Actions
ghidra_decomp-1.1.0.tar.gz 549.6 kB Without provenance Details for ghidra_decomp-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ghidra-decomp 1.1.0
File Interpreter ABI Platform Actions
ghidra_decomp-1.1.0-py3-none-any.whl Python 3 none any Details for ghidra_decomp-1.1.0-py3-none-any.whl

Total release size: 616.6 kB

Release files / ghidra_decomp-1.1.0.tar.gz

Download URL ghidra_decomp-1.1.0.tar.gz
Size 549.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3fab209e9b3247af8d53e90518479350f925b0c9db7ac5970a2ed443fe29255f
BLAKE2b-256 checksum
How to use checksums
75d1b27e9735d3e1c9b04f22f3c02fee75f3eae332bd0b1f7f17a6d970c0070b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / ghidra_decomp-1.1.0-py3-none-any.whl

Download URL ghidra_decomp-1.1.0-py3-none-any.whl
Size 67.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6fca4e0fce8d8f19238f0ef9cb9484c3b8177ee816c17b0f4469d65f6cfb01c
BLAKE2b-256 checksum
How to use checksums
ca0dd7ae66a0188552dd90482b3dedbda692b0bc11049aa413b941d74a0af40b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for ghidra-decomp 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page