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 283 forks source link

How to obfuscate 2 different folders in a way that any file can run from within ? #206

Closed ptrivedi2610 closed 4 years ago

ptrivedi2610 commented 4 years ago

@jondy

I have following directory hierarchy |-DirA |------file1.py |------file2.py |-DirB |------file3.py |------file4.py |-DirC |------file5.py |------file6.py

My requirement is to obfuscate 2 directories DirA & DirB together in such a way that I can run both scripts file3.py & file4.py individually.

Currently, it breaks due to some bootstrap command. What is the command to obfucate them together ?

jondy commented 4 years ago

First obfuscate all the .py files in the DirA

pyarmor obfuscate -O dist DirA

Then obfuscate all then entry scripts in the DirB, by the option --exact, all the scripts list command will be taken as entry scripts

pyarmor obfuscate --no-runtime --exact -O dist --src DirB file3.py file4.py

About the usage of obfuscate and some examples, refer to https://pyarmor.readthedocs.io/en/latest/man.html#obfuscate

ptrivedi2610 commented 4 years ago

@jondy Thanks for the help.

Actually what I am trying to do here is as below

  1. In DirA there are multiple sub-folders. I want to obfuscate entire DirA.
  2. In DirB, there are few test-scripts that calls apis of DirA.

To obfuscate DirA, I used below command, pyarmor obfuscate --recursive --output obf/DirA DirA/init.py

I don't need to obfuscate DirB for now. When I execute files from DirB, it gives following error from one of the DirA files

File "./DirA/sub1/init.py", line 1, in pyarmor(name, file, b'\x50\x59\x41\x52\x4d\x4f\x52\x00\x00\x03\x07\x00\x42\x0d\x0d\x0a\x02\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x40\x00\x00\x00\x9b\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xec\x50\x8c\x64\x26\x42\xd6\x01\x10\x54\xca\x9c\xb6\x36\x84\x05\x6a\x0b\xf3\xc4\x16\x01\xb4\x4d\xd3\x01\x9d\xb0\x1b\xe5\x21\x4a\x30\x1c\x71\xf3\x87\x8a\x9d\x3f\x03\x44\xa5\x67\x10\x88\x8c\x4a\xfe\xa0\x24\x78\x0f\x87\x37\xea\x2b\xb6\xa7\x02\x33\xbb\xf0\xdc\xf7\x2d\xbd\xce\x51\x34\x39\x28\xc2\xed\xb0\x68\xbd\x15\x99\xba\x19\xb7\x63\xdf\x3b\x7a\x66\xc1\x69\xc8\xfb\xac\x26\x5f\xf3\xf5\xa1\x20\xfa\x1b\x12\x07\x2a\x4f\xb8\x10\xb0\x1e\xa2\xc7\x33\x27\x5a\xa6\x67\x9a\xc5\xb2\xab\x56\x83\x16\xcd\x1a\xda\x28\xbe\x10\x5c\xf9\xcb\xea\x3e\x37\x84\x90\x48\x4c\xda\xd1\x60\x44\xa3\x84\x3e\x91\x90\x29\x14\xc4\x98\xf0\x4c\x13\xf5', 1) NameError: name 'pyarmor' is not defined

There are multiple init.py files inside DirA. Is that causing the issue

jondy commented 4 years ago

In this case first create one bootstrap package pytransform_bootstrap by command runtime:

cd DirB
pyarmor runtime -O . -i

Then edit any script in DirB, insert one line:

import pytransform_bootstrap

After that, it could import any obfuscate module

Refer to https://pyarmor.readthedocs.io/en/latest/advanced.html#run-bootstrap-code-in-plain-scripts

ptrivedi2610 commented 4 years ago

@jondy Thanks, that fixed the issue