PCodeTrans Makes Decompiled Binaries Actually Run With 99.89% Accuracy
A new feedback-driven framework recompiles Hex-Rays output into source code that runs identically to the original binary, hitting 100% function-level compilability.
ProTakeaways
- PCodeTrans converts decompiled pseudocode into source code that both compiles and behaves like the original binary. Paper
- Hits 100% function-level compilability and 99.55%/99.89% behavioral equivalence on Coreutils and Binutils.
- Uses an LD_PRELOAD relocation engine to hot-swap recompiled functions into unmodified binaries at runtime.
- Breakpoint-Matched Differential Tracing pinpoints where recovered code diverges from the original for LLM repair.
- Resolves 76-80% of logic errors on unstripped binaries; degrades to ~26% file-level success on stripped code.
- Linux x86_64 ELF only, depends on Hex-Rays, no public code release yet.
Decompilers like Hex-Rays and Ghidra are the workhorses of binary reverse engineering, but their output has a dirty secret: it looks like C, but it usually won't compile, and even when it does, it rarely behaves like the original binary. A new framework called PCodeTrans attacks that gap head on, combining function-level recompilation with a hot-swap execution engine that validates recovered code against the binary's own test suite.
The results are unusually strong for this line of work. On Coreutils and Binutils, PCodeTrans attains 100% function-level compilability on unstripped binaries alongside 99.55% and 99.89% test-validated behavioral consistency, resolves 76.56% and 79.74% of logic errors exposed by official test suites, and maintains over 96% behavioral consistency even on fully stripped binaries.
Why decompiled C is a lie
Modern decompilers optimize for a human analyst squinting at pseudocode, not for a compiler. Hex-Rays often suffers from misrecovered or incompatible types, incorrect function prototypes such as varargs and struct returns, uninitialized variables, and non-standard constructs like tool-specific intrinsics and opaque jump-table encodings that mirror disassembly artifacts rather than compilable source-level semantics. The knock-on effect is that source-based tools like CodeQL, Semgrep, or automated fuzzers can't be pointed at binary-only software without significant manual cleanup.
Recent LLM-based cleanup pipelines have made things prettier without making them correct. Some pipelines iterate on compiler diagnostics and coarse runtime signals, while others introduce training signals combining syntactic correctness with symbolic execution and SMT solving, but these approaches either struggle to scale to complex production binaries or suffer from path explosion and depend heavily on precise modeling of complex execution environments including heap state, global variables, and external libraries. The authors argue this leaves a fundamental gap: no way to verify that a rewritten function actually behaves like what the CPU was running.
Three moves that make it work
PCodeTrans is built as a tight loop of three modules that address the failure modes above one at a time:
- Context-sufficient function compilation. Rather than allowing the LLM to hallucinate missing dependencies, PCodeTrans first establishes a minimal yet globally consistent compilation foundation by extracting type definitions, external function prototypes, and global variables directly from the binary using Hex-Rays' analysis. Compiler diagnostics then drive an LLM repair loop until each function builds as a standalone
.so. - In-situ substitutable execution. Each individually compiled function is hot-swapped back into the unmodified binary and executed in situ, supporting local function replacement under globally consistent runtime conditions. The original binary's test suite becomes the equivalence oracle - no manual test writing, no symbolic execution.
- Runtime feedback-guided repair. When tests fail, a two-stage diagnostic pipeline turns coarse pass/fail signals into surgical edit instructions.
The relocation engine, in plain terms
The hot-swap trick is the paper's most concrete engineering contribution. Rather than statically rewriting the binary on disk (as prior work like PRD does, at the cost of mangling function signatures with inline assembly), PCodeTrans patches things in memory at load time.
A helper library is injected via LD_PRELOAD. Before main() runs, it parses /proc/self/maps to find load bases, then does two things:
- It temporarily elevates the host binary's .text page to read/write/execute, then overwrites the original function's entry point with a compact control-transfer stub (trampoline). The stub is a four-instruction sequence that jumps to the new implementation in the injected dynamic library.
- It patches the substitute's GOT and GOT.PLT entries so that references to global variables and external functions route back into the original binary's address space. The replacement function reads the host's globals and calls the host's other functions natively.
Because everything happens in memory against standard, unmodified C code, the LLM never has to reason about ABI hacks or architecture-specific glue. The authors note the approach generalizes conceptually to Windows PE via DLL injection and Detours-style hooking.
Turning test failures into surgical fixes
When the swapped function fails a test, PCodeTrans runs a two-stage diagnostic. First, AddressSanitizer is compiled into the substitute (but not the host) to catch memory violations introduced by decompiler artifacts like uninitialized variables driving loop bounds.
The more interesting stage is Breakpoint-Matched Differential Tracing (BP-Diff). Because the recompiled function is structurally isomorphic to its pseudocode source, the system can plant matched breakpoints in both the original binary and the substituted version, then compare traces. Within each matched call, a comparator performs breakpoint-level alignment between the substituted trace and the ground truth to flag behavioral differences, such as missing or extra breakpoint hits or variable value mismatches. The resulting structured diff (which breakpoint diverged, which variables held different values, where control flow forked) is fed to the LLM as targeted repair instructions.
A case study makes this concrete: Hex-Rays recovered a global as an unsigned _BYTE, silently killing an if (byte_26018 < 0) branch. ASan sees nothing, but BP-Diff notices the original binary hit a breakpoint inside the branch that the substitute missed. The fix is a one-word cast to (signed char).
Numbers against the field
The paper evaluates against Hex-Rays and Ghidra raw output, plus LLM refinement systems DeGPT, SK2Decompile, FidelityGPT, and DeCLLM. At the function level, raw Hex-Rays gets to about 66% behavioral equivalence on Coreutils; learning-based baselines often make things worse. SK2Decompile falls to 24.61% equivalence on Coreutils and 18.95% on Binutils because hallucinated data structures and arbitrarily altered symbol names break external linkages.
At the file level, where every function in a binary must be correct, all baselines collapse to 0% while PCodeTrans recovers 81.48% of Coreutils and 75% of Binutils binaries as fully executable equivalents. The ablation shows the LLM repair loop is doing real work: static context reconstruction alone gets Coreutils compilation to 69%, and the compiler-guided repair loop pushes it to 100%.
Where it still breaks
Stripped binaries expose the framework's ceiling. File-level equivalence on stripped Coreutils drops to about 26%, largely because decompilers misidentify function boundaries or fragment contiguous stack buffers. A prominent failure mode is opaque signature recovery in indirect calls, where Hex-Rays incorrectly recovers a function pointer as taking no arguments while the original assembly explicitly prepares an argument register. BP-Diff can localize the symptom, but recovering the missing parameter requires inspecting register state - something the C-level oracle abstracts away.
Other current limits worth knowing:
- Linux x86_64 ELF only; Windows and Mach-O are conceptual, not implemented.
- Depends on Hex-Rays 9.1 for decompilation (a commercial license).
- Data layout reconstruction is not automated - the substitute still leans on the host binary's
.dataand.bsssections for globals, so this is not yet standalone recompilation. - No public code release accompanying the paper at time of writing.
Even with those caveats, PCodeTrans is a meaningful step toward making decompiled code usable by the source-level tooling ecosystem: static analyzers, source fuzzers, patch backporting, and vulnerability remediation. The core insight - that the original binary itself is the cheapest possible equivalence oracle if you can splice functions into it cleanly - is the kind of engineering idea that other decompilation projects are likely to borrow.