Source-linked AI summary

Neural Machine Translation Inspired Binary Code Similarity Comparison beyond Function Pairs

Fei Zuo, Xiaopeng Li, Patrick Young, Lannan Luo, Qiang Zeng, Zhexin Zhang

arXiv:1808.04706v2cs.SEcs.CLcs.CRcs.PL

TL;DR

The paper addresses cross-architecture basic-block semantic comparison and code containment beyond function pairs. It adapts NMT-style embeddings and LSTMs into INNEREYE, which reportedly outperforms existing approaches on basic-block comparison and handles containment case studies effectively.

Abstract

from arXiv · show

Binary code analysis allows analyzing binary code without having access to the corresponding source code. A binary, after disassembly, is expressed in an assembly language. This inspires us to approach binary analysis by leveraging ideas and techniques from Natural Language Processing (NLP), a rich area focused on processing text of various natural languages. We notice that binary code analysis and NLP share a lot of analogical topics, such as semantics extraction, summarization, and classification. This work utilizes these ideas to address two important code similarity comparison problems. (I) Given a pair of basic blocks for different instruction set architectures (ISAs), determining whether their semantics is similar or not; and (II) given a piece of code of interest, determining if it is contained in another piece of assembly code for a different ISA. The solutions to these two problems have many applications, such as cross-architecture vulnerability discovery and code plagiarism detection. We implement a prototype system INNEREYE and perform a comprehensive evaluation. A comparison between our approach and existing approaches to Problem I shows that our system outperforms them in terms of accuracy, efficiency and scalability. And the case studies utilizing the system demonstrate that our solution to Problem II is effective. Moreover, this research showcases how to apply ideas and techniques from NLP to large-scale binary code analysis.

I. INTRODUCTION

The paper applies NLP-inspired neural methods to cross-architecture binary similarity, addressing both basic-block semantic comparison and code containment beyond function pairs.

Motivation

  • Binary analysis is often necessary when source code is unavailable, particularly for vulnerability discovery across diverse hardware architectures.Code reuse can spread one source-level vulnerability across many IoT devices, while obtaining their source code is often unlikely.Source: §I · p. 1

Code Containment

  • The work extends basic-block comparison to cross-architecture containment, targeting code components that may comprise part of a function or multiple functions.This addresses cases where plagiarism or other reused code is not an entire function.Source: §I · pp. 1–2

Research Problems

  • The paper defines Problem I as deciding whether basic blocks from different ISAs have similar semantics, and Problem II as detecting whether code is contained across ISAs.Problem I is treated as a core subtask, whereas Problem II is presented as new.Source: §I · pp. 1–2

Approach

  • The authors map instructions to words and basic blocks to sentences, using an NMT-inspired cross-assembly neural model to learn semantic representations.The model uses embeddings and LSTM-based processing to capture instruction information and dependencies automatically.Source: §I · p. 2

Modeling Assumption

  • The method treats executed function behavior as path-dependent rather than as an arbitrary straight-line instruction sequence.Compiler-scrambled paths can preserve function semantics, motivating path-aware treatment.Source: §I · p. 2

Evaluation

  • INNEREYE-BB is evaluated for accuracy, efficiency, and scalability, while INNEREYE-CC is demonstrated through cross-architecture code-similarity case studies.The authors report large-margin improvements for INNEREYE-BB and successful containment-oriented case studies for INNEREYE-CC.Source: §I · p. 2

II. RELATED WORK

Prior binary-similarity systems largely target mono-architecture analysis or cross-architecture function equivalence, leaving cross-architecture containment beyond function pairs insufficiently addressed.

Mono-architecture Solutions

  • Existing plagiarism and clone-detection methods include string-, token-, tree-, PDG-, and dynamic-birthmark-based approaches, with several relying on source code or a single architecture.These categories include API, system-call, function-call, instruction, and core-value birthmarks.Source: A. Traditional Code Similarity… · p. 3

Cross-architecture Solutions

Research Gap

  • The paper claims to fill the combined gap of binary analysis, different architectures, and code containment, which prior systems do not jointly satisfy.It presents cross-architecture binary similarity comparison beyond function pairs as the target capability.Source: B. Machine Learning-based Code… · p. 3

