LLM4Decompile: Decompiling Binary Code with Large Language Models
Hanzhuo Tan, Qi Luo, Jing Li, Yuqun Zhang
cs.PL, cs.CL
2024-03-08
LLM4Decompile fine-tunes DeepSeek-Coder (1.3B to 33B) to turn x86 assembly into C. The 6.7B model reaches 45.4% re-executability on HumanEval, against 16.01% for GPT-4o.
Decompilation turns machine code back into a high-level language. Ghidra and IDA Pro match branches and loops on the control-flow graph, but the pseudo-code still reads like a literal rendering of assembly. In the paper's running example, a nested for-loop becomes a do-while wrapped around a while, array indexing becomes pointer arithmetic, and the return type shows up as undefined4. Names are gone. Legacy migration and security instrumentation need source that a person can read and a compiler can build.
Two LLM setups were already around. One rewrites a traditional decompiler's output. DeGPT cut the cognitive load of Ghidra's result by 24.4%. DecGPT, with compiler errors fed back in, reports re-executability above 75% on IDA Pro: the share of decompiled functions that compile again and pass tests. Those numbers come from other setups. General models are pretrained on source, so binaries are a weak spot. The other setup fine-tunes a model to map assembly straight to source. Earlier open models sat near 200M parameters; the closed Nova model is about 1B. LLM4Decompile stretches the open range to 1.3B-33B and spends about 15B tokens on the task.
The base is DeepSeek-Coder. Training is sequence-to-sequence: given assembly, predict the C tokens. The loss ignores the prompt. Raw bytes never enter the model. Objdump disassembles the binary first.
LLM4Decompile-End scales that training in three steps. The corpus is ExeBench, about five million C functions. Each function is compiled with GCC at O0 through O3, from almost no optimization to aggressive optimization, and every build is paired with the same source. That sweep is data augmentation for the inverse problem. Dedup follows StarCoder, MinHash plus LSH, and samples under 10 tokens are dropped.
Training then has two stages. Stage one uses object files that compile but are not linked, so external symbols have no addresses yet. After filtering: about 7.2M samples and 7B tokens, enough to soak the model in assembly. Stage two switches to executables, about 1.6M samples and 572M tokens, so real calls show up. The 1.3B and 6.7B models train two epochs at batch size 2048 and learning rate 2e-5, about 15B tokens. On 8 A100s that is 12 days and 61 days. The 33B run stalled on cross-GPU communication and saw only 200M tokens.
LLM4Decompile-Ref changes the input. Ghidra emits pseudo-code, and the model rewrites the whole function into readable, compilable C. The pseudo-code is ugly, but the logic is mostly intact, which is easier than reading bare assembly. Ghidra Headless needs about 2 seconds per ExeBench executable even at 128 cores, and about 0.2 seconds on an unlinked object, so training uses the latter. The same O0-O3 sweep and dedup apply, and over-long samples are dropped. They keep 400K functions per optimization level, about 1B tokens. The 1.3B and 6.7B Ref models see about 2B tokens: 2 days and 8 days on 8 A100s.
Evaluation uses two sets. The 164 HumanEval problems are ported to C that depends only on the standard library. That set is HumanEval-Decompile. ExeBench contributes 5,000 GitHub functions with user-defined structs and calls. Re-executability means compile, disassemble, decompile, then rerun the original assertions.
Average re-executability over O0-O3:
| Model | HumanEval | ExeBench |
| DeepSeek-Coder-6.7B | 0.00% | 0.00% |
| GPT-4o | 16.01% | 3.78% |
| End-1.3B | 27.32% | 14.49% |
| End-6.7B | 45.37% | 17.98% |
| End-33B (200M tokens) | 31.54% | 15.40% |
The 6.7B model scores 68.05% at O0 and 36.71%-39.51% at O1-O3. GPT-4o manages 30.49% at O0 and about 10%-12% once optimizations are on. On HumanEval, 45.37% versus 16.01% is about 2.8×. On ExeBench, 17.98% versus 3.78% is about 4.8×. The abstract's "over 100%" is a relative gain, not an absolute rate. The untuned 6.7B baseline is zero on every column.
Which corpus you train on decides which benchmark you win. A 6.7B model trained only on compilable samples reaches 37.50% on HumanEval and 6.83% on ExeBench. Trained only on executable samples, those flip to 23.78% and 26.69%. The two-stage headline model hits 45.37% on HumanEval, above both single-corpus runs, but 17.98% on ExeBench, below the executable-only run at 26.69%. The benchmark closer to real project code does not peak under the two-stage recipe. There is also no comparison at a matched token budget, so data type and data volume stay tangled.
Ref is reported only on HumanEval-Decompile. Edit similarity is textual closeness to the original source.
| Model | Re-executability | Edit similarity |
| End-6.7B | 45.37% | 13.53% |
| Ghidra | 20.12% | 6.20% |
| Ghidra+GPT-4o | 35.22% | 5.72% |
| Ref-1.3B | 46.04% | 13.50% |
| Ref-6.7B | 52.74% | 13.82% |
| Ref-33B (200M tokens) | 50.91% | 13.97% |
Ref-6.7B moves Ghidra from 20.12% to 52.74%, about 2.6×, which the paper calls a 160% increase. Against End-6.7B, the step from 45.37% to 52.74% is a 16.2% relative gain, on about 2B tokens versus 15B. Ref-1.3B averages 46.04%, a hair above End-6.7B. Prompted GPT-4o lifts Ghidra to 35.22% re-executability while edit similarity falls from 6.20% to 5.72%. A Ref-22B row in the same table averages 64.18%, with the setup left to the appendix. Ref-33B, on about a tenth of the Ref tokens, lands at 50.91%, roughly 3.6% relative below Ref-6.7B. By level, Ref-6.7B scores 74.39%, 46.95%, 47.56%, and 42.07%.
GPT-4o readability scores from 1 to 5 average 2.44 for GPT-4o's own decompilation, 2.57 for Ghidra, and 3.54 for End-6.7B (4.07 at O0, 3.24 at O3). In the case study, GPT-4o turns a 1D array into a 2D array and misses the bounds. Ghidra plus GPT-4o still shows while-loops and pointer math. End and Ref recover nested for-loops and index syntax, but they invent names such as x, n, and eps, and may rewrite fabs as fabsf. Edit similarity tops out near 14% because compilation has already deleted the names.
Obfuscator-LLVM's control-flow flattening (CFF, a state variable and a dispatcher hide the branches) and bogus control flow (BCF) wipe out most of the gain. Ref-6.7B falls from 52.74% to 5.19% under CFF and 11.59% under BCF, drops of 90.2% and 78.0%. End-6.7B averages 4.27% and 8.69%. On CFF, Ghidra's 7.93% beats both models.
The largest previous open decompiler model was about 200M. This series runs from 1.3B to 33B, and the weights, data, and code are released. For recovering a legacy C function, or for sending decompiled output back through a compiler, the 6.7B end model is more likely to pass tests than pasting assembly into GPT-4o.
The practical hook is Ref behind Ghidra. The decompiler has already sketched the control flow. The model cleans syntax and structure. Ref-6.7B uses about 13% of the end-to-end tokens and still beats End-6.7B on HumanEval.
End-6.7B took 61 days on 8 A100s. On real ExeBench functions the pass rate stays under 18%. Treat it as an open baseline. It does not replace an IDA or Ghidra workflow.
The study is C on x86 only. Full fine-tunes stop at 6.7B. The 33B runs are 200M-token probes, and 70B is left open. The stated budget is about 8 A100s for a year, failed runs included.
The 16.2% Ref gain has no ExeBench number. HumanEval-Decompile is 164 functions ported from Python, standard library only. That is a different distribution from repository code with custom structs. The end model itself drops from 45.37% to 17.98% across the two sets.
The 33B results do not show that bigger is better. End-33B averages 31.54%, behind a fully trained 6.7B. The gap tracks tokens.
Re-executability means assertions passed. It does not mean the recovered function matches the original semantics. The 1-5 readability scores are another model's judgment, which the paper calls subjective.
IDA Pro, Hex-Rays, DecGPT, and Slade are not compared under one protocol. Slade depends on compiler intermediate files that releases usually omit. DecGPT's figure above 75% is on IDA Pro, with compiler errors in the loop.
Inputs are per-function Objdump assembly. The figures show labels such as func0. This is not recovery from a stripped whole-program binary, where the model would have to find function boundaries itself. Obfuscation covers only CFF and BCF. Ghidra wins on CFF, and Ref-6.7B still passes 11.59% under BCF. Basic obfuscation lowers the rate. It does not show that industrial protection is already enough.