Skip to main content

Wrap Python scripts so they print their own MD5 without reading their source at runtime.

Project description

py-self-md5

py-self-md5 wraps a Python script so the generated script prints MD5: <DIGEST> before running the original program.

The generated script does not read its own source file at runtime. Instead, the inserted prefix stores a quine-style byte template and computes the digest from the reconstructed bytes in memory.

This project is inspired by zhuzilin/pdf-with-its-own-md5, where selectable MD5-collision carriers are used to display the final digest in a PDF. This tool targets executable Python programs and does not require HashClash or precomputed collision blocks.

Install

Requires Python 3.11 or newer.

python -m pip install py-self-md5

After installation, run the built-in check:

py-self-md5 --self-test

You can also run it from the project root without installing:

python -m py_self_md5 --self-test

Usage

Create input.self_md5.py:

py-self-md5 input.py

Run the generated script:

python input.self_md5.py

The first output line is MD5: <DIGEST>, where <DIGEST> is the uppercase MD5 digest of input.self_md5.py; then the original program continues.

Write to a specific path:

py-self-md5 input.py -o output.py

Rewrite the input file in place:

py-self-md5 input.py --in-place

Replace an existing py-self-md5 prefix in place:

py-self-md5 input.py --in-place --force

Overwrite an existing output file:

py-self-md5 input.py -o output.py --force

Generate and verify in one step:

py-self-md5 input.py --check

What the wrapper preserves

  • The tool preserves shebang lines, encoding cookies, module docstrings, and from __future__ import ... placement.
  • By default, the input file is not modified.
  • Existing py-self-md5 prefixes are detected. Use --force to replace one.

Limitations

  • This is an executable self-hash wrapper, not a general MD5 collision generator.
  • The generated prefix can be large because it embeds enough bytes to reconstruct the generated script in memory.
  • --check executes the generated script, so only use it with programs you are willing to run.

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

py_self_md5-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

py_self_md5-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file py_self_md5-0.1.0.tar.gz.

File metadata

  • Download URL: py_self_md5-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for py_self_md5-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c8713e81a6f24c01404525d49386aae1ddc0dfea48834c751a1e38c45f3d2d46
MD5 b2a73c3485f6f24ed998383f15d4d81f
BLAKE2b-256 10e831d4124663bf56a9c957e3967bc59170474763bffb2aa2e7606c1c28f10d

See more details on using hashes here.

File details

Details for the file py_self_md5-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_self_md5-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for py_self_md5-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bfce1853d380c730db3cde3f9cc342cfb4e70b39bdb7eddc7a6fcfadb5a3720
MD5 850f40d3a0a9f71b2622d5f905bd5a36
BLAKE2b-256 3f00cc58847501196d09753b7fec1028204e6d1c5cb3d334a0999f2065227255

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