Abstract
Modern software compilation strips human-centric information, such as variable names, to optimize binary size and execution. This loss of semantic context presents a significant challenge for security researchers and reverse engineers. We present VarBERT, a specialized Transformer-based model that recovers original variable names from decompiled code with high accuracy. By utilizing a novel "Constrained Masked Language Modeling" (CMLM) approach, VarBERT learns the semantic relationships between code logic and identifiers directly from raw decompiler output. Our evaluation shows that VarBERT achieves over 84% accuracy, significantly outperforming existing structural-based methods while maintaining computational efficiency.
1. Introduction
When source code is compiled into binary form, meaningful identifiers like user_id or buffer_size are replaced by memory addresses or register offsets. Decompilers such as Hex-Rays or Ghidra can reconstruct the high-level logic but are forced to use generic placeholders (e.g., v1, a1). Previous attempts to solve this, such as the DIRE framework, relied on complex Abstract Syntax Trees (ASTs) and Graph Neural Networks, which are often computationally expensive and sensitive to minor structural variations.
VarBERT addresses these limitations by treating decompiled code as a natural language processing task. It demonstrates that the self-attention mechanism of Transformers is sufficient to infer code structure from raw text, eliminating the need for explicit AST extraction.
2. Methodology
VarBERT adapts the BERT (Bidirectional Encoder Representations from Transformers) architecture for the specific domain of decompiled C code. The core of the system relies on three primary innovations:
2.1 Constrained Masked Language Modeling (CMLM)
Unlike standard BERT training, which masks random tokens, CMLM specifically targets tokens corresponding to variable names. This forces the model to focus its learning capacity on the semantic "slots" where identifiers reside, learning to predict names based on the surrounding logical context.
2.2 Byte-Pair Encoding (BPE) and Tokenization
To handle the nearly infinite variety of potential variable names, VarBERT employs Byte-Pair Encoding. This allows the model to decompose complex names (e.g., get_user_name) into sub-word units (get, _user, _name), effectively managing out-of-vocabulary terms and improving generalizability.
2.3 Heuristic-Based Prediction
Because a single variable name may consist of multiple BPE tokens, the model must determine the correct number of masks to fill. The authors implemented a "Count of Token Prediction" heuristic that evaluates different mask lengths and selects the sequence with the highest average probability.
3. Experimental Evaluation
The model was trained on the DIRE dataset, comprising 164,632 unique x86-64 binaries derived from GitHub C projects. Two variants were tested: VarBERT-base (12 layers) and VarBERT-small (6 layers).
3.1 Key Results
- Accuracy: VarBERT-base achieved a 84.15% Top-1 Exact Match accuracy, surpassing the previous state-of-the-art (DIRE) by 12.36%.
- Generalization: The model showed a 49% improvement over previous methods in predicting variable names not seen during training, indicating it learns naming logic rather than simple memorization.
- Efficiency: VarBERT-small performed within 3% of the base model's accuracy while being significantly faster to train; on a 1% data subset, it trained in 3 hours compared to 13 hours for DIRE.
4. Discussion and Limitations
While VarBERT represents a significant leap in automated reverse engineering, some limitations remain. The model is currently optimized for Hex-Rays decompiler output; adaptation to other tools like Ghidra would require retraining. Additionally, the current token-count heuristic could be replaced by a dedicated neural network to further refine prediction accuracy. Future research may also explore training on obfuscated binaries to test the model's resilience against adversarial code transformations.
5. Conclusion
VarBERT demonstrates that modern NLP techniques, specifically Transformers with constrained masking, can effectively bridge the semantic gap in decompiled code. By outperforming structural models in both accuracy and speed, VarBERT provides a robust foundation for the next generation of automated reverse engineering tools.
Summary updated