Introduction
Binary code analysis is a critical task in cybersecurity, yet it remains challenging because compilation strips away high-level semantic information such as variable names and data structures. Traditional machine learning approaches often struggle with granularity and normalization. DeepSemantic addresses these issues by applying the BERT (Bidirectional Encoder Representations from Transformers) architecture to binary code, treating machine instructions as a natural language.
Problem Statement: Granularity and Normalization
Existing tools frequently analyze "basic blocks"—small sequences of code without jumps. However, empirical evidence suggests that basic blocks often lack sufficient context for semantic understanding. As shown in Figure 1, approximately 83% of matching blocks contain five or fewer instructions, which is rarely enough to determine a block's actual function.
Furthermore, the "normalization" of code—replacing memory addresses and constants to handle variability—often falls into two extremes: being too vague (losing meaning) or too specific (causing an Out-of-Vocabulary problem).
DeepSemantic Methodology
DeepSemantic introduces a "well-balanced" normalization strategy and shifts the focus to function-level granularity. By treating an entire binary function as a single "sentence," the model utilizes BERT’s self-attention mechanism to capture long-range dependencies between instructions.
The framework operates in two distinct phases, as illustrated in Figure 2:
- Stage I (Pre-training): The model learns general patterns of "binary language" from a massive unlabeled corpus of 1.3 million functions using a Masked Language Model (MLM) objective.
- Stage II (Fine-tuning): The pre-trained model is then specialized for downstream tasks, such as binary similarity (DS-BinSim) or identifying compiler toolchains (DS-Toolchain).
Well-Balanced Normalization
Instead of generic placeholders, DeepSemantic categorizes operands by their semantic role. For instance, library calls are mapped to libc[name], jump targets to jmpdst, and registers are grouped by size (e.g., reg8). This approach preserves the developer's intent while maintaining a manageable vocabulary size.
Experimental Setup
The authors evaluated DeepSemantic using a massive dataset of 1,328 binaries, totaling over 108 million instructions across 1.7 million functions. The dataset included binaries from GNUtils, SPEC2017, OpenSSL, Nginx, and vsftpd, compiled with gcc 5.4 and clang 6.0.1 at optimization levels O0 through O3.
Key Insights
- Zipf’s Law in Code: Analysis confirmed that binary instructions follow Zipf’s Law, validating the use of NLP techniques.
- Contextual Awareness: Unlike Word2vec, which assigns static embeddings, BERT’s positional awareness distinguishes between instructions based on their location (e.g., a
popin a function epilogue vs. a calculation). - Sequence over Structure: While many tools rely on Control Flow Graphs (CFGs), DeepSemantic demonstrates that the instruction sequence itself carries richer, more robust semantic weight across different optimization levels.
Evaluation Results
DeepSemantic achieved significant performance gains over state-of-the-art baselines:
- Binary Similarity: It outperformed DeepBinDiff by 49.84% and SAFE by 15.83% in F1-score, showing particular resilience against cross-optimization transformations (e.g.,
O0vsO3). - Compiler Provenance: The model reached an F1-score of 0.96 for compiler identification and 0.91 for optimization level prediction.
- Efficiency: Inference is highly optimized, with function testing taking approximately 0.12 seconds.
Limitations and Future Work
While highly effective on benign binaries, DeepSemantic has not yet been tested against obfuscated or packed malware. Additionally, the current implementation is specific to the x86_64 architecture. Future research will focus on cross-architecture analysis (e.g., x86 to ARM) by developing shared embedding spaces for different instruction sets.
Summary updated