Problem Scope

  • The paper distinguishes code containment from function equivalence because a queried component may be part of a function or span multiple functions.Function-equivalence search is too limited when stolen code is inserted into other code.Source: §III · pp. 3–4

Proposed Architecture

  • The proposed system examines semantics at basic-block, CFG-path, and code-component layers, storing block embeddings in an LSH database for online search.Multiple path pairs are combined into a component-level similarity score.Source: §III · pp. 3–4

IV. INSTRUCTION EMBEDDING GENERATION

The instruction-embedding stage adapts skip-gram word embeddings to assembly instructions, learning contextual vectors that support neural basic-block representation.

IV. INSTRUCTION EMBEDDING GENERATION

  • An instruction consists of an opcode and zero or more operands, and the paper represents each instruction with an instruction embedding.This transfers the NLP notion of word embeddings to assembly instructions.Source: §IV · p. 4
  • The notation distinguishes functions, basic blocks, matrices, vectors, and individual instructions using capitalization and type-specific formatting.These conventions identify the objects used in the embedding equations.Source: §IV · p. 4

A. Background: Word Embedding

  • Word embeddings represent contextual semantic meaning in a high-dimensional space, placing words with similar contexts near one another.The paper uses this contextual representation as the conceptual basis for instruction embeddings.Source: A. Background: Word Embedding · p. 4
  • Skip-gram trains embeddings from words appearing within a sliding context window around a current word.The paper illustrates a window covering words before and after the current word.Source: A. Background: Word Embedding · pp. 4–5
  • Assembly syntax in the paper follows Intel order: op dst, src(s).Operands are written after the opcode, with the destination preceding the source operands.Source: A. Background: Word Embedding · p. 4
  • The skip-gram softmax uses the current word embedding to predict whether a candidate word occurs in its context.Context words receive a target probability of 1, and non-context words receive 0.Source: A. Background: Word Embedding · p. 5
  • Training over a sequence maximizes a log-likelihood objective with stochastic gradient descent, but direct normalization is computationally expensive.The denominator sums over words in the context, motivating approximations.Source: A. Background: Word Embedding · p. 5
  • The system adopts skip-gram with negative sampling to reduce training cost and obtain meaningful vectors for similar words.The passage also notes that skip-gram training is unsupervised and scalable to very large word streams.Source: A. Background: Word Embedding · p. 5

B. Challenges

Instruction embeddings address two challenges in applying NLP techniques to binary code: instruction streams must represent blocks, and preprocessing must reduce out-of-vocabulary cases.

  • Instruction embedding models must be trained from scratch because reusable natural-language embedding models do not apply directly to instructions.Source: B. Challenges · p. 5
  • Out-of-vocabulary failures are especially challenging because instructions frequently contain constants, offsets, labels, and strings.Source: B. Challenges · p. 5
  • A block-level instruction stream, or BIS, represents a basic block as its ordered list of instructions.Source: C. Building Training Dataset · p. 5
  • The instruction-embedding training process uses BISs generated from functions, with each square in a BIS representing one instruction.Source: C. Building Training Dataset · p. 5, Figure 3 · p. 5
  • Preprocessing replaces numeric constants with 0, strings with <STR>, function names with FOO, and other symbol constants with <TAG>.Source: C. Building Training Dataset · p. 5
  • Applying the same preprocessing before embedding substantially reduces OOV cases, leaving very few during later testing after sufficient training data is collected.Source: C. Building Training Dataset · p. 5

D. Training Instruction Embedding Model

The model learns instruction representations and uses a Siamese LSTM architecture to encode cross-architecture basic blocks, including variable-length sequences, for similarity comparison.

D. Training Instruction Embedding Model

V. BLOCK EMBEDDING GENERATION

  • Simply summing instruction embeddings cannot handle cross-architecture differences because equivalent instructions may have very different embeddings.Source: §V · p. 6

