dashingsoft / pyarmor

A tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.
http://pyarmor.dashingsoft.com
Other
3.28k stars 280 forks source link

pyarmor.helper.merge #573

Closed populc closed 2 years ago

populc commented 3 years ago

I'm trying to obfuscate code for different platforms and versions of python with PyArmor Trial Version 6.8.0. To do this, with the help of the documentation, I have created a bat with the following commands:

pyarmor obfuscate --platform windows.x86.0  --platform windows.x86_64.0 --platform linux.x86.0  --platform linux.x86_64.0  --platform darwin.x86_64.0  --platform linux.arm.0 --platform linux.armv6.0  --platform linux.armv7.0  --platform linux.aarch32.0  --platform linux.aarch64.0 --platform android.aarch64.0  --platform android.armv7.0  --platform android.x86.0  --platform android.x86_64.0 --no-cross-protection -O py27 default_org.py
pyarmor3 obfuscate --platform windows.x86.0  --platform windows.x86_64.0 --platform linux.x86.0  --platform linux.x86_64.0  --platform darwin.x86_64.0  --platform linux.arm.0 --platform linux.armv6.0  --platform linux.armv7.0  --platform linux.aarch32.0  --platform linux.aarch64.0 --platform android.aarch64.0  --platform android.armv7.0  --platform android.x86.0  --platform android.x86_64.0 --no-cross-protection -O py38 default_org.py

python -m pyarmor.helper.merge py27/ py38/

where default.py is a python 2.7 and 3.8 compatible test script, and pyarmor3 is another bat as explained at https://pyarmor.readthedocs.io/en/latest/advanced.html#obfuscating-scripts-by-other-python-version.

The result of running the code in python 3.8 is correct, but if I try it in python 2.7 I get "RuntimeError: Marshal loads failed"

If in the last line of the bat we change the order of the arguments: python -m pyarmor.helper.merge py38/ py27/ the test result is also reversed: Python2.7 ok and python3.8 "RuntimeError: Marshal loads failed"

This is the expected performance? Can't do what I want?

jondy commented 3 years ago

Make sure the runtime files are latests, and the trial version doesn't support this feature.

  1. First make sure both py38/, py37 works
  2. Check the output log, make sure 2 versions are merged
  3. Run merged scripts in merged_dist/
populc commented 3 years ago
  1. Effectively the content of each folder works in its own version of python

  2. K:\plugin.video.test>python -m pyarmor.helper.merge py27/ py38/
    INFO     Merge 'py27/', 'py38/'...
    INFO     Merging obfuscated scripts...
    INFO     Find scripts in the path py38
    INFO     Parse reference script py27/default.py
    INFO     Parse script py38/default.py
    INFO     Write merged script: merged_dist\default.py
    INFO            * Python 3.8
    INFO            * Python 2.7
    INFO     Parse reference script py27/pytransform\__init__.py
    INFO     Ignore this script, it is not obfuscated
    INFO     Merging obfuscated scripts OK
    INFO     Merging runtime files...
    INFO     Copy non-super mode runtime package py38\pytransform
    INFO     To merged_dist\pytransform
    INFO     Merging runtime files OK
    INFO     Merge all the scripts to merged_dist successfully
  3. We repeat result: The result of running the code in python 3.8 is correct, but if I try it in python 2.7 I get "RuntimeError: Marshal loads failed"

Make sure the runtime files are latests, and the trial version doesn't support this feature.

Effectively...

K:\plugin.video.test>pyarmor download --update
INFO     PyArmor Trial Version 6.8.0
INFO     Python 2.7.13
INFO     Removed cached platform index file C:\Users\super\.pyarmor\platforms\in
dex.json
WARNING  The trial version could not download the latest platform library
INFO     Getting remote file: https://github.com/dashingsoft/pyarmor-core/raw/r4
1.15a/platforms/index.json
INFO     Write cached platform list file C:\Users\super\.pyarmor\platforms\index
.json
WARNING  The trial version could not download the latest core libraries, tag r41
.15a is always used
WARNING  The core library excepted version is r45.19, but got r41.15a from platf
orm list file C:\Users\super\.pyarmor\platforms\index.json
INFO     Nothing updated

But does this mean that with the trial version it is not possible to have an obfuscated script valid for various platforms and versions of python?

jondy commented 3 years ago

Yes, refer to https://pyarmor.readthedocs.io/en/latest/change-logs.html#id7