pyinstaller-decompiler/get_co.py

22 lines
639 B
Python

#!/usr/bin/env python3
from PyInstaller.archive.readers import ZlibArchiveReader
from sys import argv
from pathlib import Path
if len(argv) != 3:
print(f"usage {argv[0]} [PYZ] [OUTPUT_PATH]")
exit()
output_dir = Path(argv[2])
archive = ZlibArchiveReader(argv[1])
for filename, (is_package, pos, size) in archive.toc.items():
data = archive.extract(filename, raw=True)
if type(filename) is bytes:
filename = filename.decode("utf-8")
filename = filename.replace(".", "/")
out_file = output_dir / Path(f"{filename}.co")
out_file.parent.mkdir(parents=True, exist_ok=True)
out_file.write_bytes(data)