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

CodeCMR: Cross-Modal Retrieval For Function-Level Binary Source Code Matching

Zeping Yu, Wenxin Zheng, Jiaqi Wang, Qiyi Tang, Sen Nie, Shi WuNeurIPS 2020

Introduction: The Semantic Gap in Code Matching

In computer security, matching compiled binary code back to its original source code is a fundamental challenge, often considered a "holy grail" for reverse engineering and vulnerability research. The primary obstacle is the "semantic gap." When source code is compiled, human-readable structures, variable names, and logic are transformed into raw assembly instructions, often heavily rearranged by compiler optimizations.

Previous attempts to bridge this gap relied heavily on "literals"—specific strings or integers that survive the compilation process. However, at the function level, these literals are often too sparse to be reliable. A single function might contain no strings and only a few common integers (like 0 or 1), making traditional literal-based matching algorithms highly inaccurate.

Source vs. Binary Code Features

To address this, researchers introduced CodeCMR, a novel end-to-end framework that treats function-level code matching as a cross-modal retrieval task—conceptually similar to matching images with text captions.

Methodology: The CodeCMR Framework

CodeCMR maps both source code and binary code into a shared "embedding space" where semantically similar functions are positioned close together. The framework utilizes specialized encoders for different features of the code.

Overall CodeCMR Architecture
  1. Source Code Encoder: Instead of relying on complex syntax tree parsers, CodeCMR employs a Deep Pyramid Convolutional Neural Network (DPCNN) on raw character-level sequences. This approach makes the model robust to varying coding styles and significantly faster than traditional parsing methods.
  2. Binary Code Encoder: The compiled binary code is represented as a Control Flow Graph (CFG). The framework uses a Graph Neural Network (specifically, a Gated Graph Neural Network) combined with a Hierarchical Binary Model (HBMP) to generate embeddings that capture the structural logic of the assembly instructions.
  3. Literal Encoders: To ensure valuable "easy" clues aren't lost, specialized LSTM-based models process strings and integers. The Integer-LSTM is particularly notable for accounting for how integers might shift during compilation (e.g., a condition like i < 6 transforming into i <= 5).
  4. Norm Weighted Sampling: Training these models relies on "triplet loss"—pulling matching pairs closer while pushing non-matching (negative) samples away. Because standard sampling often selects "easy" negatives that don't improve the model, the authors introduced a scaling hyperparameter to increase the probability of selecting harder, more informative negative samples.

Datasets and Evaluation

The researchers evaluated CodeCMR on two large-scale datasets created for this study, each containing 30,000 training pairs and 10,000 testing pairs:

  • gcc-x64-O0: Source code compiled with GCC for the x86 architecture with no optimizations.
  • clang-arm-O3: Source code compiled with Clang for the ARM architecture with high optimizations (representing a highly challenging scenario for binary matching).

Key Results and Insights

CodeCMR significantly outperformed existing state-of-the-art tools like BinPro and B2SFinder.

  • High Accuracy: On the gcc-x64-O0 dataset, CodeCMR achieved a Recall@1 of 90.2% and a Recall@10 of 98.3%. By comparison, traditional tools like BinPro only managed a 38.6% Recall@1.
  • Cross-Architecture Robustness: Even on the much more difficult clang-arm-O3 dataset, the model maintained an impressive Recall@1 of 87.3%.
  • Structure over Literals: A key insight from the ablation studies is that at the function level, the structure of the code (its semantics) provides a much stronger signal than its literals. Semantic features alone achieved roughly 80% accuracy, whereas relying solely on literals yielded less than 45%. The combination of DPCNN (source) and HBMP+GNN (binary) did the heavy lifting, with literal LSTMs providing the final polish to surpass 90%.
  • The Power of Negative Sampling: The implementation of Norm Weighted Sampling was crucial. By carefully selecting which incorrect answers to expose the model to during training, the researchers improved the Recall@1 score by approximately 8%.

Limitations and Future Directions

While highly accurate, training and running deep neural networks like CodeCMR is computationally more resource-intensive than traditional literal-matching algorithms. Furthermore, the current research does not deeply explore how the model handles intentionally obfuscated code designed by malware authors.

Future work may extend this framework to include cross-lingual pre-training (leveraging models like BERT to further bridge the semantic gap) or adapt the architecture as a foundational step for automated decompilation, potentially generating source code directly from raw binaries.

Summary updated

BibTeX
@inproceedings{yu2020codecmr,
  author = {Zeping Yu and Wenxin Zheng and Jiaqi Wang and Qiyi Tang and Sen Nie and Shi Wu},
  title = {{CodeCMR: Cross-Modal Retrieval For Function-Level Binary Source Code Matching}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2020},
}
Figure