Skip to main content

Security Toolbox

Magic Bytes

Magic Bytes identifies, checks, and extracts binary file structures. It runs offline and does not use the network.

A signature is not proof of a valid file. Validation is not proof that a file is safe to open. The tool never executes what it inspects or extracts.

Install

Python 3.11 or newer:

pip install lupaxa-magic-bytes

The command is magic-bytes. The import path is lupaxa.magic_bytes. lupaxa is a namespace package — there is no lupaxa/__init__.py.

Quick Start

magic-bytes identify mystery.dat
magic-bytes validate picture.png --level standard
magic-bytes carve suspicious.bin --list

What it Does

  • Identifies formats from bytes, including files whose extension is wrong or missing.
  • Validates PNG, JPEG, GIF, BMP, ZIP, PDF, WAV, MP3, ELF, PE, SQLite, and GZIP.
  • Reports other common formats from signatures when no structural validator exists.
  • Finds embedded objects, trailing bytes, and overlapping interpretations.
  • Carves recoverable ranges without modifying the source.
  • Maps layouts, measures entropy, dumps hex, compares files, and scans directories.
  • Accepts declarative TOML signatures. Rules cannot run programs.

Confidence

Confidence is a label, not a probability. A file can be confidently identified and still be truncated.

Confidence Meaning
confirmed Structural validation passed
high Strong signature, or validation was only partial
medium A recognised signature with limited support
low A weak or ambiguous signature
unknown Not enough evidence

Commands

Global options come before the subcommand.

Option Effect
--config PATH Load a TOML file
--json Print one JSON document
--quiet Hide the human report
--verbose More diagnostic detail
--debug Trace unexpected errors
--no-colour Plain text
--no-progress Hide progress
--jobs N Worker count for scans
--max-file-size SIZE Refuse larger inputs
--max-scan-bytes SIZE Bound a deep scan
--timeout SECONDS Stop bounded work
--force Replace an existing output file
--version Print the version
--help Show help

Sizes accept integers, 0x hex, and K, M, or G suffixes.

| Command | Purpose | Main options | | | | ------------ | ------------------------------- | ---------------------------------------------------------------------------- | | | | identify | Name the likely formats | --all, --deep, --offset, --signatures-only | | | | inspect | Combine structure and findings | --deep, --embedded, --trailing, --entropy, --structure, --report | | | | validate | Check one recognised structure | --format, --level basic\ | standard\ | deep, --strict, --report | | scan | Walk a directory | --recursive, --mismatches, --invalid, --embedded, --trailing | | | | carve | Copy a range out of a file | --list, --id, --all, --offset, --length, --validated-only | | | | compare | Diff two files | --structural, --bytewise, --format text\ | json\ | html | | entropy | Shannon bits per byte | --block-size, --window-size, --step, --offset, --length, --chart | | | | hexdump | Show or search bytes | --offset, --length, --width, --find, --utf8 | | | | map | Draw regions | --format terminal\ | html\ | json, --show-entropy, --show-embedded | | signatures | List and manage TOML rules | list, show, add, remove, validate, test | | |

identify keeps competing candidates. The primary one is the strongest, not merely the first. An extension mismatch is an observation. High entropy is not evidence of encryption, and a PE overlay is not evidence of malice.

Validation

Level Behaviour
basic Signature and essential header checks
standard Boundaries, required chunks, and declared sizes
deep CRCs, deflate checks, and a read-only SQLite integrity check

--strict turns warnings into failures. A failed validation exits 6. That is different from the validator failing to run.

PDF reports say when a full semantic parse was not done. ZIP64 and xref streams are called out instead of being treated as corruption. SQLite deep checks open the file read-only and immutable so they do not create a journal.

Carving

magic-bytes carve suspicious.bin --list
magic-bytes carve suspicious.bin --id 2 --output recovered.bin

Boundaries are exact, estimated, or user-selected. Only an exact validated extraction is described as fully validated. Output is never executed. Existing files are kept unless --force is set. Each extraction reports the source offset, length, and SHA-256.

Custom Signatures

[[signature]]
id = "custom-data"
name = "Custom Data File"
mime = "application/x-custom"
extensions = [".dat"]
min_size = 16

[[signature.match]]
offset = 0
hex = "4C 55 50 41 ?? 41"
required = true

hex may also be a list of alternative patterns. ?? is a wildcard. end_relative measures from the end of the file. Built-in signatures cannot be replaced. A rule file that sets command, exec, script, python, or shell is rejected.

magic-bytes signatures validate custom.toml
magic-bytes signatures test custom.toml sample.dat
magic-bytes signatures add custom.toml

JSON

--json prints one object and nothing else on standard output. Offsets are integers. Reports include catalogue_version and validator_version.

{
  "schema_version": 1,
  "command": "identify",
  "success": true,
  "results": []
}

Exit Codes

Code Meaning
0 Success
1 General failure
2 Invalid arguments or configuration
3 Unsupported format or operation
4 Input or output error
5 No recognised format
6 Structural validation failed
7 Extraction failed
8 Resource limit exceeded
9 Invalid custom signature
10 Partial batch failure

Configuration

A file is optional. The user file is the platform config directory for magic-bytes / Lupaxa / config.toml. Environment variables use the MAGIC_BYTES_ prefix and override the file. Explicit CLI options override both.

validation_level = "standard"
max_file_size = 536870912
max_scan_bytes = 536870912
max_depth = 4
max_candidates = 256
max_extract_size = 268435456
workers = 4
entropy_block_size = 4096
colour = true
follow_symlinks = false
timeout_seconds = 60

Security

Inputs are untrusted. Declared lengths are checked before they are used. Decompression and candidate counts stop at configured limits. Archive carving copies the archive object; it does not unpack members or follow paths inside them. HTML reports are self-contained and escape file-derived text.

Troubleshooting

  • validate on a signature-only format exits 3 because there is no structural validator.
  • A ZIP or PDF with a prefix can still be valid. The report names the prefix.
  • Deep scans can stop early when the candidate or byte limit is reached. The report then says the analysis is incomplete.
  • carve without --list, --id, --all, or --offset only lists objects.
The Lupaxa Project Footer

Metadata

Release files for lupaxa-magic-bytes 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lupaxa-magic-bytes 0.1.1
File Size Uploaded Provenance Actions
lupaxa_magic_bytes-0.1.1.tar.gz 42.8 kB With provenance Details for lupaxa_magic_bytes-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lupaxa-magic-bytes 0.1.1
File Interpreter ABI Platform Actions
lupaxa_magic_bytes-0.1.1-py3-none-any.whl Python 3 none any Details for lupaxa_magic_bytes-0.1.1-py3-none-any.whl

Total release size: 92.0 kB

Release files / lupaxa_magic_bytes-0.1.1.tar.gz

Download URL lupaxa_magic_bytes-0.1.1.tar.gz
Size 42.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bf262e0581fcc7c5ddbe66e52fe8966da25bda0420ea83bfb69f8b0e8785b87b
BLAKE2b-256 checksum
How to use checksums
9aea08ef48bb16c7f085731b6fdf5152ecff01de5482197cc7725edacf0f4341
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / lupaxa_magic_bytes-0.1.1-py3-none-any.whl

Download URL lupaxa_magic_bytes-0.1.1-py3-none-any.whl
Size 49.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
045b62de4331a65f705d51c2b33333f73ecd7f89fb39b1bef5a63d8f0a5402b3
BLAKE2b-256 checksum
How to use checksums
fea5a19230f29c788488ae056663bc5fd1a58f807506514f416a540503645bf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for lupaxa-magic-bytes 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for lupaxa_magic_bytes-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page