TL;DR
This paper introduces GraphBinMatch, a novel graph neural network (GNN) approach for matching binary code to source code, even across different programming languages. By representing code as heterogeneous graphs capturing control, data, and call flows, GraphBinMatch significantly outperforms existing methods, achieving up to a 15% improvement in F1 score.
What Problem Does This Paper Address?
In software engineering, security, and reverse engineering, it's often crucial to determine if a piece of binary code corresponds to a specific source code snippet. This is particularly challenging when the binary and source code are written in different programming languages (cross-language matching). Existing methods often struggle with this cross-language problem, as they are typically designed for matching within a single language or treat code representations too simplistically. The authors aim to bridge this gap by developing a more robust method for cross-language binary-to-source code matching.
Methods
The core of GraphBinMatch is its use of Graph Neural Networks (GNNs). The process involves several key steps:
- Intermediate Representation (IR): Both source code and binary executables are first converted into a language-independent Intermediate Representation (IR), specifically LLVM IR. This is achieved using front-end compilers (like JLang for Java and Clang for C++) and a decompiler (RetDec for binaries).
- Graph Generation: The LLVM IR is then transformed into heterogeneous graphs. These graphs capture three types of program flows: Control Flow, Data Flow, and Call Flow. Nodes in these graphs represent instructions, variables, and constants, while edges represent their relationships. This graph representation is crucial for the GNN to learn structural and semantic information.
- Node Feature Embedding: Node features are generated using the
full_textattribute of the LLVM IR instructions, which provides a more detailed representation than just the instruction type. This detailed information is tokenized and padded to create fixed-length feature vectors. - Graph Similarity Learning: The generated graphs are fed into the GraphBinMatch GNN. This GNN, built upon the SimGNN architecture but modified for heterogeneous graphs, uses specialized heterogeneous convolution layers (GATv2Conv) to process the different types of relationships. An attention mechanism is also employed to weigh the importance of different nodes within a graph. Finally, fully connected layers produce a similarity score between the two input graphs.
Datasets
The paper uses two primary datasets:
- CLCDSA: This dataset, collected from programming competition websites (AtCoder, Google CodeJam), contains source code solutions in multiple languages (C, C++, Java). It's used for cross-language binary-source matching and cross-language source-source matching.
- POJ-104: This dataset comprises C++ solutions from a programming contest. It's used for same-language code matching tasks.
Key Insights and Ideas
- Graphs are Key for Code Semantics: Representing code as heterogeneous graphs that explicitly capture control, data, and call flows is more effective for GNNs than treating code as simple sequences of tokens. This allows the model to better understand code structure and semantics.
- Cross-Language Matching is Harder, but Solvable: The paper demonstrates that while cross-language matching is inherently more challenging (partially due to discrepancies in decompiled LLVM-IR), GraphBinMatch can achieve significant improvements over existing methods.
full_textNode Features Matter: Using the complete LLVM-IR instruction (full_text) as node features, rather than just the instruction type (text), leads to better performance, especially in cross-language tasks, by providing richer information.- Optimization Levels Can Impact Decompilation: Higher compiler optimization levels can lead to more aggressive code transformations, potentially increasing the gap between the original source code and the decompiled binary's LLVM-IR, which can slightly affect matching accuracy.
Key Results
- State-of-the-Art Performance: GraphBinMatch outperforms existing methods like BinPro, B2SFinder, and XLIR on cross-language binary-source matching, achieving an F1 score of 0.79 (up from 0.65 for XLIR).
- Significant Improvements: The paper reports improvements of up to 15% in F1 score compared to state-of-the-art approaches.
- Consistent Single-Language Performance: GraphBinMatch also performs very well on same-language binary-source matching, achieving an F1 score of 0.87, outperforming XLIR (0.85).
- Effective Source-to-Source Matching: The approach also shows strong performance in cross-language source-to-source matching, outperforming a baseline by about 20% in precision, recall, and F1 scores.
- Robustness to Optimization: The model shows consistent performance across different compiler optimization levels, indicating robustness.
Limitations and Future Work
- Decompilation Discrepancies: The paper acknowledges that decompiled LLVM-IR may not always perfectly match source code, especially concerning data types, array shapes, and speculative transformations in control flow. This can lead to false positives, particularly when code fragments have significantly different sizes.
- Template Mechanisms in C++: The use of C++ templates can complicate matching, as compiled template code might not be easily recognized as equivalent to standard library calls in other languages.
- Language Support: The approach relies on compiler front-ends to generate LLVM IR. Extending support to new programming languages requires the availability of such front-ends.
- Future Work: The authors plan to extend GraphBinMatch to more programming languages by incorporating additional compiler front-ends. They also aim to increase the dataset size to further improve prediction accuracy and explore the impact of different token embedding techniques.
Summary updated