Abstract
Traditional decompilation relies on extensive, hand-crafted rule sets that are difficult to maintain and often produce unreadable output. We present TraFix, a framework that leverages Neural Machine Translation (NMT) combined with program analysis to automate the decompilation of low-level code (x86 assembly and LLVM IR) into structured, readable C. TraFix achieves success rates of up to 97% on LLVM IR and 88% on x86 assembly by generating code templates and filling them using dependency analysis.
Introduction
Decompilation—the process of reversing low-level binary or assembly code back into a high-level language—is a critical task in security research and reverse engineering. Current state-of-the-art decompilers, such as Hex-Rays, are built upon thousands of brittle, manually defined rules. These tools are expensive to develop and often produce "assembly-in-C," which technically reflects the logic but lacks the readability of idiomatic source code.
TraFix aims to replace these manual rules with a trainable system. By observing how standard compilers (like gcc or clang) translate source code into assembly, the system learns to reverse the process using deep learning techniques.
Methodology: The TraFix Framework
The authors propose a two-phase approach called TraFix (TRAnslate and FIX) to bridge the gap between neural intuition and algorithmic precision.
- Phase 1: Template Generation: An NMT model, specifically an LSTM-based encoder-decoder with an attention mechanism, translates low-level code into a high-level code template. This template captures the logical structure (e.g.,
whileloops,ifstatements) but uses placeholders for specific variables and constants. - Phase 2: Template Filling: Because neural networks often struggle with exact numerical constants, TraFix employs Program Dependence Graphs (PDGs) to find an isomorphism between the input assembly and the generated C template. This allows the system to mathematically "fill in" the correct variable names and numeric values.
Key Innovations
To enhance the performance of the NMT model, the researchers introduced several key techniques:
- Canonicalization: Input code is simplified to help the model identify patterns. For instance, C code is transformed into a "post-order" notation (where operators follow operands), making its structure more analogous to the sequential nature of assembly instructions.
- Self-Improvement Loop: TraFix automatically generates its own training data by compiling random C snippets. If the system fails to decompile a snippet correctly, that failure is added back into the training set, allowing the model to learn from its mistakes over time.
Results and Evaluation
The framework was evaluated on 2,000 test statements across LLVM IR and x86 assembly. TraFix successfully decompiled 97% of LLVM IR benchmarks and 88% of x86 assembly benchmarks, even with default compiler optimizations enabled.
Beyond raw success rates, the readability of the output is a significant improvement over traditional tools. TraFix produces structured C code using standard control flow blocks like while and if, making the results much easier for human auditors to understand compared to the goto-heavy output of rule-based decompilers.
Limitations and Future Work
While TraFix shows great promise, it currently faces limitations regarding input length; as code blocks grow longer, the success rate tends to decrease. Additionally, the current implementation focuses on arithmetic and control flow, leaving complex data structures like pointers and custom struct types for future research. The authors suggest that scaling the model and integrating more sophisticated "de-optimization" techniques will be key to handling more complex binary transformations.
Summary updated