# fast-decomp fast-decomp is a static decompiler for x86-64 programs, written in Rust. It turns every function of a PE or ELF executable into C-like pseudocode, fast enough for whole games (the 137,813 functions of the Godot editor in 23 seconds on 6 cores), so that an AI agent or a person can read, search and annotate the program. **Status:** experimental. Input: x86-64 code from MSVC, gcc, clang and mingw. Whole-program decompile time on a logarithmic axis, fast-decomp against Ghidra 12.2. Lua: 0.18 s against 36 s. SQLite (ELF): 0.41 s against 94 s. SQLite (PE): 0.47 s against 4.2 min. OpenTTD: 6.4 s against 27 min. Godot editor: 28 s; Ghidra produced no text after 6 h 28 min. On the same stripped binaries it is 201 to 543 times faster than Ghidra 12.2's headless import, analysis and decompile-all ([Compared with Ghidra](#compared-with-ghidra)). ## What it produces `sqlite3_str_append` of SQLite 3.54.1 (public domain): ```c SQLITE_API void sqlite3_str_append(sqlite3_str *p, const char *z, int N){ assert( z!=0 || N==0 ); assert( p->zText!=0 || p->nChar==0 || p->accError ); assert( N>=0 ); assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 ); if( p->nChar+N >= p->nAlloc ){ enlargeAndAppend(p,z,N); }else if( N ){ assert( p->zText ); p->nChar += N; memcpy(&p->zText[p->nChar-N], z, N); } } ``` fast-decomp on the stripped `gcc -O2` build (no symbols; the comment header is cut): ```c struct s_36fd0_0 { /* likely: the fields this function accesses */ uint8_t _pad_0x0[8]; uint64_t f0x8_64; /* pointer */ uint32_t f0x10_32; uint8_t _pad_0x14[4]; uint32_t f0x18_32; } __attribute__((packed)); _Static_assert(sizeof(struct s_36fd0_0) == 28, ""); // 0x36fd0 sub_36fd0 (36 bytes) // likely: the result (heuristic) uint64_t sub_36fd0(struct s_36fd0_0 *a1, void *a2, uint64_t a3) { uint64_t v1; uint32_t v2; v1 = a1->f0x18_32; v2 = a3 + v1; if (v2 >= a1->f0x10_32) { return sub_36f90(a1, a2, a3) /* likely */; } if ((uint32_t)a3 != 0) { a1->f0x18_32 = v2; return memcpy(v1 + a1->f0x8_64, a2, (int64_t)(int32_t)a3); } return v1; } ``` What is a guess says so (`likely`): here the result, which is wrong (the function is `void`). Three commands record what a reader worked out, in a project directory next to the binary: ```sh fast-decomp project init sqlite-gcc-O2-stripped fast-decomp annotate sqlite-gcc-O2-stripped types --decl "struct sqlite3_str { void *db; char *zText; uint32_t nAlloc; uint32_t mxAlloc; uint32_t nChar; uint8_t accError; uint8_t printfFlags; };" fast-decomp annotate sqlite-gcc-O2-stripped func 0x36fd0 --name sqlite3_str_append --sig "void sqlite3_str_append(struct sqlite3_str *p, const char *z, int32_t N)" ``` and the same command then prints: ```c struct sqlite3_str; /* the project's type (declared in types.h); members used here: zText, nAlloc, nChar */ // 0x36fd0 sqlite3_str_append (36 bytes) void sqlite3_str_append(struct sqlite3_str *p, const char *z, uint64_t N) { uint64_t v1; uint32_t v2; v1 = p->nChar; v2 = N + v1; if (v2 >= p->nAlloc) { sub_36f90(p, z, N) /* likely */; return; } if ((uint32_t)N != 0) { p->nChar = v2; memcpy(v1 + p->zText, z, (int64_t)(int32_t)N); return; } return; } ``` A declaration changes names and types, never what the text says the code computes (`N` stays 64 bits wide because the machine code adds all of `rdx`). A C++ method of the Godot 4.3 editor (official mingw build, 133 MB, no symbols), from `serve`: ```c // 0x142563820 Control__get_combined_minimum_size (334 bytes) // likely: the result (heuristic) uint64_t Control__get_combined_minimum_size(struct Control *this) { uint64_t v1; uint128_t v2, v3; uint64_t local_30; uint64_t local_28; uint64_t local_20; if (*(uint64_u *)sub_145694570(&g_14581fce0) == 0) { if (*(uint8_t *)sub_145694570(&g_145814ca0) == 0 && (this->f0x2d5_8 & 0x40) != 0) { sub_1423902c0(&local_28, this); local_20 = 0; sub_1447a5c70(&local_20, "This function in this node (%s) can only be accessed from either the main thread or a thread group. Use call_deferred() instead."); sub_14003cd00(&local_30, &local_20, &local_28); sub_1447ddb30("get_combined_minimum_size", "scene/gui/control.cpp", 1689, "Condition \"!is_readable_from_caller_thread()\" is true. Returning: (Size2())", &local_30, 0, 0); sub_140022a90(&local_30, local_30); sub_140022a90(&local_20, local_20); sub_140022a90(&local_28, local_28); return 0; } } if (this->f0x580_8 == 0) { v1 = this->vt->vf90_get_minimum_size(this) /* likely */; this->f0x580_8 = 1; v2 = this->f0x5a4_64; v3 = v_fcmp_olt32x4(v2, (uint128_t)v1); this->f0x578_64 = (~v3 & v2) | ((uint128_t)v1 & v3); } return this->f0x578_64; } ``` The name comes from the program's own error-reporting strings, the class from its RTTI and vtables; `this`, the fields and the virtual call are typed from the whole program. ## Why use it - **It does not state what the code does not do.** Every fact is *proven* from the machine code (under [nine stated premises](docs/guide/validity.md)), *likely* (a heuristic, marked as such) or *asserted* by your project; likely and asserted facts change names and types only. What is not understood is printed as an unknown (`__unknown("unlifted fld", ...)`, `__indirect_jump(...)`, `__clobbered_rdx`), not dropped or guessed. - **It is checked.** The lifter is compared with the real CPU on 1,560 instruction codes; every function's IR and printed statement tree are run against each other in an interpreter; `fast-decomp selfcheck` does this for all 862,105 functions of the 29 corpus binaries without a failure ([STATUS.md](docs/STATUS.md#validity)). Random testing finds differences; it proves nothing ([what the checks can show](docs/guide/validity.md)). - **It is fast.** The whole pipeline, every function's text (`bench --jobs 6`, 6-core VM): | Binary | Functions | Time | Peak memory | | --- | ---: | ---: | ---: | | SQLite 3.54.1 (gcc -O2, ELF) | 1,646 | 0.37 s | 90 MB | | OpenTTD 14.1 (MSVC, PE) | 112,898 | 3.9 s | 411 MB | | node 24.22 (ELF, C++) | 104,144 | 14.8 s | 1,175 MB | | Godot 4.3 editor (mingw, PE, C++) | 137,813 | 22.6 s | 1,123 MB | The output is byte-identical for any number of threads. - **It is built for agents.** Names, prototypes, C types and comments go into a *project*, a directory of plain text next to the binary, with an `AGENTS.md` written for that binary. `fast-decomp serve` analyses the program once and answers JSON requests from memory (Godot: 23 s to start, then a median of 1.1 ms per function); `fast-decomp mcp` offers the same as Model Context Protocol tools. - **It recovers C++.** Classes, methods, `this` and virtual calls from RTTI and vtables; names from the program's own strings; statically linked MSVC runtime functions by their code; groups of functions that share a structure. ## Quick start Requirements: Rust 1.100 (selected by `rust-toolchain.toml`) and a C compiler for the example; tested on Linux x86-64. Clone `https://github.com/DimitriFourny/fast-decomp`, then: ```sh cargo build --release # about a minute on 6 cores export PATH=$PWD/target/release:$PATH cc -O2 -o demo crates/fd-cli/tests/project_fixture.c # a small program to try it on fast-decomp functions demo --name list # address, size, instructions, name, flags fast-decomp decompile demo --function list_sum # one function, C, to standard output fast-decomp export demo --out demo-decomp # every function in its own file, plus index files fast-decomp project init demo # demo.fdproj/, with an AGENTS.md for this binary fast-decomp annotate demo types --decl "struct node { int32_t key; int32_t flags; struct node *next; };" fast-decomp annotate demo func 0x12c0 --name sum_keys --sig "int32_t sum_keys(struct node *list)" fast-decomp decompile demo --function sum_keys # the names and the type, everywhere echo '{"id":1,"op":"callers","function":"sum_keys"}' | fast-decomp serve demo ``` `0x12c0` is the address `functions` printed for `list_sum` here; use the one your build prints. [Getting started](docs/guide/getting-started.md) explains each step; [working with an agent](docs/guide/agents.md) shows a session, an MCP configuration and a loop. ## Compared with Ghidra Ghidra 12.2 headless at its defaults (import, analysis, decompile-all) against `export`, same stripped files, 6 cores and 11 GB: | | Ghidra | fast-decomp | | --- | --- | --- | | SQLite (gcc -O2, ELF) | 94 s, 1.9 GB | 0.41 s, 97 MB | | OpenTTD 14.1 (MSVC) | 27 min, 5.4 GB | 6.4 s, 1.0 GB | | Godot 4.3 editor | no text after 6.5 h | 28 s, 2.5 GB | Measured on 2026-11-24 (fast-decomp at commit `6ce5878`); Ghidra ran under an 8 GB cap, with one decompiler thread on OpenTTD. Method, caveats and every other measure: [BENCHMARK.md](docs/BENCHMARK.md). - **Reviews.** Independent model reviewers were given the source, both texts under neutral labels and the machine code. On 60 C++ functions of three MSVC games they preferred fast-decomp's text in 47 and Ghidra's in 8, and found wrong statements in 6 of fast-decomp's texts and 39 of Ghidra's (mostly dropped call arguments); on 30 further functions, 16 against 10 ([details and limits](docs/MSVC-GROUND-TRUTH.md#8-independent-reviews-of-c-functions-and-what-changed-after-section-7)). On C built by gcc: [BENCHMARK.md](docs/BENCHMARK.md#independent-reviews). - **Where Ghidra is ahead.** Shorter text; `void` functions recognised more often; library functions named for more toolsets; exception handlers shown in their function; x87 and AVX-512; dozens of architectures; a GUI and a debugger. ## Limits - x86-64 only. x87, MMX and AVX-512 instructions are explicit `__unknown(...)` effects. - Pseudocode, not source that recompiles. - C++ exception handlers are separate functions, not `try`/`catch` in their parent. - The class behind a virtual call is known for about a quarter of the call sites of a large engine; classes without virtual methods are only grouped by the structure they share. - Library code is named only for the runtime builds there are signatures for (four MSVC toolset versions); `fast-decomp libsig build` makes more from any program that has a PDB. - Heavily optimised code keeps `goto`s. - Heuristics are marked `likely` and can be wrong; on C++ built with MSVC, reviewers still found wrong statements in about one text in ten, mostly about call arguments. ## Documentation [docs/README.md](docs/README.md) is the index: the guide ([getting started](docs/guide/getting-started.md), [reading the output](docs/guide/reading-output.md), [projects](docs/guide/projects.md), [agents](docs/guide/agents.md), [validity](docs/guide/validity.md), [troubleshooting](docs/guide/troubleshooting.md)), the reference ([commands](docs/reference/CLI.md), [session protocol](docs/reference/SERVE.md), [project format](docs/reference/PROJECT.md)), and for contributors the [architecture](docs/ARCHITECTURE.md), [the test corpus](docs/CONTRIBUTING.md), [status](docs/STATUS.md) and the internals of each stage. fast-decomp continues [open-decomp](https://github.com/DimitriFourny/open-decomp) (TypeScript), which still has what this one lacks: AArch64 Mach-O, a Python-like dialect, Objective-C and Swift metadata. ## License [MIT](LICENSE). Dependencies and the library data derived from system headers and runtimes keep their own terms: [third-party notices](docs/THIRD-PARTY-NOTICES.md).