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

CLAP: Learning Transferable Binary Code Representations with Natural Language Supervision

Hao Wang, Zeyu Gao, Chao Zhang, Zihan Sha, Mingyang Sun, Yuchen Zhou, Wenyu Zhu, Wenju Sun, Han Qiu, Xi Xiao

Introduction

Binary code analysis is essential for cybersecurity tasks such as malware detection and vulnerability research. However, traditional deep learning models for binary analysis often suffer from poor transferability and significant information loss due to aggressive code normalization. CLAP (Contrastive Language Assembly Pre-training) addresses these challenges by aligning binary assembly code with natural language explanations through contrastive learning. By leveraging a massive dataset of 195 million code-text pairs, CLAP produces highly transferable representations that excel in zero-shot and few-shot scenarios.

The Challenge of Binary Analysis

Existing models for binary analysis are frequently "brittle," requiring extensive task-specific labeled data and failing to generalize to unseen tasks. Furthermore, to handle the complex vocabulary of assembly, many models replace constants and strings with generic tokens, stripping away vital semantic clues. CLAP overcomes these limitations by using natural language as a semantic anchor, bridging the gap between raw assembly and human-readable intent.

Methodology: The CLAP Framework

The CLAP framework is divided into two primary components: an automated data generation pipeline and a dual-encoder contrastive learning engine.

1. The Dataset Engine

To facilitate large-scale training, the authors developed an automated pipeline to generate millions of assembly-text pairs.

  • Compilation: C/C++ packages from the Ubuntu repository were compiled using various compilers (GCC, Clang) and optimization levels to ensure structural diversity.
  • Data Augmentation: Initial explanations for source code were generated using GPT-3.5. These were then used to fine-tune a "Shadow Model" (based on LLaMA), which generates high-quality natural language descriptions directly from assembly code. This process resulted in a dataset of 195 million pairs.

2. The CLAP Engine

The core of the framework utilizes a dual-encoder architecture:

  • Assembly Encoder (CLAP-ASM): A RoBERTa-based model that employs WordPiece tokenization to retain micro-semantics (like specific constants) and Address Rebasing to preserve the control flow's relative structure.
  • Contrastive Learning: The assembly encoder and a pre-trained text encoder are jointly trained using InfoNCE loss. This pushes the vector representation of assembly code closer to its corresponding natural language explanation in the embedding space.

Experimental Results

CLAP was evaluated across several benchmarks, demonstrating superior performance compared to traditional supervised models.

  • Binary Code Similarity Detection (BCSD): In zero-shot settings on the BinaryCorp-3M dataset, CLAP achieved a Recall@1 of 83.3%, significantly outperforming the previous state-of-the-art supervised model, jTrans (57.1%).
  • Functional Identification: For cryptographic and protocol identification tasks, CLAP's zero-shot performance was competitive with models trained on 100% of task-specific data. When fine-tuned on just 1% of the data, CLAP outperformed baselines trained on the full dataset.
  • Semantic Clustering: Visualizations of the embedding space indicate that CLAP clusters code based on functional intent (e.g., networking vs. encryption) rather than just structural similarity.

Conclusion and Future Work

CLAP demonstrates that natural language supervision can provide a robust semantic foundation for binary code representations. By moving away from aggressive normalization and embracing large-scale contrastive pre-training, CLAP achieves unprecedented transferability. Future work includes expanding the training data to other operating systems and programming languages, as well as exploring CLAP's utility in complex tasks like automated deobfuscation and deep vulnerability discovery.

Summary updated

BibTeX
@inproceedings{wang2024clap,
  author = {Hao Wang and Zeyu Gao and Chao Zhang and Zihan Sha and Mingyang Sun and Yuchen Zhou and Wenyu Zhu and Wenju Sun and Han Qiu and Xi Xiao},
  title = {{CLAP: Learning Transferable Binary Code Representations with Natural Language Supervision}},
  booktitle = {ISSTA},
  year = {2024},
  url = {https://openreview.net/forum?id=4Hu8QgFWt5},
}
Figure