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

Cross-Language Binary-Source Code Matching with Intermediate Representations

Yi Gui, Yao Wan, Hongyu Zhang, Huifang Huang, Yulei Sui, Guandong Xu, Zhiyuan Shao, Hai Jin

Introduction

Identifying whether a compiled binary matches a specific source code snippet is a fundamental task in cybersecurity, essential for malware detection, reverse engineering, and vulnerability analysis. However, modern software environments are increasingly polyglot. A vulnerability might be identified in a C++ library, but an analyst may need to determine if the same logic exists in a binary compiled from Java, Rust, or Go.

Traditional tools often struggle with this "cross-language" gap because different programming languages possess distinct syntaxes, and their respective compilers generate varied machine code. To address this, researchers have developed XLIR, a deep learning framework designed to match binary code to source code across different programming languages by leveraging a common intermediate representation.

Methodology: The XLIR Pipeline

The core innovation of XLIR lies in its use of LLVM Intermediate Representation (IR) as a semantic "bridge" between disparate source languages and compiled binaries. The pipeline consists of three primary stages:

1. IR Normalization

Instead of comparing source code directly to binary, XLIR translates both into LLVM-IR. Source code is processed using LLVM Clang, while binaries are handled via the RetDec decompiler. LLVM-IR serves as a language-independent middle ground that captures the underlying logic of the code while abstracting away language-specific syntax and hardware-specific details.

Normalization process: Converting source code and binary files into a shared LLVM-IR representation.

2. IR-BERT Pre-training

To effectively process this intermediate code, the authors developed IR-BERT, a Transformer-based model. It was pre-trained on a massive corpus of 48 million LLVM-IR instructions derived from major open-source projects like the Linux kernel and TensorFlow. This phase allows the model to learn the fundamental "grammar" and logical patterns of IR before being applied to specific matching tasks.

3. Cross-Modal Alignment

The final stage involves fine-tuning the model using a triplet loss function. This training objective ensures that the mathematical embeddings of a binary and its corresponding source code are pulled closer together in a shared vector space, while embeddings of unrelated code fragments are pushed apart.

XLIR Model Architecture: (a) Triplet loss training for cross-modal alignment and (b) IR-BERT pre-training on a large IR corpus.

Experimental Evaluation

The researchers evaluated XLIR using several datasets, including a custom-curated collection based on competitive programming problems (AtCoder and Google Code Jam) in C, C++, and Java. This dataset included 32 different object files per source file, accounting for variations in compilers (GCC vs. Clang), optimization levels (-O0 to -O3), and architectures (x86, ARM).

Key Results

XLIR demonstrated a significant performance leap over existing state-of-the-art (SOTA) methods:

  • Cross-Language Matching: When matching Java binaries to C source code, XLIR achieved an F1-score of 0.61, nearly doubling the performance of B2SFinder (0.38).
  • Precision and Recall: In C/C++ binary to Java source matching, the system reached a precision of 0.73 and a recall of 0.59.
  • Single-Language Performance: Even in traditional C++ to C++ matching, XLIR outperformed baselines with an F1-score of 0.85 on the POJ-104 dataset.

Discussion and Future Work

The "Universal Translator" approach of using LLVM-IR proves highly effective because different languages often compile down to similar IR structures to implement the same logic. Furthermore, the Transformer-based architecture provides robustness against compiler optimizations that typically obfuscate binary code.

However, limitations remain. The current pipeline requires code to be compilable and binaries to be de-compilable into LLVM-IR, which may fail for obfuscated or "broken" code. Additionally, while LLVM supports many languages, those without mature LLVM front-ends (like Python) are not yet supported. Future research will aim to improve granularity, moving from file-level matching to function-level or snippet-level identification.

Summary updated

BibTeX
@inproceedings{gui2022cross,
  author = {Yi Gui and Yao Wan and Hongyu Zhang and Huifang Huang and Yulei Sui and Guandong Xu and Zhiyuan Shao and Hai Jin},
  title = {{Cross-Language Binary-Source Code Matching with Intermediate Representations}},
  booktitle = {SANER},
  year = {2022},
  url = {https://openreview.net/forum?id=VcNDZ0yXVO},
}
Figure