logo

deblob

remove binary executables from a directory git clone https://hacktivis.me/git/deblob.git
commit: c8bd35394e7b5b803443bd0f2411ecd7ff5a11f3
parent 5391197393762ac12557696c73b2bdb64cb9146b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  5 Sep 2022 15:35:59 +0200

Add support for Python 3.8/3.9/3.10 bytecode

Diffstat:

MMakefile12++++++++++++
Mdeblob.12++
Mmain.ha8++++++--
Atest/fixtures/hello.py2++
Atest/fixtures/pyc/hello.checked_hash.cpython-310.pyc0
Atest/fixtures/pyc/hello.checked_hash.cpython-38.pyc0
Atest/fixtures/pyc/hello.checked_hash.cpython-39.pyc0
Atest/fixtures/pyc/hello.timestamp.cpython-310.pyc0
Atest/fixtures/pyc/hello.timestamp.cpython-38.pyc0
Atest/fixtures/pyc/hello.timestamp.cpython-39.pyc0
Atest/fixtures/pyc/hello.unchecked_hash.cpython-310.pyc0
Atest/fixtures/pyc/hello.unchecked_hash.cpython-38.pyc0
Atest/fixtures/pyc/hello.unchecked_hash.cpython-39.pyc0
Atest/python_compile.py13+++++++++++++
14 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -40,10 +40,22 @@ test: all $(TEST_BLOBS) $(HARE) $(HAREFLAGS) test rm -fr test/check_dir-fixtures + rm -fr test/check_dir_pyc-fixtures + cp -r test/fixtures/pyc/ test/check_dir_pyc-fixtures + test -n "$$(ls test/check_dir_pyc-fixtures)" + ./deblob -d test/check_dir_pyc-fixtures + test -z "$$(ls test/check_dir_pyc-fixtures)" + rm -fr test/check_dir_pyc-fixtures + .PHONY: lint lint: $(MANDOC) -Tlint -Wunsupp,error,warning $(EXE).1 +# https://pypi.org/project/black/ python code formatter +.PHONY: format +format: + black . + .PHONY: install install: mkdir -p $(DESTDIR)$(BINDIR) diff --git a/deblob.1 b/deblob.1 @@ -45,6 +45,8 @@ x86 IBM PC BIOS Option Rom Erlang BEAM files .It Java Class files +.It +Python 3.8/3.9/3.10 bytecode files (typically *.pyc) .El .Sh EXAMPLES The following code block show how it is intended to be used in Gentoo's diff --git a/main.ha b/main.ha @@ -20,6 +20,10 @@ const magic: [_][]u8 = [ [0x55, 0xAA], // IBM PC BIOS ROM ['F', 'O', 'R', '1'], // Erlang BEAM [0xCA, 0xFE, 0xBA, 0xBE], // Java Class File & Mach-O Executable + // Python *.pyc bytecode magic numbers (defined in importlib/_bootstrap_external.py) + [0x55, 0x0D, '\r', '\n'], // (3413i litte-endian) Python 3.8 + [0x61, 0x0D, '\r', '\n'], // (3425i litte-endian) Python 3.9 + [0x6F, 0x0D, '\r', '\n'], // (3439i litte-endian) Python 3.10 ]; fn is_blob(filename: str) (bool | fs::error | io::error) = { @@ -154,7 +158,7 @@ fn check_dir(dirname: str) (void | errors::invalid) = { case let e: fs::error => fmt::fatalf("os::readdir({}): {}", dirname, fs::strerror(e)); }; - assert(len(files_before) == 12); + assert(len(files_before) == 14); const ret = check_dir(dirname); assert(ret is void); @@ -165,7 +169,7 @@ fn check_dir(dirname: str) (void | errors::invalid) = { case let e: fs::error => fmt::fatalf("os::readdir({}): {}", dirname, fs::strerror(e)); }; - assert(len(files_after) == 7); + assert(len(files_after) == 9); }; export fn main() void = { diff --git a/test/fixtures/hello.py b/test/fixtures/hello.py @@ -0,0 +1,2 @@ +#!/usr/bin/python +print("hello world") diff --git a/test/fixtures/pyc/hello.checked_hash.cpython-310.pyc b/test/fixtures/pyc/hello.checked_hash.cpython-310.pyc Binary files differ. diff --git a/test/fixtures/pyc/hello.checked_hash.cpython-38.pyc b/test/fixtures/pyc/hello.checked_hash.cpython-38.pyc Binary files differ. diff --git a/test/fixtures/pyc/hello.checked_hash.cpython-39.pyc b/test/fixtures/pyc/hello.checked_hash.cpython-39.pyc Binary files differ. diff --git a/test/fixtures/pyc/hello.timestamp.cpython-310.pyc b/test/fixtures/pyc/hello.timestamp.cpython-310.pyc Binary files differ. diff --git a/test/fixtures/pyc/hello.timestamp.cpython-38.pyc b/test/fixtures/pyc/hello.timestamp.cpython-38.pyc Binary files differ. diff --git a/test/fixtures/pyc/hello.timestamp.cpython-39.pyc b/test/fixtures/pyc/hello.timestamp.cpython-39.pyc Binary files differ. diff --git a/test/fixtures/pyc/hello.unchecked_hash.cpython-310.pyc b/test/fixtures/pyc/hello.unchecked_hash.cpython-310.pyc Binary files differ. diff --git a/test/fixtures/pyc/hello.unchecked_hash.cpython-38.pyc b/test/fixtures/pyc/hello.unchecked_hash.cpython-38.pyc Binary files differ. diff --git a/test/fixtures/pyc/hello.unchecked_hash.cpython-39.pyc b/test/fixtures/pyc/hello.unchecked_hash.cpython-39.pyc Binary files differ. diff --git a/test/python_compile.py b/test/python_compile.py @@ -0,0 +1,13 @@ +#!/usr/bin/python +import py_compile +import sys + +for check in py_compile.PycInvalidationMode: + name = check.name.lower() + value = check.value + src_file = "./test/fixtures/hello.py" + dest_file = "./test/fixtures/pyc/hello.{}.{}.pyc".format( + name, sys.implementation.cache_tag + ) + print(dest_file) + py_compile.compile(src_file, cfile=dest_file, invalidation_mode=check.value)