commit a70defc85ff40e71424553731706c7d904c235cf Author: Matthieu Jolimaitre Date: Tue Jun 17 15:30:36 2025 +0200 Init. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c81b1f0 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Comprimé + +Utility for compressing directories into unexecutable files. diff --git a/compress.py b/compress.py new file mode 100755 index 0000000..90f79fa --- /dev/null +++ b/compress.py @@ -0,0 +1,30 @@ +#!/usr/bin/env -S python3 + +import subprocess +import sys + + +def main(): + [_, input] = sys.argv + input_tar = input + ".tar" + output = input + ".cprmt" + print("Compressing '" + input + "' into '" + output + "'.") + subprocess.Popen(["tar", "cf", input_tar, input]).wait() + input_tar_fd = open(input_tar, "rb") + output_fd = open(output, "wb") + byte_index = 0 + while True: + read = input_tar_fd.read(1024) + if len(read) == 0: + break + for byte in read: + if byte_index == 0: + output_fd.write(bytes([5, byte])) + else: + output_fd.write(bytes([byte])) + byte_index += 1 + byte_index %= 4 + print("Done.") + + +if __name__ == "__main__": main() diff --git a/decompr.py b/decompr.py new file mode 100755 index 0000000..e0000d9 --- /dev/null +++ b/decompr.py @@ -0,0 +1,30 @@ +#!/usr/bin/env -S python3 + +import subprocess +import sys + + +def main(): + [_, input] = sys.argv + input_tar = input.replace(".cprmt", ".tar") + output = input_tar.replace(".tar", "") + print("Decompressing '" + input + "' into '" + output + "'.") + input_fd = open(input, "rb") + output_tar_fd = open(input_tar, "wb") + byte_index = 0 + while True: + read = input_fd.read(1024) + if len(read) == 0: + break + for byte in read: + if byte_index == 0: + pass + else: + output_tar_fd.write(bytes([byte])) + byte_index += 1 + byte_index %= 5 + subprocess.Popen(["tar", "xf", input_tar]).wait() + print("Done.") + + +if __name__ == "__main__": main() diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..af7a17a --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +/wdir \ No newline at end of file diff --git a/test/case/a b/test/case/a new file mode 100644 index 0000000..8d86a3b --- /dev/null +++ b/test/case/a @@ -0,0 +1 @@ +arbre \ No newline at end of file diff --git a/test/case/b b/test/case/b new file mode 100644 index 0000000..05e1840 --- /dev/null +++ b/test/case/b @@ -0,0 +1 @@ +barbier \ No newline at end of file diff --git a/test/run b/test/run new file mode 100755 index 0000000..7f1f3b2 --- /dev/null +++ b/test/run @@ -0,0 +1,17 @@ +#!/usr/bin/bash +cd "$(dirname "$(realpath "$0")")" +set -e + + + +rm -fr wdir +mkdir wdir wdir/in wdir/out +cp -r case wdir/in/ + + +cd wdir/in +../../../compress.py case +cp case.cprmt ../out/ + +cd ../out +../../../decompr.py case.cprmt