Skip to main content

Python bindings for Binwalk v3

Project description

pybinwalk

Python bindings for Binwalk v3, built with PyO3 and maturin.

Provides direct access to binwalk's signature scanning and extraction from Python. Also exposes a C API for use from other languages.

Requirements

  • Python >= 3.8
  • Rust toolchain (for building from source)

Installation

pip install pybinwalk

To build from source:

pip install maturin
maturin build --release
pip install target/wheels/pybinwalk-*.whl

Wheels

Prebuilt wheels are published via GitHub Actions for:

  • macOS: universal2 (arm64 + x86_64)
  • Windows: x86_64
  • Linux: manylinux (x86_64)

If a wheel isn’t available for your Python/platform, pip will build from source (requires Rust).

Usage

Scan bytes in memory

import pybinwalk

bw = pybinwalk.Binwalk()
data = open("firmware.bin", "rb").read()

for result in bw.scan_bytes(data):
    print(f"0x{result.offset:08X}  {result.name}  {result.description}")

Scan a file from disk

bw = pybinwalk.Binwalk()

for result in bw.scan_path("/path/to/firmware.bin"):
    print(f"0x{result.offset:08X}  {result.name}  {result.description}")

Configure with filters

bw = pybinwalk.Binwalk.configure(
    include=["gzip", "squashfs"],
    exclude=["jpeg"],
    full_search=False,
)

results = bw.scan_path("firmware.bin")

Extract

bw = pybinwalk.Binwalk.configure(
    target_file_name="firmware.bin",
    output_directory="./extracted",
)

analysis = bw.analyze_path(bw.base_target_file, do_extraction=True)

for sig in analysis.file_map:
    print(f"0x{sig.offset:08X}  {sig.name}")

for sig_id, extraction in analysis.extractions.items():
    print(f"{sig_id}: success={extraction.success}, dir={extraction.output_directory}")

Version

print(pybinwalk.version())

API reference

Binwalk

Method Description
Binwalk() Create an instance with default settings.
Binwalk.configure(...) Create an instance with custom options.
scan_bytes(data: bytes) Scan in-memory data. Returns list[SignatureResult].
scan_path(file_path: str) Scan a file on disk. Returns list[SignatureResult].
extract_bytes(data, file_path, file_map) Extract from in-memory data using a prior scan result. Returns dict[str, ExtractionResult].
analyze_path(target_file, do_extraction) Scan and optionally extract a file. Returns AnalysisResults.

Properties: signature_count, base_target_file, base_output_directory.

Binwalk.configure() parameters

Parameter Type Default Description
target_file_name str or None None Path to target file (required for extraction).
output_directory str or None None Directory for extracted files.
include list[str] or None None Only scan for these signature types.
exclude list[str] or None None Skip these signature types.
full_search bool False Search all offsets instead of optimized locations.

SignatureResult

Properties: offset, id, size, name, confidence, description, always_display, extraction_declined, preferred_extractor.

ExtractionResult

Properties: size, success, extractor, do_not_recurse, output_directory.

AnalysisResults

Properties: file_path, file_map (list of SignatureResult), extractions (dict mapping signature id to ExtractionResult).

C API

When built without the python feature (cargo build --release --no-default-features), the library exposes a C-compatible API:

Function Description
bw_scan(data, len) Scan a buffer. Returns JSON string.
bw_scan_with_options(data, len, options_json) Scan with filter options. Returns JSON string.
bw_version() Get version info. Returns JSON string.
bw_list_signatures() List available signatures. Returns JSON string.
bw_free(ptr) Free a string returned by any of the above.

All C API functions return a *mut c_char pointer to a JSON string. The caller must free it with bw_free().

License

MIT

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

pybinwalk-0.0.3.tar.gz (22.0 kB view details)

Uploaded Source

Built Distributions

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

pybinwalk-0.0.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pybinwalk-0.0.3-cp38-abi3-win_amd64.whl (877.4 kB view details)

Uploaded CPython 3.8+Windows x86-64

pybinwalk-0.0.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

pybinwalk-0.0.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (1.8 MB view details)

Uploaded CPython 3.8+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file pybinwalk-0.0.3.tar.gz.

File metadata

  • Download URL: pybinwalk-0.0.3.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pybinwalk-0.0.3.tar.gz
Algorithm Hash digest
SHA256 60ae1e619546c04cc89c9c8cfb868c62689d04a19713d693c1217bd31c7dada6
MD5 1d58578f9bfe2d04055d9e3b8cf057c9
BLAKE2b-256 7bc1db562769805b6a2ecf9f010d26f3bc7a7a684be91c2e25f43f01bc0920d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybinwalk-0.0.3.tar.gz:

Publisher: ci.yml on kevinmuoz/pybinwalk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pybinwalk-0.0.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pybinwalk-0.0.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dcfd8f10e5ae902db5afba5a4eb877c538cdbb590e76200d1eeab3c13d83849a
MD5 af18930e69739fe838729efef885593d
BLAKE2b-256 d202927fc47135d584f841afa5ebb9a8b3f61d084d061cbdef3965e089ab1586

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybinwalk-0.0.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on kevinmuoz/pybinwalk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pybinwalk-0.0.3-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pybinwalk-0.0.3-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 877.4 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pybinwalk-0.0.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3ef03485c3bfb95178c1f82d47f09d2d4485dfb7eb2ffc67e0a0baf020595b03
MD5 10744189ef50ef6bd044e57313b7e474
BLAKE2b-256 21f6747df92cd7216e7fd3581ddd845eec623b1927308f92a47162e3c1fcaf92

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybinwalk-0.0.3-cp38-abi3-win_amd64.whl:

Publisher: ci.yml on kevinmuoz/pybinwalk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pybinwalk-0.0.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pybinwalk-0.0.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bae2e24f5cca1183a34d5ebc24391e6069e6eca3e123d22a4f4cf633dabad4ab
MD5 19eadf732c0da1facaf56673201a6759
BLAKE2b-256 44bb9b959ae74878e4439518b579a5a6fac0394a1fc75ac0412ca7590e4a905c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybinwalk-0.0.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: ci.yml on kevinmuoz/pybinwalk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pybinwalk-0.0.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for pybinwalk-0.0.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 8559340606bc9c2b8af924c9376e0e0d1a20112583601d9c8b944a303be438c0
MD5 b5ff3307bc1805699bf8f5bc4e18ea30
BLAKE2b-256 6702f6acf9a4e52641da4cebf4949319b90574c1914fcbc4a821900b5d6095be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybinwalk-0.0.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: ci.yml on kevinmuoz/pybinwalk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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