Skip to main content
QUICK REVIEW

[Paper Review] Semantic-aware Binary Code Representation with BERT

Hyungjoon Koo, Soyeon Park|arXiv (Cornell University)|Jun 10, 2021
Software Engineering ResearchComputer Science55 references11 citations
TL;DR

This paper proposes DeepSemantic, a BERT-based model for learning semantic-aware binary code representations by applying well-balanced instruction normalization to preserve contextual information while minimizing out-of-vocabulary issues. It achieves state-of-the-art performance in binary similarity comparison, outperforming DeepBinDiff and SAFE by 49.84% and 15.83% respectively on average, and demonstrates strong results in compiler provenance prediction through fine-tuning a pre-trained BERT model on binary functions.

ABSTRACT

A wide range of binary analysis applications, such as bug discovery, malware analysis and code clone detection, require recovery of contextual meanings on a binary code. Recently, binary analysis techniques based on machine learning have been proposed to automatically reconstruct the code representation of a binary instead of manually crafting specifics of the analysis algorithm. However, the existing approaches utilizing machine learning are still specialized to solve one domain of problems, rendering recreation of models for different types of binary analysis. In this paper, we propose DeepSemantic utilizing BERT in producing the semantic-aware code representation of a binary code. To this end, we introduce well-balanced instruction normalization that holds rich information for each of instructions yet minimizing an out-of-vocabulary (OOV) problem. DeepSemantic has been carefully designed based on our study with large swaths of binaries. Besides, DeepSemantic leverages the essence of the BERT architecture into re-purposing a pre-trained generic model that is readily available as a one-time processing, followed by quickly applying specific downstream tasks with a fine-tuning process. We demonstrate DeepSemantic with two downstream tasks, namely, binary similarity comparison and compiler provenance (i.e., compiler and optimization level) prediction. Our experimental results show that the binary similarity model outperforms two state-of-the-art binary similarity tools, DeepBinDiff and SAFE, 49.84% and 15.83% on average, respectively.

Motivation & Objective

  • To address the challenge of recovering high-level semantic meaning from binary code, which lacks source-level structure and is heavily transformed during compilation.
  • To develop a unified, transferable representation model for binary analysis that generalizes across multiple downstream tasks without retraining from scratch.
  • To minimize the out-of-vocabulary (OOV) problem in binary code representation while preserving rich semantic and syntactic information.
  • To enable effective binary similarity detection and toolchain provenance prediction using a single, pre-trained BERT-based architecture.

Proposed method

  • Proposes a well-balanced instruction normalization technique that maps low-level machine instructions into a semantically meaningful, vocabulary-friendly representation suitable for BERT.
  • Adapts the BERT architecture to process binary code by treating each function as a sequence of normalized instructions, enabling contextual representation learning.
  • Leverages a pre-trained BERT model for generic code representation, followed by fine-tuning on specific downstream tasks such as binary similarity and compiler provenance.
  • Uses a sequence-level classification head for downstream tasks, enabling end-to-end training with gradient-based optimization.
  • Applies self-attention mechanisms to capture long-range dependencies and structural context across instructions within a function.
  • Employs a controlled vocabulary mapping that balances instruction detail and OOV reduction, based on empirical analysis of 108 million instructions and 1.7 million functions.

Experimental results

Research questions

  • RQ1Can a BERT-based model learn meaningful, semantic-aware representations of binary code when fine-tuned on function-level sequences?
  • RQ2How does instruction normalization affect the quality of learned representations and the OOV rate in binary code modeling?
  • RQ3To what extent can a single pre-trained BERT model generalize across diverse binary analysis tasks such as similarity detection and compiler provenance prediction?
  • RQ4How does the proposed method compare to state-of-the-art tools like DeepBinDiff and SAFE in binary similarity tasks?

Key findings

  • The binary similarity model, DS-BinSim, outperforms DeepBinDiff by 49.84% on average and SAFE by 15.83% on average in similarity detection tasks.
  • The model achieves strong performance in compiler provenance prediction, demonstrating the robustness of learned representations for toolchain inference.
  • The majority of matching basic block pairs (83%) in existing tools consist of five instructions or fewer, indicating that block-level granularity is insufficient for semantic understanding.
  • Function-level representation captures more contextual information than basic block-level analysis, as evidenced by the high mismatch rate (14.1%) in block-level matching with identical instruction sequences from different functions.
  • The instruction distribution in binaries follows Zipf’s law, suggesting linguistic-like structure, which supports the use of NLP-inspired models like BERT.
  • Despite the lack of access to the source code of Order matters, a comparable BERT-based approach, DeepSemantic shows superior performance in binary similarity, indicating its effectiveness and generalization capability.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.