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.
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.
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