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

Trex: Learning Execution Semantics from Micro-Traces for Binary Similarity

Kexin Pei, Zhou Xuan, Junfeng Yang, Suman Jana, Baishakhi RayarXiv 2020

Abstract

Identifying semantically similar binary functions across disparate architectures and compiler settings is a fundamental challenge in security research. Traditional methods often rely on syntax or control-flow graphs, which are easily disrupted by optimizations or obfuscation. We present TREX (TRansfer-learning EXecution semantics), a framework that learns the functional behavior of code by pretraining on "micro-traces"—short sequences of instructions paired with their runtime register values. TREX achieves state-of-the-art accuracy in cross-architecture and cross-optimization matching while operating up to 8x faster than existing models.

Introduction: The Challenge of Binary Similarity

Binary similarity analysis—determining if two compiled functions perform the same task—is essential for vulnerability discovery, malware lineage tracking, and digital forensics. However, the same source code can result in vastly different binaries due to variations in Instruction Set Architectures (ISA), compiler optimization levels (e.g., -O0 vs -O3), and intentional obfuscation. Existing machine learning approaches often treat code as text or graphs, failing to capture the underlying "execution semantics"—the actual behavior of the code when run. If the syntax changes, these models often fail to recognize the functional equivalence.

The TREX Framework

TREX addresses this by teaching a model the rules of execution through a three-phase transfer learning approach.

The three-phase TREX framework: Pretraining on micro-traces, Finetuning for function similarity, and Inference for matching.

1. Micro-Execution and Pretraining

To capture execution semantics, TREX utilizes "micro-execution," where functions are run with randomized initial states (registers and memory). This generates micro-traces: sequences of instructions paired with the resulting register values. During pretraining, the model performs Masked Language Modeling (MLM), predicting hidden opcodes or values within a trace. To succeed, the model must learn the "execution semantics"—the rules of how instructions transform data.

2. Hierarchical Transformer Architecture

TREX employs a specialized Transformer architecture designed for code. A key innovation is the treatment of numerical values. Instead of normalizing or discarding them as "dummy tokens," TREX uses a bi-LSTM to encode raw 8-byte values into embeddings. This allows the model to understand mathematical relationships and memory offsets directly from the data.

The TREX model architecture, featuring a Transformer with a bi-LSTM for encoding micro-trace values.

3. Finetuning and Inference

After pretraining, the model is finetuned on pairs of semantically similar functions. Crucially, while the model learns from dynamic execution data, it only requires static code during the finetuning and inference phases. This allows TREX to retain "execution intuition" without the overhead of running code during a search, making it practical for large-scale analysis.

Evaluation and Results

TREX was evaluated on a massive scale, using over 1.4 million functions across four architectures (x86, x64, ARM, MIPS) and various optimization and obfuscation levels.

  • Superior Accuracy: TREX outperformed state-of-the-art systems like SAFE and Gemini, showing improvements of 7.8% in cross-architecture matching, 7.2% in cross-optimization, and 14.3% in cross-obfuscation scenarios.
  • Performance Gains: The Transformer-based architecture enables high parallelism, making TREX up to 8x faster than RNN or GNN-based alternatives during embedding generation.
  • Real-World Impact: In a case study of 180 firmware images, TREX successfully identified 16 previously undisclosed vulnerabilities (CVEs) in the latest versions of commercial products from vendors like TP-Link and Netgear.

Conclusion

By shifting the focus from code syntax to execution semantics, TREX provides a robust and efficient solution for binary similarity analysis. Its ability to "read" code with an understanding of its runtime behavior allows it to overcome the traditional barriers of architecture shifts and compiler optimizations, providing a powerful tool for modern security researchers.

Summary updated

BibTeX
@misc{pei2020trex,
  author = {Kexin Pei and Zhou Xuan and Junfeng Yang and Suman Jana and Baishakhi Ray},
  title = {{Trex: Learning Execution Semantics from Micro-Traces for Binary Similarity}},
  year = {2020},
  eprint = {2012.08680},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2012.08680},
}
Figure