LmPa: Improving Decompilation by Synergy of Large Language Model and Program Analysis

Xiangzhe Xu, Zhuo Zhang, Shiwei Feng, Yapeng Ye, Zian Su, Nan Jiang, Siyuan Cheng, Lin Tan, Xiangyu Zhang · OpenReview

Abstract

Decompilation aims to recover the source code form of a binary executable, a critical task for malware analysis, vulnerability detection, and code reuse. A prominent challenge is recovering meaningful variable names from stripped binaries. We propose a novel method, GENNM, which leverages the synergy of large language models (LLMs) and program analysis. While LLMs encode rich knowledge, their limited input size often precludes sufficient global context. Our approach divides the task into multiple LLM queries and uses program analysis to correlate and propagate results. Evaluation shows that 75% of recovered names are considered good by users, and our technique outperforms state-of-the-art methods by 16.5% in precision and 20.23% in recall.

Introduction: The Challenge of Stripped Binaries

When software is compiled, human-readable metadata like variable names are typically removed to save space or protect intellectual property. This "stripping" process creates a significant barrier for reverse engineers. Traditional machine learning approaches treat variable renaming as a classification task, selecting names from a fixed vocabulary. However, this leads to three primary issues: a "closed vocabulary" that cannot generate new names, a "long-tail bias" favoring generic terms (e.g., buffer or ptr), and "local blindness" where the model lacks context from the broader program's call graph.

Figure 4: Comparison between original source code and the recovered variable names in a decompiled function, illustrating the mapping from placeholder names to descriptive identifiers.

Methodology: From Classification to Generation

The GENNM framework shifts the paradigm from classification to generation using a sequence-to-sequence architecture based on models like CodeGemma and CodeLlama. This allows the model to compose descriptive names from sub-word tokens rather than picking from a static list.

Symbol Preference Optimization (SymPO)

To address the long-tail bias, we introduced Symbol Preference Optimization (SymPO). Inspired by alignment techniques like Direct Preference Optimization (DPO), SymPO explicitly trains the model to prefer specific, descriptive names over generic ones. For instance, if a model predicts buffer where the ground truth is packet, SymPO adjusts weights to favor the more precise term in that specific context.

Context-Aware Propagation

GENNM employs iterative inference and validation. It predicts names for a function, propagates those names across the call graph, and uses a data-flow-based validation algorithm. This mimics the workflow of human experts who use function calls and interactions—such as seeing a variable passed to send_packet()—to deduce its purpose.

Key Insights: The Power of Context and Preference

A core finding is that human developers combine common concepts into unique names. Generative models excel at this by assembling names from frequent sub-tokens. Furthermore, global context is vital; a variable's role often becomes clear only when viewed through its interaction with other functions in the "neighborhood."

Figure 3: Comparison of variable name predictions across different models, highlighting how SymPO and global context move predictions from generic placeholders to specific, descriptive names.

Evaluation and Results

GENNM was tested against the DIRTY and VarCorpus benchmarks, using string similarity to ensure honest measures of generalization. Key findings include:

  • Superior Precision: GENNM outperforms previous leaders like VarBERT and ReSym by 5.6 to 11.4 percentage points.
  • Handling Unseen Data: In predicting names never seen during training, GENNM achieved a 168% improvement in precision compared to baselines (jumping from 8.5% to 22.8%).
  • Efficiency vs. Scale: Specialized fine-tuning allowed GENNM (2B or 7B parameters) to outperform massive models like GPT-4 by 11.3 points, proving that domain-specific training beats raw model size for decompilation tasks.

Conclusion and Future Work

While GENNM significantly advances variable name recovery, challenges remain with highly optimized binaries (-O2, -O3) which obscure code structure. Future research will focus on deeper semantic understanding of complex data structures and improving robustness across diverse compiler optimization levels.

Summary updated

Abstract

Decompilation aims to recover the source code form of a binary executable. It has many applications in security and software engineering such as malware analysis, vulnerability detection and code reuse. A prominent challenge in decompilation is to recover variable names. We propose a novel method that leverages the synergy of large language model (LLM) and program analysis. Language models encode rich multi-modal knowledge, but its limited input size prevents providing sufficient global context for name recovery. We propose to divide the task to many LLM queries and use program analysis to correlate and propagate the query results, which in turn improves the performance of LLM by providing additional contextual information. Our results show that 75% of the recovered names are considered good by users and our technique outperforms the state-of-the-art technique by 16.5% and 20.23% in precision and recall, respectively.
BibTeX
@misc{xu2023lmpa,
  author = {Xiangzhe Xu and Zhuo Zhang and Shiwei Feng and Yapeng Ye and Zian Su and Nan Jiang and Siyuan Cheng and Lin Tan and Xiangyu Zhang},
  title = {{LmPa: Improving Decompilation by Synergy of Large Language Model and Program Analysis}},
  year = {2023},
  eprint = {2306.02546},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.02546},
}
Figure