Skip to main content
QUICK REVIEW

[Paper Review] Variable Name Recovery in Decompiled Binary Code using Constrained Masked Language Modeling

Pratyay Banerjee, Kuntal Kumar Pal|arXiv (Cornell University)|Mar 23, 2021
Software Engineering ResearchComputer Science51 references5 citations
TL;DR

This paper proposes VarBERT, a constrained masked language modeling approach using BERT and Byte-Pair Encoding to recover meaningful variable names from decompiled binary code. By addressing the challenge of predicting the correct number of masked tokens through a heuristic post-processing step, the model achieves 84.15% exact match accuracy on a large-scale dataset of 164,632 binaries, significantly outperforming prior state-of-the-art methods.

ABSTRACT

Decompilation is the procedure of transforming binary programs into a high-level representation, such as source code, for human analysts to examine. While modern decompilers can reconstruct and recover much information that is discarded during compilation, inferring variable names is still extremely difficult. Inspired by recent advances in natural language processing, we propose a novel solution to infer variable names in decompiled code based on Masked Language Modeling, Byte-Pair Encoding, and neural architectures such as Transformers and BERT. Our solution takes extit{raw} decompiler output, the less semantically meaningful code, as input, and enriches it using our proposed extit{finetuning} technique, Constrained Masked Language Modeling. Using Constrained Masked Language Modeling introduces the challenge of predicting the number of masked tokens for the original variable name. We address this extit{count of token prediction} challenge with our post-processing algorithm. Compared to the state-of-the-art approaches, our trained VarBERT model is simpler and of much better performance. We evaluated our model on an existing large-scale data set with 164,632 binaries and showed that it can predict variable names identical to the ones present in the original source code up to 84.15\% of the time.

Motivation & Objective

  • To address the critical challenge of recovering meaningful variable names in decompiled binary code, which hinders reverse engineering of stripped binaries.
  • To improve upon existing methods like DEBIN and DIRE, which suffer from poor generalization, high computational cost, or limited performance.
  • To leverage recent advances in NLP—specifically BERT and masked language modeling—for variable name recovery in low-level code.
  • To develop a simpler, more data-efficient model that generalizes well across diverse binary programs.
  • To reduce the manual effort required in renaming variables during reverse engineering by automating semantic name inference.

Proposed method

  • Fine-tune a BERT-based model using constrained masked language modeling, where masked tokens represent unknown variable names in decompiled code.
  • Use Byte-Pair Encoding to learn a code-specific vocabulary from raw decompiled C code, enabling better tokenization of low-level constructs.
  • Introduce a heuristic-based post-processing algorithm to predict the correct number of masked tokens for each variable name, addressing a key challenge in masked prediction.
  • Train two variants—VarBERT-base and VarBERT-small—on a large dataset of 164,632 x86-64 binaries derived from GitHub C projects.
  • Leverage contextual representations from Transformers to capture syntactic and semantic context around variables, improving name prediction.
  • Evaluate performance using exact match accuracy and generalization metrics on both training and out-of-distribution code samples.

Experimental results

Research questions

  • RQ1Can constrained masked language modeling effectively recover variable names in decompiled binary code with high accuracy?
  • RQ2How does the proposed model compare to state-of-the-art baselines like DEBIN and DIRE in terms of accuracy and generalization?
  • RQ3To what extent does the model generalize to variable names not seen during training, especially those from shared libraries?
  • RQ4How does the model perform on variable names split into multiple tokens, and what are the primary failure modes?
  • RQ5Can a smaller, more efficient BERT model achieve comparable or better performance than larger, more complex architectures?

Key findings

  • The VarBERT-small model achieves an exact match accuracy of 84.15% on the DIRE dataset, surpassing prior state-of-the-art models by 12.36 percentage points.
  • The model generalizes significantly better than baselines, with a 49% improvement in generalization performance on code not seen during training.
  • The model performs well on multi-token variable names, maintaining reasonable accuracy even for names split into two to five tokens.
  • The primary error types are incorrect token count prediction, partial token misgeneration, and off-by-few-chars errors, which stem from ambiguity in the prediction space.
  • The model is more data-efficient and computationally lighter than DIRE, while achieving superior performance with a smaller architecture.
  • The heuristic-based token count prediction algorithm effectively addresses the challenge of variable name length uncertainty, enabling high-accuracy inference.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.