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.35k stars 284 forks source link

Pyarmor + Nuitka does not work? #174

Closed sla-te closed 4 years ago

sla-te commented 4 years ago

I obfuscated a simple hello-world.py with pyarmor and then compiled a standalone exe using nuitka and I get this error:

Traceback (most recent call last):
  File "C:\Users\user\Desktop\dist\hello-world.dist\pytransform\__init__.py", line 287, in pyarmor_runtime
    init_runtime()
  File "C:\Users\user\Desktop\dist\hello-world.dist\pytransform\__init__.py", line 54, in wrap
    return func(*args, **kwargs)
  File "C:\Users\user\Desktop\dist\hello-world.dist\pytransform\__init__.py", line 83, in init_runtime
    return _init_runtime(0, 0, 0, 0)
RuntimeError: Check restrict mode failed (1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\Desktop\dist\hello-world.dist\hello-world.py", line 2, in <module>
  File "C:\Users\user\Desktop\dist\hello-world.dist\pytransform\__init__.py", line 289, in pyarmor_runtime
    raise PytransformError(e)
pytransform.PytransformError: Check restrict mode failed (1)
jondy commented 4 years ago

Try to obfuscate the scripts with --restrict 0, for example,

pyarmor obfuscate --restrict 0 foo.py
sla-te commented 4 years ago

Yeah, that really worked thanks. Anything else I need to consider?

jondy commented 4 years ago

I think nuitka must change something of the entry script, so it can't be accepted by pyarmor.

Here are some differences of the obfuscated scripts https://pyarmor.readthedocs.io/en/latest/understand-obfuscated-scripts.html#the-differences-of-obfuscated-scripts

sla-te commented 4 years ago

I will look into that. What about if I have a folder structure with multiple scripts? I just tried obfuscating all of them manually and after many features were not working anymore.

I get this when I try to start the features:

File "MRTFiles/range_controller.py", line 1, in <module>
    __pyarmor__(__name__, __file__,'\x50\x59\x41\x52\x4---verylong)
NameError: name '__pyarmor__' is not defined
jondy commented 4 years ago

This scripts need to be obfuscated separately, for example,

pyarmor obfuscate --no-runtime --exact MRTFiles/range_controller.py

Refer to https://pyarmor.readthedocs.io/en/latest/understand-obfuscated-scripts.html#bootstrap-code

sla-te commented 4 years ago

I manually compiled all scripts now now I get this error:

Traceback (most recent call last):
  File "MRTFiles/range_controller.py", line 1, in <module>
    from pytransform import pyarmor_runtime
ModuleNotFoundError: No module named 'pytransform'

EDIT: After I manually recreated the folder structure and copied the pytransform folder in every other folder it works

sla-te commented 4 years ago

Ok, I had to compile every script with --restrict 0 again - Now I get:

Traceback (most recent call last):
  File "<C:\Users\user\Desktop\mnwd_tool-obf\dist\MRT.dist\MRT.py>", line 3, in <module>
  File "<frozen MRT>", line 17, in <module>
ModuleNotFoundError: No module named 'PySimpleGUI'

after compiling the obfuscated source with nuitka

jondy commented 4 years ago

I'm not familiar with nuitka (pyarmor could pack the scripts with backend tool `PyInstaller). If the scripts have been obfuscated, any dependent module or package imported by the script could not be found by build tool (nuitak or PyInstaller). For PyInstaller, PyArmor does some extra work, I think nuitka need to do some extra work either, refer to https://pyarmor.readthedocs.io/en/latest/how-to-do.html#how-to-pack-obfuscated-scripts

sla-te commented 4 years ago

Yes I opened an issue over there and asked the them as well https://github.com/Nuitka/NUITKA-Utilities/issues/26

sla-te commented 4 years ago

@jondy can you participate here, nuitka is asking how to find all necessary imports:

https://github.com/Nuitka/NUITKA-Utilities/issues/26

jondy commented 4 years ago

@chwba

If i add an import above from pytransform import pyarmor_runtime I get Traceback (most recent call last): File "", line 267, in protect_pytransform File "", line 225, in check_obfuscated_script RuntimeError: unexpected obfuscated script

This exception can be eliminated by obfuscated the scripts with --no-cross-protection

pyarmor obfuscate --no-cross-protection --restrict 0 foo.py

I also check the thread you mentioned above, It seems there is no valued advice to find the hidden imports in the obfuscated scripts by nuitka automatically.

sla-te commented 4 years ago

With this additional argument and some further "magic" I was able to compile with nuitka. Can you recommend a way to speed the process up? Check here for how I am doing it at the moment: Nuitka/NUITKA-Utilities#26

jondy commented 4 years ago

Create a project to obfuscate all the scripts, for example:

cd /path/to/src
pyarmor init --src "."

This will create a project file .pyarmor_config in the current path, then config the project with multiple entries

pyarmor config --cross-protection 0 --restrict 0 --entry "foo.py,bar.py,mrt/main.py"

After that, obfuscate all the scripts to dist

pyarmor build --output dist

Once the scripts changed, just run build again

pyarmor build --output dist

I don't know why pytransform must be copied to each folder, it could be taken as a common python package with some data files and one binary library (which will be loaded by ctypes), I think one copy is enough

sla-te commented 4 years ago

Thank you for the help. Due to the structure of our app only manually obfuscating every script with the "--exact" argument worked for me.

FuckingToasters commented 2 years ago

Hello, i

Create a project to obfuscate all the scripts, for example:

cd /path/to/src
pyarmor init --src "."

This will create a project file .pyarmor_config in the current path, then config the project with multiple entries

pyarmor config --cross-protection 0 --restrict 0 --entry "foo.py,bar.py,mrt/main.py"

After that, obfuscate all the scripts to dist

pyarmor build --output dist

Once the scripts changed, just run build again

pyarmor build --output dist

I don't know why pytransform must be copied to each folder, it could be taken as a common python package with some data files and one binary library (which will be loaded by ctypes), I think one copy is enough

Hello, i ran these commands and they seem to work however when i tried to use nuitka to compile it to a executable using following command:

nuitka --warn-unusual-code --follow-imports --show-progress --assume-yes-for-downloads --standalone --plugin-enable=multiprocessing --show-modules --show-progress --mingw64 --onefile --include-package-data selenium pytransform --nofollow-import-to=importlib --no-pyi-file --experimental=use_pefile --experimental=use_pefile_recurse --run main.py

I got following issue:

__main__.py: can't find '__main__' module in 'pytransform'

I then looked up the issue in google and only found similar problems from others but their solutions did not solved my problem. I also asked the developer of nuitka and he told me, that this problem is related to pyarmor so i ask here.

fahadbashirgg commented 2 years ago

@jondy @FuckingToasters @sla-te I used some methods and wasted a lot time on pyarmor and nuikta and now i am able to Work with both same time I was working to protect my script with 4 layers but due to pyarmor trial i am able to do it only 3 layers because of it's big file not encrypting problem my script was much bytes But i tested everything pyarmor and nuikta works for me but still i have problem of pyarmor large script not encryption with trail... LoL due to this thing my one encrypting layer remaining but nuikta and pyarmor working perfectly together for me ❤️

demon071 commented 9 months ago

@jondy @FuckingToasters @sla-te I used some methods and wasted a lot time on pyarmor and nuikta and now i am able to Work with both same time I was working to protect my script with 4 layers but due to pyarmor trial i am able to do it only 3 layers because of it's big file not encrypting problem my script was much bytes But i tested everything pyarmor and nuikta works for me but still i have problem of pyarmor large script not encryption with trail... LoL due to this thing my one encrypting layer remaining but nuikta and pyarmor working perfectly together for me ❤️

Can you share how to get pyarmor to work with nuikta?