BinDiff Documentation

repository·main·Indexed 23 days ago

https://github.com/google/bindiff

An open-source binary comparison tool used by vulnerability researchers to identify differences and similarities in disassembled code across binary versions. It features support for IDA Pro, Binary Ninja, and Ghidra, and utilizes a matching strategy based on abstract executable structures, flow graphs, and call graphs. The documentation covers installation, building from source using CMake and Ninja, configuring function and basic block matching algorithms, and interpreting confidence and similarity metrics.

Tokens
2.3K
Snippets
4
Records
15
Agent score
84%

What's inside BinDiff

  1. Understand BinDiff matching strategy

    main

    BinDiff matches functions by analyzing the abstract structure of an executable rather than concrete assembly instructions.

    The process follows these steps:

    1. Signature Generation: Every function receives a signature based on its normalized flow graph (number of basic blocks, edges, and calls to sub-functions).
    2. Initial Global Matching: BinDiff identifies functions that share unique characteristics across both binaries.
    3. Drill Down: If an attribute is ambiguous (appears multiple times), BinDiff narrows the search by only considering equivalent sets of functions for that attribute.
    4. Call Graph Expansion: Once a match is found, BinDiff examines the parents (callers) and children (callees) of that match to find new matches.
    5. Basic Block Matching: Finally, BinDiff performs matching at the basic block level for newly matched functions.
  2. Quickstart: Install BinDiff

    main

    To start using BinDiff immediately without building from source, download the prebuilt installation packages from the official releases page.

    Note: BinDiff requires a separate disassembler to function. It includes out-of-the-box support for:

    • IDA Pro
    • Binary Ninja
    • Ghidra
  3. Use BinDiff with Ghidra and Binary Ninja

    main

    BinDiff 7 includes beta support for Ghidra and Binary Ninja:

    • Ghidra: The BinExport Ghidra extension is included in the package. You must manually export files from Ghidra to be able to bindiff them.
    • Binary Ninja: A BinExport plugin for Binary Ninja is included (beta). You can use the third-party BD Viewer or export files manually to bindiff them.
  4. Build BinDiff native code from source

    main

    BinDiff uses CMake and Ninja to build its native C++ components.

    Prerequisites

    • BinExport 12: The companion plugin (required).
    • Boost: 1.83.0 or higher.
    • CMake: 3.14 or higher.
    • Ninja: For build execution.
    • Compiler:
      • Linux/macOS: GCC 15 or a recent Clang.
      • Windows: Visual Studio 2022 compiler and the Windows 11 SDK.
    • Git: 1.8 or higher.

    Build Steps (Linux Example)

    1. Configure and generate build files:
    cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
    1. Build and run tests:
    cmake --build build --config Release
    (cd build; ctest --build-config Release --output-on-failure)
    1. Install:
    cmake --install build --config Release
    cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
    cmake --build build --config Release
    (cd build; ctest --build-config Release --output-on-failure)
    cmake --install build --config Release
  5. Build BinDiff without IDA Pro support

    main

    If you do not have an IDA Pro license or wish to exclude IDA integration from your build, use the -DBINEXPORT_ENABLE_IDAPRO=OFF flag during the CMake configuration step.

    cmake -S . -B build/out -G Ninja -DCMAKE_BUILD_TYPE=Release \
      -DBINEXPORT_ENABLE_IDAPRO=OFF
  6. Build the BinDiff Java GUI

    main

    The Java-based visual user interface requires Gradle 6.x, Java 11 LTS, and the commercial yFiles graph visualization library (specifically the 2.x branch).

    Setup

    1. Install Gradle 6.x.
    2. Set the YFILES_DIR environment variable to the directory containing y.jar and ysvg.jar.

    Build Commands

    Windows:

    set YFILES_DIR=<path\to\yfiles_2.17>
    cd java
    gradle shadowJar

    Linux or macOS:

    export YFILES_DIR=<path/to/yfiles_2.17>
    cd java
    gradle shadowJar

    Running the GUI

    After building, the self-contained artifact bindiff-ui-all.jar is located in java/ui/build/libs/. Run it using:

    java -jar bindiff-ui-all.jar
  7. Overview of BinDiff

    main

    BinDiff is a binary comparison tool designed to identify differences and similarities in disassembled code. It is primarily used for:

    • Identifying and isolating vulnerability fixes in vendor-supplied patches.
    • Analyzing multiple versions of the same binary.
    • Transferring analysis results between binaries to avoid duplicate work (e.g., in malware analysis).
    • Retaining knowledge across teams of binary analysts by standardizing analysis results.
  8. Use BinDiff with Ghidra

    main

    BinDiff provides an experimental extension for the Ghidra disassembler. This extension is open source and allows for BinDiff functionality within the Ghidra environment, similar to the IDA Pro plugin.

    To build and use the Ghidra extension, you must access the source code and specific instructions located in the binexport repository on GitHub.

    https://github.com/google/binexport/tree/main/java
  9. Configure Function Matching algorithms

    main

    Function matching algorithms can be applied canonically per function or per edge. Edge matching (matching edges if source and target function attributes match) provides stronger matches but can be significantly slower for large call graphs. If you encounter performance issues, disable edge-matching-based algorithms.

    Function Matching Algorithms

    AlgorithmMatch QualityPerformance
    Hash matchingvery goodvery good
    Name hash matchingvery goodvery good
    Edges flow graph MD indexvery goodmedium
    Edges call graph MD indexgoodmedium
    MD index matching (flow graph MD index, top-down/bottom-up)goodvery good
    Prime signature matchinggoodvery good
    MD index matching (call graph MD index, top-down/bottom-up)goodvery good
    Edges proximity MD indexmediumpoor
    Relaxed MD index matchingmediummedium
    Address sequencepoorvery good
    String referencesmediumvery good
    Loop count matchingpoorvery good
    Call sequence matching (exact/topology/sequence)very poorgood
  10. Interpret BinDiff Confidence and Similarity values

    main

    BinDiff provides two primary metrics to evaluate the quality of a match: Confidence and Similarity.

    Confidence

    Confidence represents the average algorithm confidence (match quality) weighted by a sigmoid squashing function. It indicates how trustworthy the match is based on the strength of the underlying algorithms used. A high similarity score is not considered reliable if the confidence value is low.

    Function Similarity

    Function similarity is a weighted sum of the following factors, which is ultimately multiplied by the Confidence value:

    • ~50%: Difference in flow graph MD index
    • ~25%: Quota of matched flow graph edges to total edges
    • ~15%: Quota of matched basic blocks to total basic blocks
    • ~10%: Quota of matched instructions to total instructions

    Binary Similarity

    Binary similarity measures how much two binaries resemble each other. This value is also multiplied by the Confidence value. To prevent artificial inflation from shared runtime libraries, only non-library functions are included in these counts:

    • ~35%: Quota of matched flow graph edges to total edges
    • ~25%: Quota of matched basic blocks to total basic blocks
    • ~20%: Difference in call graph MD index
    • ~10%: Quota of matched functions to total functions
    • ~10%: Quota of matched instructions to total instructions