# Getting started This page builds fast-decomp, compiles a small program to try it on, and goes through the commands you use first. Every command here was run as written (`scripts/check_docs.py` runs them again); the outputs are cut where `...` stands. ## Build You need Rust 1.100 (the repository's `rust-toolchain.toml` pins it; with [rustup](https://rustup.rs) the right toolchain is installed on the first build) and, for the example program, a C compiler. fast-decomp has been developed and tested on Linux x86-64; it reads PE and ELF files whatever system produced them. ```sh cargo build --release export PATH=$PWD/target/release:$PATH fast-decomp --help ``` The release build takes about a minute on 6 cores and gives one executable, `target/release/fast-decomp`, with no runtime dependency beyond the C library. Nothing is installed elsewhere and no configuration file is read. ## A program to try it on The repository has the source of a small program its tests decompile: a linked list, a structure with floats and an enum, a global, a callback. ```sh cc -O2 -o demo crates/fd-cli/tests/project_fixture.c fast-decomp info demo ``` `info` describes the file without decompiling it: format, ABI, sections, imports, symbols, where function starts come from (`hints`: symbols, unwind records), and at the end what function discovery found: ``` format Elf, X86_64, ABI SysV ... functions 20 (1 noreturn, 5 import thunks), 53 blocks, 220 instructions jump tables 0 (0 with a heuristic bound); unresolved indirect jumps 0 ``` ## Finding functions ```sh fast-decomp functions demo --name list ``` ``` address size instructions name flags c_name demangled source source_file 0x1280 54 14 list_count list_count list_count symbol - 0x12c0 29 10 list_sum list_sum list_sum symbol - 0x12f0 32 10 list_weight list_weight list_weight symbol - ``` Without `--name` every function is listed. The columns are tab-separated: the entry address, the bytes and instructions of its code, the name and where it comes from (`source`: a symbol, an export, an import, the PDB or DWARF debug information, or, for stripped programs, `string` and `table` names derived from the program's own strings, `vtable` names from the C++ class model, `-` for none), the C identifier the text uses (`c_name`) and the demangled name. The addresses on your machine may differ from these: they depend on the compiler. A function is selected by any of its names (`--function list_sum`) or by any address inside it (`--address 0x12c0`). A stripped program's functions are called `sub_
`. ## Decompiling one function ```sh fast-decomp decompile demo --function list_sum ``` ```c /* list_sum @ 0x12c0 * 29 bytes, 5 blocks, 10 instructions; found by Symbol (High confidence); state ok * structure: 2 ifs, 0 switches, 1 loops, 0 gotos, 0 labels * interface: * signature: i32@rax list_sum(i64 a0@rdi) [parameters proven; result likely] ... */ struct s_12c0_0 { /* likely: the fields this function accesses */ uint32_t f0x0_32; uint8_t _pad_0x4[4]; uint64_t f0x8_64; /* struct s_12c0_0 * */ } __attribute__((packed)); _Static_assert(sizeof(struct s_12c0_0) == 16, ""); // 0x12c0 list_sum (29 bytes) // likely: the result (heuristic) int32_t list_sum(struct s_12c0_0 *a1) { uint32_t v1, v2; if (a1 == NULL) { return 0; } v1 = 0; do { v2 = v1 + a1->f0x0_32; a1 = (struct s_12c0_0 *)a1->f0x8_64; v1 = v2; } while (a1 != NULL); return v2; } ``` The source was `for (; p; p = p->next) s += p->key;` over `struct node { int key; int flags; struct node *next; ... }`. The comment header says how the function was found, its state (`ok`), how it was structured, its signature with the evidence for each part and the registers it reads, writes and preserves. Then the structure the function's accesses imply (the field at offset 0 is 32 bits, the one at 8 holds a pointer to the same structure), then the C. [Reading the output](reading-output.md) explains every element of this dialect. `decompile` analyses the whole program first when it has at most 25,000 functions (well under a second for most programs), so the text is exactly what an export writes. On larger programs it analyses only the function and its callees (2.7 s for a method of the Godot editor, most of it finding the program's functions), and the header says so; `--exact` forces the whole-program analysis, and a session ([agents](agents.md)) keeps it in memory. `--json` prints the same text with its facts as JSON (the signature with each parameter's location and status, callers, callees, strings, globals); `--addresses` ends every statement with the address of its machine instruction. `disasm` and `ir` show the same function as machine code and as the intermediate representation. ## Exporting everything ```sh fast-decomp export demo --out demo-decomp ``` ``` fast-decomp: 20 functions in ... s (... functions/s), 22270 bytes written, peak RSS ... MB; 0 internal errors, 0 verify failures, 0 size cut-offs, 0 with likely facts withdrawn ``` The directory holds one file per function, `functions//
_.c` (a bucket is 64 KiB of address space, so that no directory gets too large), and: | File | Content | | --- | --- | | `index.tsv` | every function: address, size, name, state, its file, C name, demangled and short names, where the name comes from, the source file its error messages name | | `diagnostics.tsv` | everything a stage could not do, by function | | `fd_prelude.h` | the types and helpers the text uses (`uint64_u`, `VCALL`, `__unknown`, ...) | | `types.h` | the structures recovered over the whole program, merged | | `strings.tsv`, `globals.tsv`, `globals.h`, `xrefs.tsv` | the program's strings, globals and cross references, with the functions using each | | `vtables.tsv`, `classes.tsv`, `methods.tsv` | C++ virtual tables, classes and their virtual methods | Everything is plain text meant for `grep`, `rg` and an agent's file tools. The files are byte-identical for any number of threads (`--jobs`). `--single-file` writes one `.c` file instead; `--name TEXT` exports only the functions whose name contains `TEXT`. ## Recording what you learn What you learn about a binary goes into its **project**: `demo.fdproj/` next to it, plain text that every command applies. Its `AGENTS.md` explains the format with examples taken from the binary. ```sh fast-decomp project init demo 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 ``` ```c // 0x12c0 sum_keys (29 bytes) int32_t sum_keys(struct node *list) { uint32_t v1, v2; if (list == NULL) { return 0; } v1 = 0; do { v2 = v1 + list->key; list = (struct node *)list->next; ``` The name, the parameter and the structure now show in this function, in its callers (`player_score` calls `sum_keys(...)`), in `functions`, `xrefs` and in an export. [Working with a project](projects.md) covers the records, the type dialect and how a structure reaches the code. ## Next - [Reading the output](reading-output.md): what each construct of the text means. - [Working with an agent](agents.md): the session (`serve`), MCP, and an agent loop. - [Validity](validity.md): how much to trust a function, and why. - [Command reference](../reference/CLI.md): every command and option.