A. Background: LSTM in NLP

  • LSTM is used to encode instruction sequences because it is designed to capture long-term dependencies, while basic blocks usually contain fewer than 500 instructions.Source: A. Background: LSTM in NLP · p. 6

B. Cross-lingual Basic-block Embedding Model Architecture

C. Challenges

Learning block embeddings requires labeled similar and dissimilar pairs, but establishing basic-block ground truth is difficult and model hyperparameters require examination.

  • Basic-block ground truth is challenging because blocks lack names that can directly establish similarity labels.Source: C. Challenges · p. 7
  • NMT hyperparameters cannot be assumed to transfer directly, so their values must be comprehensively examined for this model.Source: C. Challenges · p. 7

D. Building Dataset

The dataset pairs equivalent blocks through shared compiler-generated identifiers and constructs dissimilar examples using same-architecture n-gram similarity thresholds.

VI. PATH/CODE COMPONENT SIMILARITY COMPARISON

INNEREYE addresses cross-architecture code-component containment by combining cross-lingual basic-block embeddings with path-based similarity comparison. It searches candidate target paths and aggregates their similarity into a component score.

  • Cross-architecture containment is harder than function-pair comparison because a critical component may be embedded inside a function.Existing work either targets one architecture or compares complete function pairs.Source: §VI · p. 7, B. Component Similarity Comparison · p. 8

Path Similarity Comparison

  • The method decomposes query code into linearly independent paths and compares each against target-program paths using LCS over semantically equivalent basic blocks.Query paths are generated after unrolling each loop once and applying depth-first search.Source: §VI · p. 7, A. Path Similarity Comparison · p. 8
  • For each query path, the highest LCS-based similarity across target paths becomes its path similarity score.The score uses the longest common subsequence of semantically equivalent basic blocks.Source: A. Path Similarity Comparison · p. 8

Starting-Block Identification

  • Starting-block discovery searches target basic-block embeddings with locality-sensitive hashing and iteratively tests query blocks as possible starts.This addresses the unknown insertion location of the query component.Source: B. Component Similarity Comparison · p. 8

Component Similarity Score

  • The final component similarity score is a path-length-weighted average of the individual path similarity scores.This combines evidence from multiple query paths.Source: B. Component Similarity Comparison · p. 8

Summary

  • Integrating the embedding model with the existing path-comparison approach yields an effective and efficient cross-architecture component-similarity solution.The authors also identify benefits for systems that rely on basic-block similarity.Source: B. Component Similarity Comparison · p. 8

VII. EVALUATION

The evaluation examines INNEREYE across accuracy, efficiency, scalability, preprocessing, embedding quality, and cross-architecture code-component search. It uses cross-architecture basic-block datasets and reports low post-preprocessing OOV rates.

  • INNEREYE is evaluated for accuracy, efficiency, and scalability, including basic-block similarity and cross-architecture code-component search.The evaluation covers Problem I and realistic Problem II applications.Source: §VII · p. 8

Experimental Setup

  • The implementation uses word2vec instruction embeddings and a Keras model with TensorFlow as backend.The path-selection setup requires selected linearly independent paths to cover at least 80% of query basic blocks.Source: A. Experimental Settings · p. 8

Dataset

  • Dataset I contains cross-architecture basic-block pairs labeled with similarity ground truth, compiled from x86-64 and ARM programs at optimization levels O1–O3.The dataset includes 437,104 x86 basic blocks and 393,529 ARM basic blocks.Source: B. Dataset · pp. 8–9

Out-Of-Vocabulary Instructions

D. Qualitative Analysis of Instruction Embeddings

The embedding analysis finds architecture-specific clustering alongside semantic relationships across ISAs. Accuracy experiments show INNEREYE-BB outperforming a manually selected-feature SVM on the reported testing subsets.

D. Qualitative Analysis of Instruction Embeddings

