TL;DR
This paper introduces SLaDe, a novel small language model decompiler that achieves state-of-the-art accuracy and readability for optimized assembly code across different architectures (x86 and ARM). By combining a Transformer model with a type inference engine and training on real-world code, SLaDe significantly outperforms existing decompilers like Ghidra and large language models like ChatGPT.
What Problem Does This Paper Address?
Decompilation, the process of converting low-level assembly code back into human-readable source code, is crucial for tasks like legacy code porting and malware analysis. However, existing decompilers face significant challenges:
- Traditional decompilers (e.g., Ghidra) are often hard to read, struggle with external type declarations, and require extensive manual effort to support new architectures and optimization levels.
- Existing neural decompilers have shown promise in generating more readable code but are typically limited to synthetic, unoptimized code and often produce incorrect results.
- Large Language Models (LLMs) like ChatGPT can generate code, but their performance on decompilation is inconsistent, often producing code that is both hard to read and incorrect, despite their massive size.
The authors aim to bridge this gap by creating a decompiler that is accurate, readable, portable across architectures and optimization levels, and requires minimal engineering effort.
Methods
SLaDe employs a novel approach that combines several key techniques:
- Small Language Model (SLM) Transformer: SLaDe uses a 200M-parameter Transformer model, significantly smaller than typical LLMs, trained specifically for decompilation at the function level.
- Sequence-to-Sequence Architecture: The model is trained as a sequence-to-sequence system, taking assembly code as input and generating C code as output.
- Novel Tokenization: A custom tokenizer is used to handle code effectively, derived from character frequencies and employing subword tokenization to manage out-of-vocabulary tokens.
- Dropout-Free Regularization: To improve semantic accuracy, the model is trained without dropout, relying instead on weight decay regularization.
- Type Inference Augmentation: A critical innovation is the integration of a type inference engine (PsycheC). Since neural decompilers often struggle with inferring types for external functions or complex data structures, PsycheC analyzes the generated code and its constraints to infer missing types, making the decompiled code compilable and executable.
- Training on Real-World Code: Unlike previous neural approaches, SLaDe is trained on a large dataset of real-world, optimized assembly code, making it more robust and practical.
Datasets
- Training Data: The model is trained on an expanded version of the AnghaBench dataset, combined with assembly-C pairs from ExeBench, totaling approximately 4 million functions. This dataset includes code from GCC with various optimization levels.
- Evaluation Data:
- ExeBench: A large-scale benchmark suite with over 4,000 functions, used to evaluate performance across two ISAs (x86 and ARM) and two optimization levels (-00 and -03).
- Synth Benchmarks: A smaller, simpler benchmark suite used for detailed analysis and to evaluate performance on programs with simpler types.
Key Insights and Ideas
- Small Models Can Be Powerful: SLaDe demonstrates that a relatively small Transformer model (200M parameters) can achieve superior performance in decompilation compared to much larger LLMs like ChatGPT, especially when fine-tuned for the specific task.
- Type Inference is Crucial for Accuracy: The integration of a type inference engine is a game-changer. It significantly improves the compilability and correctness of the generated code, addressing a major limitation of previous neural decompilers.
- Real-World Data Matters: Training on actual optimized assembly code, rather than synthetic examples, is key to achieving practical and robust decompilation performance.
- Portability is Achievable: SLaDe's ability to work across different ISAs (x86 and ARM) and optimization levels with minimal re-engineering effort highlights the potential of neural approaches for broad applicability.
- Readability vs. Correctness Trade-off: While many neural approaches prioritize readability, SLaDe achieves a strong balance, producing code that is both significantly more readable than traditional decompilers and more accurate than existing neural methods.
Key Results
- Accuracy: SLaDe is up to 6x more accurate than Ghidra and up to 4.2x more accurate than ChatGPT on the ExeBench dataset.
- Readability: SLaDe generates significantly more readable code than both Ghidra and ChatGPT, as measured by edit similarity.
- Portability: SLaDe demonstrates strong performance across both x86 and ARM architectures, and across -00 and -03 optimization levels, outperforming Ghidra significantly, especially on optimized code.
- Type Inference Impact: The type inference algorithm improves SLaDe's performance by an average of 14%, enabling more decompiled examples to compile.
- Model Size: SLaDe achieves its performance with a model size orders of magnitude smaller than ChatGPT.
Limitations and Future Work
- External Function Calls: SLaDe's failures are often due to incorrectly predicting arguments for externally declared functions.
- Complex Data Structures: While type inference helps, mistyping arguments for matrix variables (e.g., mistaking floats for integers) remains a challenge.
- Future Work: The authors suggest increasing the scope of decompilation to larger program units, exploring pre-training and program repair techniques, and investigating hybrid approaches that integrate learnable and analytic methods. They also believe further exploration of combinations of neural approaches and analytic techniques like type inference is warranted.
Summary updated