NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Pre-Training Representations of Binary Code Using Contrastive Learning

Yifan Zhang, Chen Huang, Yueke Zhang, Huajie Shao, Kevin Leach, Yu Huang

Abstract

Binary code analysis and comprehension is critical to applications in reverse engineering and computer security tasks where source code is not available. Unfortunately, unlike source code, binary code lacks semantics and is more difficult for human engineers to understand and analyze. In this paper, we present ContraBin, a contrastive learning technique that integrates source code and comment information along with binaries to create an embedding capable of aiding binary analysis and comprehension tasks. Specifically, we present three components in ContraBin: (1) a primary contrastive learning method for initial pre-training, (2) a simplex interpolation method to integrate source code, comments, and binary code, and (3) an intermediate representation learning algorithm to train a binary code embedding. We further analyze the impact of human-written and synthetic comments on binary code comprehension tasks, revealing a significant performance disparity. While synthetic comments provide substantial benefits, human-written comments are found to introduce noise, even resulting in performance drops compared to using no comments. These findings reshape the narrative around the role of comment types in binary code analysis. We evaluate the effectiveness of ContraBin through four indicative downstream tasks related to binary code: algorithmic functionality classification, function name recovery, code summarization, and reverse engineering. The results show that ContraBin considerably improves performance on all four tasks, measured by accuracy, mean of average precision, and BLEU scores as appropriate. ContraBin is the first language representation model to incorporate source code, binary code, and comments into contrastive code representation learning and is intended to contribute to the field of binary code analysis.

Introduction

Binary code is often described as the "dark matter" of software engineering. While source code is rich with human-readable variable names and logic-explaining comments, binary code—the actual executable instructions—is a stripped-down sequence of operations that is notoriously difficult for both humans and machines to analyze.

In their research, Vanderbilt, NUS, and William & Mary introduce ContraBin, a framework designed to bridge this semantic gap by aligning binary code with the high-level semantic "soul" it typically lacks.

The Semantic Gap in Binary Analysis

The core challenge in binary analysis is the loss of abstraction. When code is compiled, high-level structures (like a "quicksort algorithm") are replaced by low-level register moves and jumps. Existing AI models for code often focus on source code and struggle when applied to binaries due to a "cold start" problem: raw assembly lacks the inherent semantic markers that models typically latch onto. Previous attempts to bridge this gap often failed to account for the massive structural differences between high-level source and compiled assembly.

The ContraBin Framework

ContraBin addresses these challenges through a multi-modal pre-training framework that uses contrastive learning to align binary code with source code and natural language comments.

Overview of the ContraBin framework including data preparation, contrastive learning, and downstream tasks.

The framework consists of three primary stages:

  1. Multi-Modal Alignment: The model processes three "views" of the same program: source code, binary code (LLVM IR), and a natural language comment. Using a contrastive loss (similar to CLIP), it pushes representations of the same program together in a shared embedding space while separating different programs.
  2. Anchored Encoders: To stabilize training, the system uses "anchored" (frozen) encoders for high-level modalities (source and comments) while keeping the binary code encoder trainable. This forces the binary representation to align with the established semantic space of natural language.
  3. Task-Specific Fine-Tuning: The pre-trained binary encoder is then fine-tuned for specific downstream tasks such as functionality classification and reverse engineering.

Simplex Interpolation: The Secret Sauce

A key innovation in ContraBin is Simplex Interpolation (SI). The jump from assembly to high-level source code is often too large for a model to learn in a single step. SI uses linear and non-linear interpolation to create "intermediate" views, mimicking a "gradual learning" process. This allows the model to learn how complex assembly blocks map back to high-level logic more effectively.

Detailed architecture of the Learnable Simplex Interpolation Module.

Experimental Setup and Datasets

The researchers utilized the AnghaBench dataset, containing 1 million single-function C files, compiled to LLVM assembly. High-quality synthetic comments were generated using CodeT5 to provide a clean training signal.

Evaluation was conducted across several benchmarks:

  • POJ-104: For algorithmic functionality classification.
  • DIRE: For recovering function names from stripped binaries.
  • Reverse Engineering: Testing the ability to "decompile" binary back into source code.

Key Results and Insights

ContraBin demonstrated substantial improvements across all evaluated tasks:

  • Functionality Classification: Achieved a Mean Average Precision (MAP) of 43.78 on POJ-104, a 14.34% improvement over the RoBERTa baseline.
  • Function Name Recovery: Improved accuracy by 13.6% over state-of-the-art baselines.
  • Reverse Engineering: Improved the "Exact Match" score by 7.01% compared to GraphCodeBERT.

One of the most surprising findings was the "Comment Paradox": human-written comments often introduced more noise (due to copyright notices or irrelevant text) than synthetic ones. LLM-generated comments provided a much cleaner semantic signal for training. Furthermore, t-SNE visualizations confirmed that ContraBin successfully clusters semantically similar functions together, unlike standard models.

Conclusion and Future Work

ContraBin represents a significant step forward in binary code representation. By integrating source, binary, and natural language through contrastive learning and simplex interpolation, it provides a more robust foundation for binary analysis tasks. Future work will explore scaling to larger LLM architectures and incorporating human-in-the-loop evaluations to assess the real-world utility for reverse engineers.

Summary updated

BibTeX
@article{zhang2025pre,
  author = {Yifan Zhang and Chen Huang and Yueke Zhang and Huajie Shao and Kevin Leach and Yu Huang},
  title = {{Pre-Training Representations of Binary Code Using Contrastive Learning}},
  journal = {Accepted by TMLR},
  year = {2025},
  url = {https://openreview.net/forum?id=qmfUL6D0iz},
}
Figure