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

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.2.tar.gz (21.1 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.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

pybinwalk-0.0.2-cp38-abi3-win_amd64.whl (851.0 kB view details)

Uploaded CPython 3.8+Windows x86-64

pybinwalk-0.0.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

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

pybinwalk-0.0.2-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.2.tar.gz.

File metadata

  • Download URL: pybinwalk-0.0.2.tar.gz
  • Upload date:
  • Size: 21.1 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.2.tar.gz
Algorithm Hash digest
SHA256 811ac959263edc6a8e188281023d7dab45bbe3fe1104f8679a18bc74aa773402
MD5 2d269d941409376b6baaee37345a8b3d
BLAKE2b-256 09d89bbdbebf1ea8628504449382f851e394ac63a0e68a85b0bb965e29116941

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybinwalk-0.0.2.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.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pybinwalk-0.0.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 419fd7bb11010ddd1e5966474ed4c49ec4ccf64e5e4aad0857bce5a170963da2
MD5 bb9dde454ece4591c78ebe07810b0a00
BLAKE2b-256 c6dea2e718b080b7e30434b55c866af7184c2a91622e1d8eae3397cac7e84871

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybinwalk-0.0.2-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.2-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pybinwalk-0.0.2-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 851.0 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.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7a5a46ac48ea9ab975bb7a693f621828c092a62473ab8861e8fa1fcffe1c85a6
MD5 f564817e07b180f67c5e4c917a0d37d0
BLAKE2b-256 8f0d16ad8aa0cd8588c068488d33cdb527b46f244048a7709eea3882756977a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybinwalk-0.0.2-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.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pybinwalk-0.0.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09be483b4f199c6016991df9f927db62f7e38e03fe222fdcaa4b014b6c087c12
MD5 5aec28fbcfe4594d6d324f09fafc1cff
BLAKE2b-256 f9ad058260136767d87c5b3091b61f9504a87b2dc153c0c1fad39be825a7d657

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybinwalk-0.0.2-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.2-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.2-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 5e374b2d6866c4357dfb8cbf1de1420611b81ae739d03e4c68b9f4240d128523
MD5 6d3d2acd0edff2e69efaec2bf5f86583
BLAKE2b-256 9cd396e4a33399886a852cf556f272381529e46edd3ae0de284837c562d5d0fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybinwalk-0.0.2-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