# fast-decomp: the command-line tool `crates/fd-cli` builds the `fast-decomp` binary on top of `fd-pipeline` ([PIPELINE.md](../internals/PIPELINE.md)). Arguments are parsed by hand (no dependency). ```sh cargo build --release -p fd-cli # target/release/fast-decomp fast-decomp --help # the commands fast-decomp export --help # one command fast-decomp --version # the version (also -V) ``` ``` fast-decomp 0.1.0 ``` `--version` prints the version of the crate the binary was built from, nothing else (no commit hash, no build date). General form: `fast-decomp COMMAND FILE [OPTIONS]`; options may come before or after `FILE`, `--flag value` and `--flag=value` are both accepted. Addresses are hexadecimal with `0x` or decimal. Every command that discovers functions takes `--jobs N` (worker threads; default one per CPU), `--pdb PATH` (the PDB of a PE image; it must match the image's CodeView GUID and age, else exit code 2), `--no-debug` (ignore PDB and DWARF) and `--no-class-metadata` (ignore RTTI, `_ZTV` symbols and vtable headers: vtables, classes and their hierarchy come from the code alone, as for an MSVC `/GR-` build without symbols; CLASSES.md section 4). Without `--pdb` the PDB the image names is looked for next to it; one that does not match is reported on standard error and not used ([NAMES.md](../internals/NAMES.md)). `--libsig FILE[,FILE...]` adds signature files for library recognition and `--no-libsig` turns it off ([LIBID.md](../internals/LIBID.md): statically linked library functions named by their code, `likely`; the project's `libsig/`, the user's directory and the shipped files are used otherwise). `--compiler msvc|gnu` states the compiler family instead of what the image says ([IMAGE.md](../internals/IMAGE.md#compiler-family); `info` prints what was read): it decides how a result nobody reads is printed (INTERFACE.md section 5). Nothing is interactive. **The project** ([PROJECT.md](PROJECT.md)): every command that reads a binary (`functions`, `disasm`, `ir`, `decompile`, `export`, `strings`, `xrefs`, `classes`, `class`, `vtables`, `bench`, `selfcheck`) shows the project `FILE.fdproj/` when it exists: its names (source `user`), signatures, types, comments. `--project DIR` names another directory, `--no-project` ignores it, `--force` applies a project made for another binary (by address, unverified; otherwise refused, exit code 2). Selection by name (`--function`) accepts the project's names. **Exit codes**: 0 success; 1 the command ran and found problems (an internal error or a verification failure in `decompile`, `export`, `bench` or `selfcheck`, or an output it could not write); 2 bad usage or an input that cannot be processed. Errors go to standard error as `fast-decomp: : `, for example `unsupported file: ELF32 (ARM) (supported: PE32+ x86-64, ELF64 x86-64, Mach-O 64 arm64)` or `unsupported architecture: function discovery handles x86-64 only, the image is Aarch64`. Every run checks each function's region tree before printing it (PIPELINE.md, "The tree check"): a tree that fails is never printed; the function is an internal error whose header says why and prints structured without un-threading, or flat (every jump a `goto`). **Function selection** (`disasm`, `ir`, `decompile`, `xrefs`): `--function NAME` is a name in any of its forms, exactly (case-sensitive): raw (the symbol, export or debug name, the import name of an import thunk, `sub_`, a name the class model gives: `Window::vf12`, `Label::~Label`), demangled (`Rect::area() const`), short (`Rect::area`) or the C identifier (`Rect__area`, `Window__vf12`). When no function has the name, the error lists up to ten functions whose name, in any form, contains it; when several do (overloads by their short name, static functions of two files), it lists their addresses, demangled names and C names (use `--address` or a form that is unique, such as the C name). `--address VA` is the entry or any address inside the function. ## info Format, architecture, ABI, the compiler family and what says so, image base, entry points, sections, imports per library, exports, symbols, function hints by source, debug pointers (PDB, build id, debuglink, Mach-O UUID, DWARF), loader warnings; for x86-64 images also the discovery counters and the debug names read (`debug names pdb from …/sqlite-pe-O2.pdb: 890 functions (481 with parameters), 185 data`). ``` $ fast-decomp info bin/sqlite-gcc-O2 format Elf, X86_64, ABI SysV compiler gnu (an ELF file (gcc or clang)) image base 0x0 file size 1220648 bytes entry 0xa570 (Main) ... imports 68 from 1 libraries libc.so.6: 65 (no library recorded): 3 exports 0 symbols 1857 hints Symbol 1637, EhFrame 1633 build id 12931876ed5d567fbe715cf7e260292faa64f180 dwarf no functions 1646 (0 noreturn, 42 import thunks), 46340 blocks, 214508 instructions jump tables 48 (0 with a heuristic bound); unresolved indirect jumps 0 ... ``` Mach-O arm64 images are described; their functions are not discovered (AArch64 is not decompiled). ## functions `functions FILE [--name SUBSTR] [--source PATH] [--reporters] [--json]`: every function by address: address, size (bytes of code in its blocks), instructions, name (raw), flags (`noreturn`, `import-thunk`, `invalid-code`, `unknown-flow`, `unresolved-jump`, `dangling-exit`, `unproven-table`, `overlaps-other`), `c_name` (the identifier the C text uses), `demangled`, `source` (`symbol`, `export`, `import`, `pdb`, `dwarf`, `string` for a name from the function's reporter calls and `table` for one from a registration table ([NAMES.md](../internals/NAMES.md) sections 5 and 6, `likely`), `vtable` for a name the class model derives, [CLASSES.md](../internals/CLASSES.md); `-` without a name), `source_file` (the source file and lines its reporter calls name, `likely`: `scene/gui/control.cpp:1689-1702`; `-`). `--name` keeps functions whose name in any form (raw, demangled, short, identifier) contains `SUBSTR`, case-insensitive; `--source` those whose reporter calls name a file containing `PATH` (case-insensitive: "everything from this file"). `--reporters` prints instead the reporters found (callee, address, all its calls, the calls that pass the file, the functions they are in, the file, line and function positions, and per position its role and the counts behind it: paths, line numbers, strings, function names, distinct values), after the synthetic classes (`class_`) whose methods' qualified string names agree on a class name. JSON adds `c_name`, `demangled`, `short`, `source`, `source_file`. ``` $ fast-decomp functions big/godot-win64.exe --source scene/gui/control.cpp address size instructions name flags c_name demangled source source_file ... 0x142563820 334 79 Control::get_combined_minimum_size Control__get_combined_minimum_size Control::get_combined_minimum_size string scene/gui/control.cpp:1689 ... ``` ``` $ fast-decomp functions bin/sqlite-gcc-O2 --name sqlite3_open address size instructions name flags c_name demangled source source_file 0xb0170 12 3 sqlite3_open sqlite3_open sqlite3_open symbol - 0xb0180 5 1 sqlite3_open_v2 sqlite3_open_v2 sqlite3_open_v2 symbol - 0xb0190 355 100 sqlite3_open16 sqlite3_open16 sqlite3_open16 symbol - ``` ``` $ fast-decomp functions small/cpp-gcc-O2 --name rect:: address size instructions name flags c_name demangled source source_file 0x3a60 11 3 _ZNK4Rect4areaEv Rect__area Rect::area() const symbol - ... ``` ``` $ fast-decomp functions small/m-gcc-O2 --json --name abort [ { "address": "0x1030", "size": 6, "instructions": 1, "name": "abort", "c_name": "abort", "demangled": "abort", "short": "abort", "source": "import", "flags": [ "noreturn", "import-thunk" ] } ] ``` ## disasm `disasm FILE (--function NAME | --address VA)`: one paragraph per basic block with its address range, its instructions (bytes and Intel syntax, call targets named), how it ends and its successor edges. ``` $ fast-decomp disasm small/m-gcc-O2 --function classify ; classify @ 0x15e0 block 0x15e0 .. 0x15e5: 0x15e0 83ff32 cmp edi,32h 0x15e3 7f1b jg short 0000000000001600h end: conditional jump -> 0x1600 (taken) 0x15e5 (not-taken) ... ``` ## ir `ir FILE (--function NAME | --address VA) [--stage lifted|ssa|opt|analyzed] [--addresses]`: the IR of one function in `fd-ir`'s text form ([IR.md](../internals/IR.md) section 5): `lifted` (register form), `ssa` (after SSA construction), `opt` (default, after simplification), `analyzed` (after `fd_analysis::analyze`: the stack frame promoted, what the C text is printed from; instruction numbers have gaps, the function is not compacted). `--addresses` keeps the `; @0x…` provenance of every instruction. ``` $ fast-decomp ir small/m-gcc-O2 --function smod7 func @0x1840 isa=x86-64 form=ssa { b0: v0:64 = entryreg rdi ... v12:32 = sdiv v10, v11 ... return [rax=v16, rdx=v14, xmm0=v2, xmm1=v3, rbx=v4, rbp=v5, r12=v6, r13=v7, r14=v8, r15=v9, rsp=v18] } ``` ## decompile `decompile FILE (--function NAME | --address VA) [--exact | --local] [--json] [--verify] [--seeds N] [--addresses] [--no-unthread]`: one function to standard output, exactly the text `export` writes for it when the whole program is analysed first: with `--exact`, and by default when the image has at most 25,000 functions (under a second on SQLite). With `--local` (and by default on larger images) only the function and its callees are analysed: what the whole program decides (return and kind demand from the callers, the class flow, structures shared across functions, the project's anchors elsewhere, the virtual callers' lines) is missing, and the header says so (` * text: local (this function and its callees only): ...`); `--json` has `exact`. A session (`serve`, below) prints the exact text in milliseconds after analysing once. The text: a C comment header (how the function was found, its state, calls, tail calls, structure counters, the premises the stack analysis used, the signature with its evidence and the summary's register sets, strings, globals, class roles, diagnostics), the structures the function uses, then the function in C from `fd-emit` ([EMIT.md](../internals/EMIT.md)) with the analysis's facts: parameters, call arguments and results, types, `likely` marks ([reading the output](../guide/reading-output.md)). The types and helpers it uses are in `fd_prelude.h`, which `export` writes. `--addresses` ends every statement with `// 0x…`, the address of its machine instruction. ``` $ fast-decomp decompile small/m-gcc-O2 --function list_sum /* list_sum @ 0x14d0 * 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] * summary: reads {rdi}; writes {rax}; preserves {rcx, rdx, rsi, r8, r9, r10, r11, xmm0, ...} * body: C (types and helpers: fd_prelude.h) * structure group: struct s_14d0_0 (likely: the first parameter of 2 functions, structs.tsv) */ struct s_14d0_0 { /* likely: the fields this function accesses */ uint32_t f0x0_32; uint8_t _pad_0x4[4]; uint64_t f0x8_64; /* struct s_14d0_0 * */ } __attribute__((packed)); _Static_assert(sizeof(struct s_14d0_0) == 16, ""); // 0x14d0 list_sum (29 bytes) // likely: the result (heuristic) int32_t list_sum(struct s_14d0_0 *a1) { uint32_t v1, v2; if (a1 == NULL) { return 0; } v1 = 0; do { v2 = v1 + a1->f0x0_32; a1 = (struct s_14d0_0 *)a1->f0x8_64; v1 = v2; } while (a1 != NULL); return v2; } ``` Names in the C text are C identifiers, unique in the image ([NAMES.md](../internals/NAMES.md) section 2): `Rect__area` for `Rect::area() const`, `yy_reduce_isra_0` for `yy_reduce.isra.0`, a trailing `_` for names the emitter uses itself (`v1_`, `rdi_`); the header shows the demangled name, the raw one with its source and the C name, and the debug information's prototype when there is one. `--verify` runs every checker after every stage (see `selfcheck`); a failure is listed in the header's diagnostics, the state is `verify-failed` and the exit code 1. `--no-unthread` (also on `export`, `bench` and `selfcheck`) structures the IR without the rewrites that undo jump threading (OPT.md section 5), for comparisons. `--json` prints one JSON object instead (for agents: no C to parse): | Field | Content | | --- | --- | | `address`, `name`, `c_name`, `demangled` | the function's entry, its name as printed, its C identifier, its demangled form (`null` without one) | | `name_source` | `user` (the project), `symbol`, `export`, `import`, `pdb`, `dwarf`, `string`, `table`, `vtable`, or `null` (`sub_`) | | `replaces` | for a project's name: `{name, source}` of the name it replaces | | `state`, `size`, `instructions` | as in the header | | `signature` | `text` (the declaration line of the text), `source` (`project` when a `sig` gives it, else `analysis`), `params`: `[{name, location, status}]` (`location` a register or `stack+0x8`; `status` `asserted`, `proven` or `likely`), `result`: `{location, void, status}` or `null` | | `callees` | per call site `{site, kind, address, name}` (`kind` `call`, `import`, `indirect`), then `{kind: "tail", address, name}` per tail call | | `callers` | `{address, name, kind}` (`call` or `tail`), each caller once | | `strings` | `{address, text}` of the string literals the function uses | | `globals` | `{address, name, name_source, kinds, comment?}` (`name_source` `user`, `symbol` or `address` for `g_`; `kinds` as in `xrefs.tsv`) | | `classes` | the class model's roles: `{role: "slot", class, table, slot}` or `{role: "constructor" \| "destructor" \| "deletingdestructor", class}` | | `project` | `comment`, `line_comments` (`[{address, comment}]`), `notes` (what of the project could not apply: raw accesses, a short signature, two anchors, unprinted comments) | | `diagnostics` | `{severity, code, message, address}` | | `text` | the text `decompile` prints | ## serve, mcp `serve FILE [--project DIR] [--jobs N]`: a resident session ([SERVE.md](SERVE.md)). It analyses the whole program once, then reads one JSON request per line on standard input and writes one JSON response per line on standard output (`{"id":1,"op":"decompile","function":"main"}` → `{"id":1,"ok":true,"token":0,"result":{...}}`); progress and logs go to standard error. The operations are this page's commands with the same fields (`functions`, `decompile`, `disasm`, `xrefs`, `strings`, `globals`, `classes`, `class`, `vtables`, `annotate`, `project_init`, `project_check`, `project_status`, `info`) plus `callers`/`callees` to a depth, `common_refs`, `changes_since`, `batch` and `help`. Every `decompile` text is the full export's for the current project; annotations through the session, by one-shot `annotate` or by editing the project's files apply at the next request. It ends when standard input closes. `mcp FILE [--project DIR] [--jobs N]`: the same session as a Model Context Protocol server over standard input and output (tools only, both protocol eras). ## project init, check, status, compact `project init FILE [--dir DIR]`: creates `FILE.fdproj/` (or `DIR`): `project.toml` (format, the binary's file name, size, SHA-256 and quick hash, the tool version), an empty `annotations.jsonl`, `types.h` (a comment) and `AGENTS.md` (the format and the commands, with examples on this binary). Refuses a directory that holds a project. `project check FILE [--json] [--project DIR] [--force]`: every finding about the project against the binary, one per line, `file:line[:column]: level [code]: message` (codes in PROJECT.md section 10), then `DIR: N records on M subjects; E errors, W warnings, K notes`; computes the binary's SHA-256. Exit code 1 when there is an error. `--json`: ```json {"ok": true, "errors": 0, "warnings": 1, "notes": 0, "records": 2064, "subjects": 2064, "verified": true, "problems": [{"level": "warning", "file": "annotations.jsonl", "line": 1797, "column": 0, "code": "name-taken", "message": "`local_getline` is a name the decompiled text uses itself: printed as `x_local_getline_`"}]} ``` `project status FILE [--json]`: records by kind and property (`func.name 1928, func.sig 1766, …`), functions named by the project, by the image or its debug information, and unnamed; globals named by the project and the image's data symbols; the types (structures, unions, members, enums, typedefs); the errors. `--json`: `{records: {"func.name": n, …}, functions: {total, named_by_project, named_by_image, unnamed}, globals: {named_by_project, data_symbols}, types: {structs, unions, members, enums, typedefs}, errors}`. `project compact FILE [--force]`: rewrites `annotations.jsonl` with one line per subject (the current value of every property, stable order), without replaced and retracted records. Refuses while a line does not read (it would be lost), unless `--force`. ## annotate ``` annotate FILE func ADDR [--name NAME] [--sig PROTOTYPE] [--comment TEXT] annotate FILE global ADDR [--name NAME] [--type TYPE] [--comment TEXT] annotate FILE line ADDR --comment TEXT annotate FILE field STRUCT OFFSET --name NAME --type TYPE [--comment TEXT] annotate FILE param FUNC N [--name NAME] [--type TYPE] (N: 2 or a2) annotate FILE frame FUNC OFFSET --name NAME (OFFSET: -0x18 or local_18) annotate FILE types --decl "C declarations" annotate FILE --batch RECORDS.jsonl (- for standard input) [--delete] [--by WHO] [--note WHY] [--json] [--dry-run] [--project DIR] [--force] ``` Each record is validated against the binary before anything is written (PROJECT.md section 8); with `--delete` it retracts the properties given (all of the subject's without any). The valid records are appended to `annotations.jsonl` with the function's fingerprint and size; each input prints `ok annotations.jsonl:LINE RECORD`, `refused INPUT: [code] message` or `hint INPUT: …`, then `N written, M refused`. Exit code 1 when a record was refused. `types --decl` appends to `types.h` when the declarations read without new errors (`ok types.h:LINE added struct X, enum Y`). `--json`: ```json {"dry_run": false, "written": 1, "refused": 1, "results": [ {"input": "new.jsonl:1", "ok": true, "line": 57, "record": "{\"func\":\"0x14d0\",\"name\":\"list_sum\",…}", "problems": [], "hints": []}, {"input": "new.jsonl:2", "ok": false, "line": null, "problems": ["[name-taken] `printf` is already the name of the function at 0x1050 (printf); `printf_2` is free"], "hints": []}]} ``` Measured on Godot with a 50,000-record project: 1.5–1.6 s per call; on SQLite 58–69 ms (discovery of the image is most of it; the class model is not built). ## export `export FILE --out PATH [--single-file] [--name SUBSTR [--exact | --local]] [--verify] [--seeds N] [--addresses] [--no-unthread]`: every function (or those whose name contains `SUBSTR`, case-insensitive). A selection's texts follow `decompile`'s rule: the full export's (the whole program analysed, only the selection written) with `--exact` or on images of at most 25,000 functions, else local, said in each header. - Default: `PATH` is a directory receiving `functions//
_.c` (bucket = the address shifted right by 16, in hex: 64 KiB of address space per directory), `index.tsv` (`address size name state file c_name demangled short source source_file source_lines other_files`, by address: `name` raw, `file` from the C name; `source_file` the implementation file the function's reporter calls name most, `source_lines` its lines (`1689-1702`), `other_files` the other files with their lines, `path:12-30;path:7`, all `likely` and `-` when the calls name none), `diagnostics.tsv` (`function address severity code message`; discovery's diagnostics have function `-`), `fd_prelude.h` and `types.h` (the recovered structures of the image, merged; each function file also declares the views it uses, docs/internals/TYPES.md); when every function is exported (no `--name`), also the data index ([DATA.md](../internals/DATA.md)): `strings.tsv`, `globals.tsv`, `xrefs.tsv`, `vtables.tsv` and `globals.h`, and the class model ([CLASSES.md](../internals/CLASSES.md)): `classes.tsv` and `methods.tsv` (below); and `structs.tsv`, the groups of functions that share the structure of their first parameter (below; not written when there is no group). With a project, `types.h` starts with the project's types (byte-exact, PROJECT.md section 9), `index.tsv`'s `source` is `user` for the project's names, `globals.h` shows the project's types and comments of globals. Exporting into an earlier export replaces its `functions/` tree; a non-empty directory without `index.tsv` is refused. - `--single-file`: `PATH` is one `.c` file with every function in address order, starting with `#include "fd_prelude.h"`, `#include "globals.h"` (when every function is exported) and the structure declarations; `fd_prelude.h` and `globals.h` are written next to it. A summary line goes to standard error: ``` $ fast-decomp export bin/sqlite-gcc-O2 --out sqlite-export fast-decomp: 1646 functions in ... s (... functions/s), 11820883 bytes written, peak RSS ... MB; 0 internal errors, 0 verify failures, 0 size cut-offs, 1 with likely facts withdrawn ``` The files are byte-identical for any `--jobs`. ### Data files Tab-separated, one record per line, a header line first, ordered by address (`xrefs.tsv`: by function address, then target address). Addresses are `0x…`; functions are named by their C identifier (the name the text uses; `sub_` without one), a list of functions is `name,name,…` (at most 32, then `(+N)`); `-` is an empty field. Texts are C-escaped and quoted (`"…"`, `u"…"` for UTF-16); a field never holds a tab or a newline. | File | Columns | | --- | --- | | `strings.tsv` | `address`, `encoding` (`utf8`/`utf16`), `length` (bytes, without the terminator), `referenced` (`yes`: some function uses the address; `no`: plausible text found by scanning), `section` (`rodata`, `data`, `relro`), `text`, `functions` (those using the address) | | `globals.tsv` | `address`, `name` (the identifier of the data symbol, `vtable_`, else `g_`), `section` (`rodata`, `data`, `relro`, `bss`), `size` (of the symbol, 0 when unknown), `widths` (access sizes in bytes, `-` for address uses only), `access` (`read`, `write`, `addr`, `arg`, `stored`, `indexed`, joined by `\|`), `functions`, `demangled` (of a mangled symbol, `vtable for `, else `-`) | | `xrefs.tsv` | `function` (address), `name`, `address` (what it uses or calls), `kind` (as `access`, plus `call` and `tail` from discovery's call graph and from calls a fold made direct, `vcall` for a virtual call through a slot of a known class: the address is the class's vtable, the target `Control::vf35`, CLASSES.md section 15; a virtual call with a proven receiver is a `call` of its target), `widths`, `target` (the function, the quoted string, the vtable's class, the global's name, `name+0x…` inside an object, else `-`) | | `vtables.tsv` | `table` (address point), `class` (demangled: `Rect`, `Godot::Node`, `Widget`; else as written; `-` when unknown), `evidence` (`symbol`, `rtti`, `msvc`, `layout`, `stored`, comma-joined), `slot`, `function` (address; `-` for a pure-virtual import), `name` (the function's short demangled name, `Rect::area`), `installers` (functions storing the table into an object), `class_raw` (`4Rect`, `N5Godot4NodeE`, `.?AVWidget@@`), `c_name` (`vtable_Rect`), `class_id` (the class of `classes.tsv` the table belongs to; `-` for a table the class model leaves out: a construction vtable, a duplicate, the continuation of a table split by null slots) | | `classes.tsv` | one line per class, by id: `id`, `name` (demangled; `class_` without one), `name_source` (`rtti`, `symbol`: a `_ZTV` symbol, `address`), `hierarchy` (`rtti`: the RTTI lists the bases; `likely`: inferred; `unknown`), `bases` (`id@0xoffset`, `virtual id@?` for a virtual base at a run-time offset, `(likely:evidence)` after an inferred one: `store-order`, `structor-call`, `shape`, `subobject`), `tables` (`address@0xsubobject offset`), `slots` (of the primary table), `size` (bytes, `likely`; `-`), `constructors`, `destructors` (C names of the candidates, all `likely`), `abstract` (`yes`: a slot is pure or null), `raw` (the RTTI or `_ZTV` name), `c_name` (the class's identifier) | | `structs.tsv` | one line per function of a group of at least two functions whose first parameter is one recovered structure ([TYPES.md](../internals/TYPES.md) section 3b; all `likely`), by group, then address: `group` (`struct s__`: the group's name, a name `types.h` declares), `structure` (the merged structure of `types.h` the group's structures are part of; several groups can share one), `functions` (the group's size), `address`, `name` (the function's C name), `member_by` (`parameter`: the function's own first parameter has the structure; `callers`: it has none, and every object its callers pass there is of this group), `role` (`constructor-like`: the function only stores to the structure, to at least two fields, and returns it: a constructor, an `init` function, or a function returning the structure by value; else `-`). `grep -P '^struct s_1400e4cc0_0\t' structs.tsv` lists the functions that work on one type. A separate file because a group is no property of a function's text: `index.tsv` keeps one line per function with what its file holds. | | `methods.tsv` | one line per slot of every class table, by class, table, slot: `class_id`, `class`, `table` (address point), `offset` (subobject), `slot`, `function` (address; `-` for a pure-virtual import or a null slot), `name` (its C name), `owner` (class id of the most-base class with the same function in that slot; `-` for pure slots, thunks and unknown ones), `kind` (`introduced`, `override`, `inherited`, `pure`, `destructor`, `deleting-destructor`, `thunk-0x10` with the adjustment it adds to `this`, `unknown`), `status` (`rtti` or `likely`), `folded` (`yes`: one body in the slots of unrelated classes, owner ambiguous), `target` (a thunk's target, C name; `-`) | `globals.h` declares every global as the C text uses it: `extern [const] uint32_t name;` by access width, `uint8_t name[size]` (or `[]`) for several widths or indexed access, with its address and section in a comment; it includes `fd_prelude.h`. Function headers gain, when they apply: the reporter calls' facts (NAMES.md section 5: ` * source (likely, from 3 reporter calls): scene/gui/control.cpp:1689-1702, core/templates/vector.h:123`, ` * name from strings (likely, unique): "get_combined_minimum_size" in scene/gui/control.cpp:1689; class Control from its vtable slot`, ` * signature (string, likely): …`, ` * also contains code of (likely, inlined): …` / ` * contains code of (likely; no name: …): push_back (core/templates/vector.h:64, in 412 functions)`), registrations (` * registered (likely) as "print" in the table at 0x…`), a synthetic class's name from its methods' strings (` * class hint (strings, likely): class_3da8 is Engine (5 of 5 methods' strings)`), `strings:` and `globals:` (at most 16 each, with the address, the text or name, the kinds and widths), the class model's roles (at most 4: ` * class: Control (slot 35, overrides Node::vf35; also inherited by 313 classes)`, ` * class: thunk in slot 2 of the table of Multi for its subobject at +0x10: adds -0x10 to this, then Multi::a2()`, ` * constructor candidate of Label [likely: installs, after-alloc]`, ` * destructor of Label (deleting) [likely: installs, slot, frees]`, ` * class: one body in the slots of unrelated classes (identical code; owner ambiguous): A slot 3, B slot 7, …`), `vtable slots:` (`slot 2 of 0x5d10 Rect [symbol,rtti]`), and the premise `P5 N loads from read-only memory folded`. ## strings `strings FILE [--grep TEXT] [--jobs N]`: the rows of `strings.tsv` (with its header line); `--grep` keeps the strings whose text contains `TEXT`, ignoring ASCII case. Like `xrefs` and `vtables` it analyses every function (summary-only, no text) to build the index: about the time of a `bench` without the structuring and emission stages. ``` $ fast-decomp strings bin/sqlite-gcc-O2 --grep "unable to open" address encoding length referenced section text functions 0xe7bc2 utf8 27 yes rodata "unable to open database: %s" attachFunc 0xe8931 utf8 28 no rodata "unable to open database file" 0xf1728 utf8 36 yes rodata "unable to open shared library [%.*s]" sqlite3_load_extension ``` (`"unable to open database file"` is reached through a table of pointers in `.data.rel.ro`, not from code: `referenced no`.) ## xrefs `xrefs FILE (--address VA | --function NAME | --string TEXT | --class NAME) [--jobs N]`: rows `direction` (`from`: a function using the address; `to`: what the function uses), `function` (address), `name`, `address`, `kind`, `widths`, `target`, as in `xrefs.tsv`. - `--address VA`: every function using `VA` (for a sized object, any address inside it), and when `VA` is a function, its callers (`call`/`tail`). - `--function NAME`: its callees and everything it uses, then its callers. - `--string TEXT`: the functions using each string whose text contains `TEXT` (ignoring ASCII case). - `--function NAME` also lists the virtual call sites that can reach the function (a method): `from vcall - Control::vf35 (likely)` (CLASSES.md section 15). - `--class NAME`: every function using one of the class's vtables (constructors, destructors, vptr comparisons), then the callers of its constructor and destructor candidates. `NAME` as for `class`. A virtual method by the name the model gives it: `--function Window::vf12`. ## vtables `vtables FILE [--jobs N]`: the rows of `vtables.tsv`. ``` $ fast-decomp vtables small/cpp-gcc-O2 table class evidence slot function name installers class_raw c_name class_id 0x5d10 Rect symbol,rtti,stored 0 0x3aa0 Rect::~Rect main 4Rect vtable_Rect 0 ... ``` ## classes `classes FILE [--name SUBSTR] [--tree] [--jobs N]`: the C++ classes of the image, the rows of `classes.tsv` (with its header line); `--name` keeps the classes whose name (demangled, C identifier or raw) contains `SUBSTR`, ignoring ASCII case. `--tree` prints the hierarchy as an indented tree instead: each class under its first base, with its slot count, its size when known, `bases likely` for an inferred hierarchy, `abstract`, and its other bases; with `--name`, the matching classes, their ancestors and their descendants. The class model needs no decompilation (discovery, the vtables and a scan of the code around them: [CLASSES.md](../internals/CLASSES.md)), so this is about the time of `info`. ``` $ fast-decomp classes big/godot-win64.exe --tree --name HSeparator Object [38 slots, 336 bytes] Node [51 slots, 992 bytes] CanvasItem [87 slots, abstract] Control [102 slots, 2360 bytes] Separator [102 slots, 2384 bytes] HSeparator [102 slots, 2384 bytes] ``` ## class `class FILE (--name NAME | --id N) [--jobs N]`: one class: its names and RTTI, hierarchy status, size, bases (offset, status and evidence), derived classes, and per vtable (address point, subobject offset) every slot with its function, name, owner and kind, the functions that refer to the table, then the constructor and destructor candidates with their evidence. `NAME` is the demangled name, the C identifier or the RTTI name, exactly; when several classes have it (two anonymous namespaces), the error lists their ids. ## bench `bench FILE [--jobs N] [--repeat N] [--json] [--no-demand] [--no-types] [--no-unthread] [--profile]`: load, discovery and every function into a null sink; prints the wall time per phase (`names`: reading debug information and building the name table, what it adds to the run; `statics`: the data statics built beside it; `classes`: the class model, after the statics; `of which demand`: return demand's second pass; `merge types`: the structure merge), the thread time per stage and of the driver, the critical path, the process CPU time, functions/s, machine instructions/s, peak RSS, output size, and the counters of what was not understood. `--repeat N` reports the fastest of N complete runs. `--json` prints the same as one JSON object; `--no-types` skips the type stage (to measure it) (the input of `scripts/status.py`, which generates [STATUS.md](../STATUS.md)). `--profile` turns on the phase timers (`fd_core::prof`) and prints, after the table, discovery's phases (wall time) and every phase inside the stages ranked by its own thread time (time not spent in a phase opened inside it), with its share, inclusive time and count, then the resident memory at points of the run and the run's wall-clock timeline (each section from the start of discovery: start, wall and CPU time, the cores it kept busy, the most resident memory in it) ([PERF.md](../internals/PERF.md)). ``` $ fast-decomp bench bin/sqlite-gcc-O2 --jobs 6 --repeat 3 bin/sqlite-gcc-O2 functions 1646 (ok 1646, size-cutoff 0, verify-failed 0, internal-error 0, likely-withdrawn 0) code 850670 bytes, 46340 blocks, 214508 machine instructions (214508 exact, 0 intrinsic, 0 unknown) IR instructions: 751149 lifted (3.50/insn), 667426 SSA (3.11), 483776 optimized (2.26), 443536 analyzed (2.07) ... phase wall ms load 1.5 discover 16.2 schedule 0.5 names 0.4 statics 1.8 classes 0.1 strings 0.4 (beside classes) functions 263.2 (6 threads) of which demand 44.7 merge types 12.0 finish 0.2 total 296.2 stage thread ms share graph 9.5 0.6% lift 87.7 6.0% optimize 334.7 22.8% analyze 332.1 22.7% types 130.6 8.9% data 14.8 1.0% structure 198.0 13.5% emit 338.3 23.1% verify 0.0 0.0% driver 19.2 1.3% critical path 106.8 ms (longest call chain, each function with all its stages) process CPU time during the function phase: 1490.7 ms ... not understood: 0 unlifted instructions, 0 unresolved indirect jumps, 0 unknown block ends, 0 unproven jump tables, ... ``` ## libsig build, merge, info, match Signature files for library recognition ([LIBID.md](../internals/LIBID.md)). The image's debug information is never used by these commands except where `--pdb`/`--truth` names it. - `libsig build FILE --pdb PDB -o OUT [--whole LIBRARY] [--own-std] [--origin TEXT]`: one entry per runtime library function of a PE (by the PDB's module of the function's entry: the MSVC toolset's and the Windows SDK's libraries), one own-code entry per program function of at most 256 bytes. `--whole NAME`: every function is library code of `NAME` (a runtime DLL with its own PDB). `--own-std`: also the C++ standard library's instances in the program's own objects, as library `std` (a measurement). The PDB's age may be the CodeView record's in its information or its DBI stream (Microsoft's symbol server raises the first). - `libsig build FILE (--archive LIB.a ... | --all-symbols) --library NAME -o OUT`: from an image with symbols (ELF, mingw PE): the functions whose symbol one of the static archives defines (or every named function) are library `NAME`. - `libsig merge -o OUT [--library LIB,...] IN ...`: equal entries once, a signature with several names kept as a group that names nothing, own-code entries no library entry resembles dropped; `--library` keeps those libraries' entries. - `libsig info IN ...`: family, component, toolsets, builds, entries per library, origin. - `libsig match FILE [--sig IN ...] [--only] [--truth PDB [--wrong]] [--list]`: what the files (as a run finds them, plus `--sig`; `--only`: the `--sig` files alone) recognise in `FILE`, its debug information ignored: the toolset read from the image, the files used and why, then one line per function: address, size, name, library, evidence (or `?` and the candidates). `--truth PDB` prints instead, per class of code (the PDB's), the functions named right, wrong, given candidates (with and without the true name among them) and unnamed, the precision, the right and wrong names by evidence and by bytes not masked; `--wrong` lists the wrong names. ## selfcheck `selfcheck FILE [--sample N] [--seeds N] [--no-unthread] [--profile]`: the checked pipeline over every function, or over a deterministic sample of N (the functions with the smallest hash of their address): the IR verifier after lifting, after SSA construction, after simplification and after the analysis; the equivalence of the lifted and the optimized IR in the interpreter on `--seeds` random states (default 4; V3); the frame-aware equivalence of the optimized and the analyzed IR (STACK.md section 9) on as many states; the region-tree verifier (which every run makes); the AST check of the emitter (EMIT.md section 7) on as many seeds. Prints each failing function with its diagnostics (and, as `WITHDRAWN`, each function whose likely facts were taken back: a pass, its text checked), then a summary and `PASS` or `FAIL`; exit code 1 on any failure or internal error. `scripts/selfcheck_all.sh` runs it on every corpus binary (PIPELINE.md, "The routine check"). `--profile` adds the phase table of `bench --profile`, the checkers among the phases (`verify.ast`, `verify.stack`, ...). ``` $ fast-decomp selfcheck big/godot-win64.exe --sample 20000 --jobs 6 selfcheck .../godot-win64.exe: 20000 functions checked (2753203 machine instructions), 20000 passed (0 with likely facts withdrawn), 0 verify failures, 0 internal errors, 0 size cut-offs; ... s PASS ```