TL;DR
This paper introduces GENNM, a novel system that leverages generative large language models (LLMs) to recover meaningful variable names from stripped binaries during decompilation. By incorporating global calling contexts and optimizing for developer naming preferences rather than raw token frequency, GENNM significantly outperforms traditional classification-based approaches, especially on rare or completely unseen variable names.
What Problem Does This Paper Address?
When software is compiled into a binary executable, helpful metadata like variable names are typically stripped away to save space or protect intellectual property. Reverse engineers rely on decompilers to translate this binary back into human-readable source code, but the resulting code is littered with generic placeholders (e.g., v29, v57, s).
Previous machine learning attempts to rename these variables treat the problem as a classification task over a fixed vocabulary. This introduces three major flaws:
- The Closed-Vocabulary Problem: A classifier cannot predict a variable name it hasn't explicitly seen during training.
- The Long-Tail Bias: Variable names follow a highly skewed distribution. A few names (like
bufferordata) appear tens of thousands of times, while over 50% of names appear only once or twice. Classifiers naturally default to these high-frequency, generic names. - Context Blindness: Existing models analyze functions in isolation, completely missing vital clues hidden in neighboring caller or callee functions.
Methods
GENNM addresses these limitations by shifting the paradigm from classification to generative sequence modeling using fine-tuned open-source LLMs (such as CodeGemma-2B and CodeLlama).
The framework relies on three core techniques:
- Generative Fine-Tuning: Instead of picking from a fixed list, GENNM generates names token-by-token. This allows it to compose entirely new or rare names out of common sub-words (e.g., combining
ip,hdr, andlenintoip_hdrlen). - Context-Aware Propagation: To avoid overwhelming the LLM's token window with entire codebases, GENNM uses function signatures as lightweight summaries. It iteratively propagates predicted names along the program's call graph, allowing information from callers and callees to inform local variable predictions.
- SYMbol Preference Optimization (SymPO): To counteract the long-tail dataset bias, the authors adapted Direct Preference Optimization (DPO). SymPO explicitly trains the model to favor contextually precise names over generic, high-frequency ones (e.g., preferring
packetoverbufferin a network programming context).
Finally, a Name Validation step uses static data-flow analysis and majority voting to ensure that the generated names remain semantically consistent across multiple iterations.
Datasets
The authors evaluated GENNM on two prominent datasets, applying strict deduplication rules (filtering out binaries where fewer than 70% of functions were unique) and string-similarity thresholds to prevent data leakage:
- The DIRTY Dataset: Rebuilt from popular GitHub C/C++ projects to ensure binaries were fully stripped.
- The VarCorpus Dataset: Derived from Linux packages via the Gentoo package manager.
Key Insights and Ideas
- Names are Compositional: Human developers rarely invent completely random variable names; they compose them from common keywords. Generative models naturally mirror this cognitive process, allowing them to accurately predict names never seen in the training set.
- Frequency $\neq$ Preference: Standard training losses reward models for guessing the most common word. By framing the problem around developer preference via SymPO, the model learns that a less frequent word can be a much better fit for a specific programming domain.
- Call Graphs as Context Summaries: Passing entire function bodies of callers/callees degrades LLM performance due to long-context attention issues. Passing just the signatures provides the perfect balance of semantic richness and token efficiency.
Key Results
GENNM was evaluated against state-of-the-art baselines like VarBERT (classification-based) and ReSym (LLM-based):
- Overall Accuracy: GENNM outperformed VarBERT by 5.6 to 11.4 percentage points in precision and recall across both datasets.
- Unseen Names: In the most challenging setup—where the ground-truth variable names were completely absent from the training set—GENNM improved precision by 32% over the closest baseline (boosting precision from 17.3% to 22.8%).
- vs. Black-Box LLMs: GENNM outperformed massive commercial models like GPT-4 and GPT-3.5 by 11.3 percentage points in precision, demonstrating that task-specific fine-tuning beats raw model scale for decompiled code analysis.
Limitations and Future Work
The authors note that aggressive compiler optimizations (-O2 and -O3) remain a significant hurdle. Optimization flags drastically alter control-flow and eliminate intermediate variables, causing the decompiled output to diverge heavily from standard source code distributions. Future work will focus on enhancing the model's structural understanding of heavily optimized binaries.
Summary updated