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.
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
validateon 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.
carvewithout--list,--id,--all, or--offsetonly lists objects.
Metadata
Release files for lupaxa-magic-bytes 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lupaxa_magic_bytes-0.1.0.tar.gz | 42.8 kB | With provenance | Details for lupaxa_magic_bytes-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lupaxa_magic_bytes-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for lupaxa_magic_bytes-0.1.0-py3-none-any.whl |
Total release size: 92.0 kB
Release files / lupaxa_magic_bytes-0.1.0.tar.gz
| Download URL | lupaxa_magic_bytes-0.1.0.tar.gz |
|---|---|
| Size | 42.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00d15b083e25d2223c5e37c78c444d7e3f802c1259ec0cd0b9edaba8d512aa4f
|
|
BLAKE2b-256 checksum How to use checksums |
d4af75c4d6a777023bfe7aef4996cc142e481a185b87ee43cea17e113852a6c7
|
| 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 18, 2026.
Transparency logRelease files / lupaxa_magic_bytes-0.1.0-py3-none-any.whl
| Download URL | lupaxa_magic_bytes-0.1.0-py3-none-any.whl |
|---|---|
| Size | 49.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3bda04efe6dbdb7260f8c09c820f8322a965a83cbdccfeac79e46a5b31a4fc14
|
|
BLAKE2b-256 checksum How to use checksums |
671d157f3775d2f0ec52fb1b1ae69f691c45462f58d8e4d2be8294b4e56c2d52
|
| 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 18, 2026.
Transparency logSecurity for lupaxa-magic-bytes 0.1.0
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.
Attestation for lupaxa_magic_bytes-0.1.0.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 18, 2026.
Transparency logA 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.