Symbol Preference Aware Generative Models for Recovering Variable Names from Stripped Binary

Xiangzhe Xu, Zhuo Zhang, Zian Su, Ziyang Huang, Shiwei Feng, Yapeng Ye, Nan Jiang, Danning Xie, Siyuan Cheng, Lin Tan, Xiangyu Zhang

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:

  1. The Closed-Vocabulary Problem: A classifier cannot predict a variable name it hasn't explicitly seen during training.
  2. The Long-Tail Bias: Variable names follow a highly skewed distribution. A few names (like buffer or data) 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.
  3. 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:

  1. 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, and len into ip_hdrlen).
  2. 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.
  3. 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 packet over buffer in 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.

Fig. 6: Training pipeline of GENNM

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.
Fig. 3: Distribution of name frequencies. More than 50% vari- able names (in orange) appear only once in the training dataset.

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

Abstract

Decompilation aims to recover the source code form of a binary executable. It has many security applications, such as malware analysis, vulnerability detection, and code hardening. A prominent challenge in decompilation is to recover variable names. We propose a novel technique that leverages the strengths of generative models while mitigating model biases. We build a prototype, GenNm, from pre-trained generative models CodeGemma-2B, CodeLlama-7B, and CodeLlama-34B. We finetune GenNm on decompiled functions and teach models to leverage contextual information. GenNm includes names from callers and callees while querying a function, providing rich contextual information within the model's input token limitation. We mitigate model biases by aligning the output distribution of models with symbol preferences of developers. Our results show that GenNm improves the state-of-the-art name recovery precision by 5.6-11.4 percentage points on two commonly used datasets and improves the state-of-the-art by 32% (from 17.3% to 22.8%) in the most challenging setup where ground-truth variable names are not seen in the training dataset.
BibTeX
@misc{xu2023symbol,
  author = {Xiangzhe Xu and Zhuo Zhang and Zian Su and Ziyang Huang and Shiwei Feng and Yapeng Ye and Nan Jiang and Danning Xie and Siyuan Cheng and Lin Tan and Xiangyu Zhang},
  title = {{Symbol Preference Aware Generative Models for Recovering Variable Names from Stripped Binary}},
  year = {2023},
  eprint = {2306.02546},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.02546},
}
Figure