Beyond the C: Retargetable Decompilation using Neural Machine Translation

Iman Hosseini, Brendan Dolan-GavittarXiv 2022 · DOI

Introduction

Decompilation—the process of reversing binary machine code into human-readable source code—is a critical tool for security auditing and malware analysis. Traditional decompilers like Ghidra or Hex-Rays rely on extensive manual engineering and are largely restricted to the C language. Adapting these tools for modern languages like Go or OCaml requires significant effort to build language-specific parsers and intermediate representations.

Researchers at NYU have introduced Beyond The C (BTC), a neural decompiler that simplifies this process by treating decompilation as a pure Neural Machine Translation (NMT) task. By moving away from language-specific Abstract Syntax Trees (ASTs) and instead treating code as text, BTC offers a "retargetable" framework capable of handling multiple high-level languages with minimal adjustment.

The BTC Framework

The BTC system frames assembly-to-source translation similarly to translating between natural languages. The core of the system is a Transformer architecture, which has proven superior to earlier Recurrent Neural Network (RNN) approaches in handling the long-range dependencies found in code.

The BTC pipeline: from raw source and assembly files to a trained neural decompiler.

The methodology relies on three key pillars:

  1. Minimalist Preprocessing: Instead of complex parsing, the system performs basic normalization, such as whitespace cleaning and replacing string literals with generic tokens.
  2. Byte Pair Encoding (BPE): Rather than using language-specific lexers, BTC employs BPE to break code into sub-word units based on frequency. This allows the model to learn the syntax of any language without prior grammatical knowledge.
  3. Function-Level Mapping: To generate training pairs, the researchers utilize Call Frame Information (CFI) directives in assembly files. These directives provide a reliable map between assembly blocks and high-level source functions.

Datasets and Evaluation

To test the retargetability of BTC, the authors curated datasets for C, Go, Fortran, and OCaml. These ranged from small sets of ~10k functions to massive corpora, including a C dataset with 2 million functions from Debian packages and an OCaml dataset with 700k functions from the OPAM manager. Performance was measured using Average Edit Distance (AED), where a lower score indicates higher similarity to the original source code.

Insights on Language Verbosity

A significant contribution of this work is the analysis of "sequence contraction" ($\eta$), defined as the ratio of assembly tokens to source tokens. This metric quantifies how much information the model must compress during translation.

Distribution of sequence contraction η across different language pairs.

The researchers found that languages like Go are significantly more "verbose" in assembly compared to C. For instance, while the ratio for English-to-German translation is near 1.0, the ratio for Go assembly-to-source is approximately 15.1. This explains why certain languages are inherently more difficult for NMT models to decompile; the model must learn to synthesize a very concise high-level representation from a vast amount of low-level machine instructions.

Results and Qualitative Success

BTC achieved state-of-the-art results on established benchmarks. The large-scale C model reached an AED of 0.46, significantly outperforming previous neural decompilers (which scored ~0.70). More importantly, BTC produced the first-ever neural decompilation results for Fortran, Go, and OCaml.

Qualitatively, the model excels at recovering high-level control structures like loops and conditionals. Remarkably, it often "guesses" contextually appropriate variable names, a feat traditional decompilers rarely achieve. The system is also highly efficient, capable of decompiling over 10 functions per second on a standard GPU.

Limitations and Future Directions

While BTC provides a readable "sketch" of the original code, it is not yet a perfect source of truth. The "black box" nature of NMT means the model can occasionally introduce critical semantic errors, such as swapping mathematical operators. Furthermore, the current training pipeline depends on assembly files containing DWARF or CFI information. Future research will focus on adapting the model for "stripped" binaries where this metadata is absent and improving the handling of complex functional language features like OCaml's anonymous closures.

By releasing their datasets and models, the authors aim to shift the focus of the security community toward more flexible, language-agnostic decompilation tools.

Summary updated

BibTeX
@misc{hosseini2022beyond,
  author = {Iman Hosseini and Brendan Dolan-Gavitt},
  title = {{Beyond the C: Retargetable Decompilation using Neural Machine Translation}},
  year = {2022},
  eprint = {2212.08950},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2212.08950},
}
Figure