dashingsoft / pyarmor

A tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.

Home Page:http://pyarmor.dashingsoft.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] `RuntimeError: unauthorized use of script (1:1102)`

printpal-io opened this issue · comments

I am obfuscating my code with Pyarmor first, and then trying to Cythonize it to .so file.

I am Pyarmoring the code with the following command:

pyarmor gen -O dist2 src/* --enable-jit --mix-str --obf-code 2 --assert-call --private

These are the files that get Pyarmored:

src/
    main.py
    pw/ 
        utils.py
        interface.py
        core.py
        infer.py

after which, I am able to run my script by calling python3 main.py

I then Cythonize my code with the following:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [
    Extension("pw.utils",  ["pw/utils.py"]),
    Extension("pw.core",  ["pw/core.py"]),
    Extension("pw.infer",  ["pw/infer.py"]),
    Extension("pw.interface",  ["pw/interface.py"])#,
]

for e in ext_modules:
    e.cython_directives = {'language_level': "3"}

setup(
    name = 'PrintWatch',
    cmdclass = {'build_ext': build_ext},
    ext_modules = ext_modules
)

After which, the code will not run when I call python3 main.py:

File "<frozen __main__>", line 4, in <module>
  File "<frozen main>", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1116, in exec_module
  File "<frozen pw.core>", line 228, in _call_with_frames_removed
  File "pw/core.py", line 3, in init pw.core
RuntimeError: unauthorized use of script (1:1102)

I have set the restrict_mode 0 in the config, it still has this issue. I believe it may have something to do with asserting import and private, since we cythonize the files to .so after pyarmor obfuscation. My application requires none of the code to be readable or importable, so the private and assert call/import must be enabled. Is there a way to generate the outputs as .so files?

The recommend way is using --enable-bcc with --assert etc. Do not use Cython, because it just converts the following 2 statements to C code:

from pyarmor_runtime_xxxx import __pyarmor__
__pyarmor__(...)

The recommend way is using --enable-bcc with --assert etc. Do not use Cython, because it just converts the following 2 statements to C code:

from pyarmor_runtime_xxxx import __pyarmor__
__pyarmor__(...)

Using --enable-bcc causes my script to fail self-authentication but I can try again. I am currently doing the pyarmor obfuscation --> packing with pyinstaller:
pyarmor -d gen --mix-str --assert-call --assert-import --private --pack dist/main/main main.py.

Would this suffice or do you recommend taking more steps?