An experimental V port of fast-decomp, an x86-64 static decompiler. It loads an executable, discovers functions, lifts instructions to a checked intermediate representation, and prints C-like pseudocode. The implementation uses V ownership mode for its application code, with owning aggregates, explicit borrows, and independent clones where needed.
The upstream reference is commit
b64727aded1f6bcd60d866de425a349978522f7b.
The port implements SSA, whole-program analysis and a checked statement AST.
The mapping to all 18 upstream crates and remaining differences are listed in
PORTING.md. Upstream performance numbers and corpus results do
not describe this implementation.
Requirements: a recent V compiler with aggregate ownership support, a C compiler,
and Make. Tests additionally use Python 3, a C++ compiler, and strip. Linux
x86-64 is the tested host. The pinned compiler revision is
bcc7f9b287e07a8f2dbaaeed4b01c659445840a4.
git clone https://github.com/vlang/decomp
cd decomp
make V=/path/to/v/v
./bin/decomp --helpIf V is on PATH, make is sufficient. The build uses
v -ownership -prod -cc cc -o bin/decomp cmd/decomp. The application rejects a
build that omits ownership mode. V's default garbage collector stays enabled;
the ownership checker also handles owned cleanup in application code. See
OWNERSHIP.md for the distinction and the concrete borrowing
boundaries.
The instruction decoder is the vendored MIT-licensed Zydis 4.1.1 C library. V implements the loaders, discovery, IR, lifting, analyses, metadata, project handling, services, and emitter. Zydis supplies instruction lengths, operands, register effects, and assembly text. Its adapter retains no V pointers. The decoder builds locally; an installed decoder library or a Rust toolchain is not required. Dependency provenance includes exact revisions and regeneration instructions.
mkdir -p build
cc -O2 -g tests/fixtures/project_fixture.c -o build/demo
./bin/decomp info build/demo
./bin/decomp functions build/demo --name list
./bin/decomp disasm build/demo --function list_sum
./bin/decomp ir build/demo --function list_sum --stage lifted
./bin/decomp decompile build/demo --function list_sum
./bin/decomp decompile build/demo --function list_weight --verify --json
./bin/decomp export build/demo --out build/demo-decomp --jobs 4--address 0x... selects a function by its image virtual address. Addresses are
not file offsets and are not adjusted for a running process's ASLR slide. Names
can be original symbols, demangled names, generated C identifiers, or project
names. Ambiguous names require an address.
An export directory contains functions/*.c, fd_prelude.h, types.h, and
index.tsv, strings.tsv, globals.tsv, xrefs.tsv, vcalls.tsv, classes.tsv,
and methods.tsv. --single-file --out build/all.c writes one combined file and
both headers beside it. Output is deterministic across worker counts.
Export workers borrow one immutable session and own their function-local IR and
text; the writer emits results in address order in bounded batches.
| Area | Current implementation |
|---|---|
| Images | Checked ELF64/PE64/Mach-O/fat, immutable/RELRO reads, relocations, actual PLT targets, symbols/imports/exports, unwind, LSDA/SEH/EH3/EH4 and funclets |
| Debug data | Native DWARF 2–5 and PDB/MSF/CodeView readers, validated identities, ranges, names, types and signatures |
| Discovery | Staged recovery, boundaries and stack depth, direct/tail/import calls, thunks, guarded jump-table proofs and bounded fallbacks |
| Instructions | Integer/flag operations, scalar extensions, REP strings, SSE/AVX lanes, conversions/shuffles and explicit intrinsic effects |
| SSA and optimization | Global SSA, phi simplification, unthreading, known bits, width narrowing, arithmetic/magic-division rewrites, immutable folding, CSE/DCE and checked control recovery |
| Analysis | Frame lattice, escape/liveness, slot promotion, canaries, balance, stack/register parameters, variadics and returns; SCC summaries, caller demand, type unification and class flow |
| Output | Region forest, loops/switches/short circuits, phi destruction, local coalescing, independent statement AST, typed fields/locals/globals, enums/constants, virtual calls and explicit fallback |
| Names and classes | Native Itanium/MSVC/Rust legacy/v0 grammars, overload identifiers, runtime-string naming, RTTI, inheritance, vtables and constructor/destructor evidence |
| Library data | Platform prototypes, record layouts, constants/flag sets, contextual argument formatting, allocator/noreturn/FP evidence and runtime helper contracts |
| Library recognition | Native .libsig format, code/data/call-context matching, archive/PDB-backed build/merge/truth tools and bundled MSVC databases |
| Projects | Binary/fingerprint binding, function/global/line/parameter/frame/field assertions, C declarations and ABI layouts, validation, retraction and provenance-preserving compaction |
| Automation | Structured decompilation JSON, resident prepared facts with project edits/change generations, and MCP read tools over stdio |
The precise instruction families and operand limitations are in SUPPORTED_INSTRUCTIONS.md. The image reader can inspect ARM64 Mach-O metadata; instruction discovery and decompilation are x86-64 only.
The text describes recovered machine operations. It is pseudocode, not the
original source or a promise that a translation unit recompiles. Integer values
retain their machine widths. Floating operations use bit patterns and helpers,
so a scalar floating result can appear as uint64_t rather than a guessed C
return type. Function signatures, incomplete argument lists, and uncertain
metadata remain marked as likely or asserted.
__unknown(...) is an instruction whose semantics are not implemented. Its
known register and memory effects remain visible. __indirect_jump(...) is an
unresolved transfer. __clobbered_register(...) represents a call result or
volatile register value that cannot be determined. These markers are part of
the result and should not be read as no-ops.
The analysis assumes static code, the selected platform ABI, ordinary memory, and the default floating-point environment. It does not model concurrent interference, arbitrary self-modification, unmasked FP exceptions, or a custom calling convention. The default GC is part of the supported runtime setup.
A project defaults to BINARY.fdproj. --project DIR selects another project;
--no-project ignores it. A project is bound to the executable's complete
SHA-256, size and upstream quick hash. Older native metadata without a quick hash
still checks SHA-256. --force permits applying assertions to another binary
and marks the binding unverified. Function assertions also carry code size and
a relocation-insensitive fingerprint. Invalid subjects are withheld; fingerprint
mismatches warn while retaining address-bound assertions.
./bin/decomp project init build/demo
./bin/decomp annotate build/demo types --decl \
'struct node { int32_t key; int32_t flags; struct node *next; };'
./bin/decomp functions build/demo --name list_sumUse the address printed by functions in the next command:
./bin/decomp annotate build/demo func 0xADDRESS \
--name sum_keys \
--sig 'int32_t sum_keys(struct node *list)' \
--comment 'Sum the keys of the linked list'
./bin/decomp decompile build/demo --function sum_keys
./bin/decomp project check build/demo
./bin/decomp project compact build/demoThe type parser supports structures, unions, enumerations, typedefs, pointers, function-pointer declarators, arrays, qualifiers, flexible array members, explicit offsets/sizes, packing/alignment, and checked constant expressions. Layouts distinguish LP64 and Windows LLP64. Constant expressions are bounded to signed 64-bit arithmetic and reject overflow.
An asserted signature supplies parameter display names when its ABI placement is understood; it never truncates a machine value to a narrower asserted type. Parameter, frame-local and field assertions guide display names and typed expressions. Line comments and global assertions retain their addresses. Machine-derived read/write contracts remain separate from project assertions. Unsupported annotation keys are rejected; invalid subjects, declarations and signatures are checked before a write. For example:
./bin/decomp annotate build/demo param 0xADDRESS a1 --name list
./bin/decomp annotate build/demo frame 0xADDRESS local_20 --name temporary
./bin/decomp annotate build/demo field node 0 --name key --type int32_t--delete retracts the supplied properties. With no supplied property it
retracts all properties of that subject. Records retain per-property by and
note provenance through compaction. Projects use a versioned native format;
an upstream Rust project's metadata file is not assumed compatible.
Bundled signatures load by default. --libsig FILE adds a database,
--libsig-only selects only supplied databases, and --no-libsig disables
recognition. --pdb FILE selects a PDB, --no-debug disables debug input, and
--no-strnames disables runtime-string naming.
./bin/decomp libsig info libid/data/msvc/msvc-vc-14.38.libsig
./bin/decomp libsig match build/demo --list
./bin/decomp libsig build build/demo --all-symbols --library demo -o build/demo.libsig
./bin/decomp libsig merge -o build/combined.libsig build/demo.libsig
./bin/decomp libsig --helpConstruction also supports archive membership and PDB module provenance.
libsig match --truth FILE.pdb compares recognition against PDB truth.
Recognized types require agreement with actual parameter shapes; they do not
replace machine contracts.
serve retains the image and prepared facts, accepts one JSON request per line on stdin, and
writes one JSON response per line on stdout:
printf '%s\n' \
'{"id":1,"op":"functions","name":"list"}' \
'{"id":2,"op":"decompile","function":"list_sum"}' \
'{"id":3,"op":"callers","function":"list_sum"}' \
| ./bin/decomp serve build/demoRead operations include info, functions, disasm, ir, decompile,
imports, strings, globals, vcalls, xrefs, callers, callees, classes, class, and vtables.
functions supports cursor/limit; text operations support
offset/max_bytes with UTF-8-safe slicing. Decompilation JSON also describes
signatures/parameters, callers/callees, strings/globals/classes, assertions,
diagnostics and verification. callers and callees are directional queries.
Project operations are project_init, project_check, project_status,
annotate, reload, and changes_since. For example:
{"id":4,"op":"annotate","record":{"func":"0x1234","name":"read_packet"},"dry_run":true}annotate accepts exactly one record, records, or types; dry_run validates
without writing. Updates build validated replacement state, refresh retained
facts, compare emitted-text hashes and advance the generation token.
changes_since reports functions whose output changed since a token; unchanged
reloads advance the token without false changes. Failed validation leaves
files and token unchanged. Refresh currently reanalyzes the whole program;
upstream dependency-driven incremental performance is not reproduced.
./bin/decomp mcp BINARY exposes the read tools using JSON-RPC over stdio and
the MCP 2024-11-05 protocol. It reports tools through tools/list and accepts
tools/call. Diagnostic text goes to stderr.
make check
make test
./bin/decomp selfcheck build/demo --jobs 4 --seeds 4SSA, dominance, CFGs, regions and statement assignment are structurally checked.
--verify and selfcheck compare lifted versus optimized IR and optimized IR
versus an independently executed statement AST. Ordered traces include calls,
intrinsics, unknown effects, stores, returns and traps; seeded models compare
external effects. Separate concrete samples report unavailable memory, missing
external models, undefined values, unsupported semantics and exhausted budgets
as skipped. Arithmetic status flags are not ABI results; DF remains observable.
JSON results use structurally_valid and a separate verification object with
runs, matched, skipped, and skip_reasons, together with distinct effect-trace,
AST and frame statistics. Limited traces and skipped samples are not complete
matches. These are bounded differential checks, not proofs of arbitrary output.
The test suite includes loader corruption checks, real compiled/stripped ELF
and C++ RTTI fixtures, ownership move rejection, C type/layout checks, CFG and
jump-table regressions, upstream scalar rewrite cases, generated CFGs through
each stage, independently executed ASTs, emitted-C compilation/execution,
deterministic parallel output, all project subjects, library-signature commands
and MCP/session integration. Native x86 suites compare before/after optimization
against the CPU and report host-feature skips; exact coverage is documented in
the instruction table. Every V test compiles with -ownership; the runner also
rejects allocator diagnostics even on exit status 0. The upstream 29-binary
corpus has not been run, and no full output or performance parity is claimed.
MIT, preserving the upstream copyright notice. See LICENSE,
UPSTREAM.md, the Zydis/Zycore licenses under
thirdparty/zydis, and the library-data notice.