Packaging Pyarmor obfuscated script #9039
-
Hi- I am working on a project where I am hoping to obfuscate the project with PyArmor, then package it with PyInstaller. I am able to obfuscate the project with PyArmor. I am also able to package the unobfuscated project with PyInstaller. But, I am not able to package the obfuscated code. I can see from the terminal output that PyInstaller misses
My suspicion is that the bytecode is too long for PyInstaller, as when I package a smaller test project with less dependencies, PyInstaller does not miss importing the hook. Is there a limit to the length of bytecode that can be imported in a hook? Here is a link to the discussion on PyArmor that brought me here. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I believe I provided the incorrect file reference before. The file that is not getting processed is The test project with fewer dependencies (106) works fine. |
Beta Was this translation helpful? Give feedback.
-
I don't think so. The following example generates a package with 10k sub-modules and a hook that adds them to hiddenimports, and it seems to work for me: import sys
import os
import pprint
NUM_MODULES=10_000
hook_dir = 'extra-hooks'
module_names = [
f"mypackage.module_{i}" for i in range(NUM_MODULES)
]
# Create package and its modules
for module_name in module_names:
module_file = module_name.replace('.', os.sep) + '.py'
module_dir = os.path.dirname(module_file)
os.makedirs(module_dir, exist_ok=True)
with open(module_file, 'w') as fp:
print("# Test module", file=fp)
print(f"""print("Importing module {module_name!r}!")""", file=fp)
with open('mypackage/__init__.py', 'w') as fp:
print("import importlib", file=fp)
for module_name in module_names:
print(f"importlib.import_module({module_name!r})", file=fp)
with open('program.py', 'w') as fp:
print("import mypackage", file=fp)
# Create hook
os.makedirs(hook_dir, exist_ok=True)
hook_file = os.path.join(hook_dir, 'hook-mypackage.py')
with open(hook_file, 'w') as fp:
print(f"hiddenimports={pprint.pformat(module_names)}", file=fp)
# Now run: pyinstaller --clean --noconfirm --additional-hooks-dir=extra-hooks program.py So if the hook is not ran, there are couple of possibilities I can think of:
|
Beta Was this translation helpful? Give feedback.
I don't think so. The following example generates a package with 10k sub-modules and a hook that adds them to hiddenimports, and it seems to work for me: