Skip to main content

Python wrapper to manipulate bindiff files

Project description

Python Bindiff

python-bindiff is a python module aiming to give a friendly interface to launch and manipulate bindiff between two binary iles.

How it works ?

The module relies on python-binexport to extract programs .BinExport and then directly interact with the binary differ (of zynamics) to perform the diff. The generated diff file is then correlated with the two binaries to be able to navigate the changes.

Installation

The python module requires Bindiff. Thus first refers to Zynamics installation directives.

Then the python module can be installed with:

pip install python-bindiff

The python module needs to execute the differ executable. As such it should be available:

  • either in the path
  • or via the BINDIFF_PATH environment variable

Usage as a python module

The simplest way to get the programs, already exported with BinExport, diffed, is:

from bindiff import BinDiff

diff = BinDiff.from_binary_files("sample1.exe", "sample2.exe", "out.BinDiff")

# or performing the diff on BinExport files
diff = BinDiff.from_binexport_files("sample1.BinExport", "sample2.BinExport", "out.BinDiff")

To load the diffing results of an existing diff.BinDiff file, do:

from bindiff import BinDiff

diff = BinDiff("sample1.BinExport", "sample2.BinExport", "diff.BinDiff")
print(diff.similarity, diff.confidence)
# do whatever you want with diff.primary, diff.secondary which are the
# two Program object

But programs can be instanciated separately:

from binexport import ProgramBinExport
from bindiff import BinDiff
p1 = ProgramBinExport("sample1.BinExport")
p2 = ProgramBinExport("sample2.BinExport")

diff = BinDiff(p1, p2, "diff.BinDiff")

Note that all the diff data are embedded inside program objects thus after instanciating BinDiff those p1 and p2 are modified.

From the API it is also possible to directly perform the BinExport extraction and the diffing:

Usage as a command line

The bindiffer command line allows to generate a diff file from the two .BinExport files or directly from the binaries (thanks to python-binexport and idascript). The help message is the following:

Usage: bindiffer [OPTIONS] <primary file|dir> <secondary file|dir>

  bindiffer is a very simple utility to diff two binary files using BinDiff in command line. The two input files can be either binary files (in which
  case IDA is used) or directly .BinExport file (solely BinDiff is used). It also accept two directories two diff each files based on their names 

Options:
  -d, --disassembler [ida|ghidra|binary_ninja]
                                  Disassembler to use
  --disass-path TEXT              Path of the disassembler (dir or binary for IDA, dir for Ghidra)(if not provided search $PATH or environment
                                  variable IDA_PATH, GHIDRA_PATH)
  -t, --threads INTEGER           Thread number to use
  --timeout INTEGER               Per-file export timeout in seconds (if not set, no timeout is enforced)
  -b, --bindiff-path PATH         BinDiff differ directory
  --stop-on-error                 Stop on error
  -o, --output PATH               Output BinDiff file, or directory for batch
  --override                      Override existing output files (includes .BinExport files)
  -bw, --bindiff-workspace PATH   Create a BinDiff Workspace database
  -h, --help                      Show this message and exit.

To work bindiff differ binary should be in the $PATH, given via the BINDIFF_PATH environment variable or with the -b command option. Similarly when diff binaries directly the ida64 binary should be available in the $PATH, given with the IDA_PATH environment variable or via the -i command option.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_bindiff-0.4.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_bindiff-0.4.0-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file python_bindiff-0.4.0.tar.gz.

File metadata

  • Download URL: python_bindiff-0.4.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_bindiff-0.4.0.tar.gz
Algorithm Hash digest
SHA256 0da57ef4e74d1e109b95bb2f616f6a5aff98ffc83f40b633177908ecd6959373
MD5 b65fc182f0fc14aae4168ce946aefed7
BLAKE2b-256 f4902f465fa74cc2f0e9e0183aae25ae25686ab1099f4f4640be13a24a443bc6

See more details on using hashes here.

File details

Details for the file python_bindiff-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: python_bindiff-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_bindiff-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de7c8d541fef203b9353f3111e9e9e76f9105d720de5a2eb22d5b4578cbe8487
MD5 54dbf3a08fc59afebd8066fbc07dcf19
BLAKE2b-256 c7bd642e351c7c5b34101204a95a57840ee533a64e3160db14e53f7f01fe5d53

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page