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.32k stars 282 forks source link

Cross platform issue with obfuscation on x64 linux desktop, then run on pi arm7 #244

Closed thefatmoop closed 4 years ago

thefatmoop commented 4 years ago

Hello, If I generate obfuscated scripts on my desktop, then transfer them to a pi, i'm unable to run them on the pi. Since pyarmor is using ctypes i'm guessing it's due to an architecture difference between the x64 desktop -> arm pi.

My question is: How can I generate obfuscated scripts on my desktop that will run on the raspberry pi?

Traceback (most recent call last): File "loadCell.py", line 2, in <module> pyarmor_runtime() File "/home/pi/temp/dist/pytransform/__init__.py", line 314, in pyarmor_runtime pyarmor_init(path, is_runtime=1, suffix=suffix) File "/home/pi/temp/dist/pytransform/__init__.py", line 309, in pyarmor_init _pytransform = _load_library(path, is_runtime, platid, suffix) File "/home/pi/temp/dist/pytransform/__init__.py", line 277, in _load_library m = cdll.LoadLibrary(filename) File "/usr/lib/python2.7/ctypes/__init__.py", line 444, in LoadLibrary return self._dlltype(name) File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__ self._handle = _dlopen(self._name, mode) OSError: /home/pi/temp/dist/pytransform/_pytransform.so: wrong ELF class: ELFCLASS64

jondy commented 4 years ago

Refer to Distributing Obfuscated Scripts To Other Platform

thefatmoop commented 4 years ago

Thanks, i have many scripts in the same folder which almost all need to be executed. The command below seemed like it'd give everything runtime capabilities pyarmor obfuscate --platform linux.armv7 --exact *.py

But this leads to error when transferring and running on the pi: Traceback (most recent call last): File "<loadCell.py>", line 3, in <module> File "<frozen loadCell>", line 14, in <module> File "</home/pi/temp/dist/localProvisionClient.py>", line 4, in <module> File "<frozen localProvisionClient>", line 109, in <module> File "<frozen localProvisionClient>", line 104, in protect_pytransform File "<frozen localProvisionClient>", line 90, in check_lib_pytransform File "/usr/lib/python2.7/genericpath.py", line 57, in getsize return os.stat(filename).st_size OSError: [Errno 2] No such file or directory: '/home/pi/temp/dist/pytransform/platforms/linux/armv7/_pytransform.so' I do have this file, just in a different location /home/pi/temp/dist/pytransform/_pytransform.so

Now if I run this on my x64 desktop and then transfer/run on pi: pyarmor obfuscate --platform linux.armv7 loadCell.py the loadcell script works, but then the other scripts don't get runtime.

jondy commented 4 years ago

It's a bug in the v6.x.0, I'll fix it in next version v6.2.1. But in the older version it should work, I guess the version in your x64 desktop is old version pyarmor.

jondy commented 4 years ago

Fixed in v6.2.1

thefatmoop commented 4 years ago

Thanks Jondy, I updated but still getting errors:

Script obfuscation log from desktop (mainly to show 6.2.1 version), i'll buy license once this is working $ pyarmor obfuscate --platform linux.armv7 --exact *.py INFO PyArmor Trial Version 6.2.1 INFO Target platforms: ['linux.armv7'] INFO Source path is "/home/bo/Desktop/dowork" INFO Entry scripts are ['AggregatorClient.py', 'aggregator.py', 'loadCell.py', 'localProvisionClient.py', 'localProvisionServer.py', 'logUpload.py', 'provision.py'] INFO Use cached capsule /home/bo/.pyarmor/.pyarmor_capsule.zip INFO Search scripts mode: Exact INFO Save obfuscated scripts to "dist" INFO Read public key from capsule INFO Obfuscate module mode is 1 INFO Obfuscate code mode is 1 INFO Wrap mode is 1 INFO Restrict mode is 1 INFO Advanced mode is 0 INFO Generating runtime files to dist/pytransform INFO Extract pytransform.key INFO Generate default license file INFO Write license file: dist/pytransform/license.lic INFO Copying /home/bo/.pyarmor/platforms/linux/armv7/3/_pytransform.so INFO Generate runtime files OK INFO Start obfuscating the scripts... INFO /home/bo/Desktop/dowork/AggregatorClient.py -> dist/AggregatorClient.py INFO Patch this entry script with protection code INFO Insert shell line: #!/usr/bin/env python INFO Insert bootstrap code to entry script dist/AggregatorClient.py INFO /home/bo/Desktop/dowork/aggregator.py -> dist/aggregator.py INFO Insert bootstrap code to entry script dist/aggregator.py INFO /home/bo/Desktop/dowork/loadCell.py -> dist/loadCell.py INFO Insert bootstrap code to entry script dist/loadCell.py INFO /home/bo/Desktop/dowork/localProvisionClient.py -> dist/localProvisionClient.py INFO Patch this entry script with protection code INFO Insert shell line: #!/usr/bin/env python INFO Insert bootstrap code to entry script dist/localProvisionClient.py INFO /home/bo/Desktop/dowork/localProvisionServer.py -> dist/localProvisionServer.py INFO Patch this entry script with protection code INFO Insert bootstrap code to entry script dist/localProvisionServer.py INFO /home/bo/Desktop/dowork/logUpload.py -> dist/logUpload.py INFO Patch this entry script with protection code INFO Insert shell line: #!/usr/bin/env python INFO Insert bootstrap code to entry script dist/logUpload.py INFO /home/bo/Desktop/dowork/provision.py -> dist/provision.py INFO Patch this entry script with protection code INFO Insert bootstrap code to entry script dist/provision.py INFO Obfuscate 7 scripts OK.

The pi has pyarmor installed. I didn't update the pi's pyarmor as it isn't needed to run obfuscated scripts.

Error when running on the pi: $ python loadCell.py Traceback (most recent call last): File "<loadCell.py>", line 3, in <module> File "<frozen loadCell>", line 14, in <module> File "</home/pi/temp/dist/localProvisionClient.py>", line 4, in <module> File "<frozen localProvisionClient>", line 109, in <module> File "<frozen localProvisionClient>", line 104, in protect_pytransform File "<frozen localProvisionClient>", line 90, in check_lib_pytransform File "/usr/lib/python2.7/genericpath.py", line 57, in getsize return os.stat(filename).st_size OSError: [Errno 2] No such file or directory: '/home/pi/temp/dist/pytransform/platforms/linux/armv7/_pytransform.so'

jondy commented 4 years ago

Sorry, I made a mistake. As a quick workaround, you can download the latest pyarmor.py in the master branch and overwrite the pyarmor.py in your desktop.

thefatmoop commented 4 years ago

Still getting the error. I installed pyarmor with pip install pyarmor, so tried doing pip uninstall pyarmor and reinstall and got the error. I also downloaded the latest pyarmor master and replaced pyarmor.py in where i think is the right location: sudo cp /home/bo/Downloads/pyarmor-master/src/pyarmor.py /usr/local/lib/python2.7/dist-packages/pyarmor-6.2.1-py2.7.egg/pyarmor/pyarmor.py

Did I do that right?

jondy commented 4 years ago

First check the latest pyarmor.py, about line 658, make sure the keyword argument multiple like this

multiple=platforms and len(platforms) > 1,

Then run pyarmor -d obfuscate ..., it will print the path where pyarmor installed. Make sure you copy it the right location.

thefatmoop commented 4 years ago

Yeah did a search for pyarmor.py, looks like whereis and what was actually getting run didn't match paths. Anyway looks like it's working now, i'll do more testing in 1-2 days when I need to run pyarmor more