E. Accuracy of INNEREYE-BB

  • The ROC curves for the four testing datasets remain close to the left and top borders, indicating good accuracy for the base models.The evaluations use Dataset I and disjoint training, validation, and testing basic blocks.Source: E. Accuracy of INNEREYE-BB · p. 10, 2) Results · p. 10
  • INNEREYE-BB also reports ROC results for large blocks with more than 20 instructions and small blocks with fewer than 5 instructions.The O3 subsets contain 221 large-block pairs and 2,409 small-block pairs.Source: E. Accuracy of INNEREYE-BB · p. 10
  • INNEREYE-BB achieves higher AUC values than the SVM classifier using six manually selected block features.The feature-based representation loses instruction semantics and dependency information.Source: 3) Comparison with Manually Selected… · pp. 10–11
  • Examples show INNEREYE-BB correctly classifying similar and dissimilar block pairs that the statistical feature-based SVM misclassifies.The cited examples are presented in Tables II and III.Source: 3) Comparison with Manually Selected… · p. 11

F. Hyperparameter Selection for INNEREYE-BB

Hyperparameter experiments assess training duration, embedding dimensions, network depth, and recurrent-unit type. The reported choices balance accuracy against computational cost.

Number of Epochs

  • AUC stabilizes and loss becomes nearly stable after epoch 20, indicating rapid attainment of good performance.The model was evaluated every 10 epochs during 200-epoch training.Source: 1) Number of Epochs · p. 11

Embedding Dimensions

  • Instruction embedding dimensions above 100 have similar AUC values, so dimension 100 is selected as a computational trade-off.Higher dimensions increase training time.Source: 2) Embedding Dimensions · p. 11
  • Block embedding dimensions of 10, 30, and 50 perform similarly, so dimension 50 is selected as a computational trade-off.Higher dimensions increase computational costs.Source: 2) Embedding Dimensions · p. 11

Network Depth

  • Two- and three-layer LSTMs outperform a single-layer network, while their AUC values are close to each other.The authors choose network depth 2 because additional layers increase complexity without significant performance gains.Source: 3) Network Depth · pp. 11–12

Network Hidden Unit Types

G. Efficiency of INNEREYE-BB

INNEREYE-BB achieves practical training and testing efficiency, substantially outperforming symbolic execution in block-comparison speed while supporting effective code-component searches.

Training Time

  • Training time grows linearly with epochs and training samples, while more complex LSTM networks require more time per epoch.The study reports linear dependence on epochs and corpus or sample size, with deeper LSTMs taking longer per epoch.Source: 1) Training Time · p. 13
  • Five and a half hours trains four two-layer models for 20 epochs, whereas single-layer models take about 40 minutes each and retain good performance.The four-model estimate uses the reported per-epoch times and 20 training epochs.Source: 1) Training Time · p. 13

Testing Time

  • Network depth is the major contributor to testing computation time, while embedding dimension is also varied in the evaluation.Figure 14 examines testing time across network layers and block-embedding dimensions.Source: 2) Testing Time · p. 13, Figure 14 · p. 13
  • 3700x to 140000x faster than symbolic execution, with an average speedup as high as 8000x, INNEREYE-BB markedly reduces block-comparison time.The comparison used 1,000 randomly selected block pairs.Source: 2) Testing Time · p. 13

Code Component Similarity Comparison

VIII. DISCUSSION

The discussion highlights INNEREYE’s broader contribution to binary analysis while identifying compiler diversity and obfuscation as unevaluated boundaries.

Limitations

  • The model was trained only on LLVM-compiled binaries, so performance on binaries produced by diverse compilers remains unevaluated.The authors state that compiler agnosticism is expected but reserved verification for future work.Source: §VIII · p. 14
  • The study evaluated architectural and compilation-setting variation but did not evaluate code obfuscation at the basic-block level.The authors identify obfuscation handling without expensive symbolic execution as future work.Source: §VIII · p. 14

Broader Impact

  • The block embedding model can benefit prior systems that rely on basic-block comparison or representation by providing precise and efficient block information.The discussion explicitly connects the model to several prior systems.Source: §VIII · p. 14

Contributions

  • INNEREYE-BB uses instruction word embeddings and LSTM encoding to support cross-architecture basic-block comparison without manually selected features.INNEREYE-CC extends this capability to cross-architecture code containment.Source: §IX · p. 14
Loading 1808.04706v2…