Using Project¶
Project is a folder include its own configuration file, which used tomanage obfuscated scripts.
There are several advantages to manage obfuscated scripts by Project:
- Increment build, only updated scripts are obfuscated since last build
- Filter obfuscated scripts in the project, exclude some scripts
- Obfuscate the scripts with different modes
- More convenient to manage obfuscated scripts
Managing Obfuscated Scripts With Project¶
Use commandinit to create a project:
cdexamples/pybenchpyarmorinit--entry=pybench.py
It will create project configuration file.pyarmor_config
inthe current path. Or create project in another path:
pyarmorinit--src=examples/pybench--entry=pybench.pyprojects/pybench
The project pathprojects/pybench will be created, and.pyarmor_config
will be saved there.
The common usage for project is to do any thing in the project path:
cdprojects/pybench
Show project information:
pyarmorinfo
Obfuscate all the scripts in this project by commandbuild:
pyarmorbuild
Change the project configuration by commandconfig.
For example, exclude thedist
,test
, the.py files in thesefolder will not be obfuscated:
pyarmorconfig--manifest"include *.py, prune dist, prune test"
The data files also could be listed in manifest, and they will be copied tooutput path when building the project. For example:
pyarmorconfig--manifest"include *.py, include config.json"pyarmorbuild
By--manifest
, the project scripts could be selected exactly, moreinformation refer to the description of the attributemanifest in the sectionProject Configuration File
Force rebuild:
pyarmorbuild--force
Run obfuscated script:
cddistpythonpybench.py
After some scripts changed, just runbuild again:
cdprojects/pybenchpyarmorbuild
Obfuscating Scripts With Different Modes¶
First configure the different modes, refer toThe Modes of Obfuscated Scripts:
pyarmorconfig--obf-mod=1--obf-code=0
Then obfuscating scripts in new mode:
pyarmorbuild-B
Obfuscating Some Special Scripts With Child Project¶
Suppose most of scripts in the project are obfuscated with restrict mode 3, buta few of them need to be obfuscated with restrict mode 2. The child project isright for this case.
First create a project in the source path:
cd/path/to/srcpyarmorinit--entryfoo.pypyarmorconfig--restrict3
Next clone the project configuration file to create a child project named.pyarmor_config-1:
cp.pyarmor_config.pyarmor_config-1
Then config the child project with special scripts, no entry script, andrestrict mode 2:
pyarmorconfig--entry"" \--manifest"include a.py other/path/sa*.py" \--restrict2 \.pyarmor_config-1
Finally build the project and child project:
pyarmorbuild-Bpyarmorbuild--no-runtime-B.pyarmor_config-1
Project Configuration File¶
Each project has a configure file. It’s a json file named.pyarmor_config
stored in the project path.
name
Project name.
title
Project title.
src
Base path to match files by manifest template string.
It could be absolute path, or relative path based on project folder.
manifest
A string specifies files to be obfuscated, same as MANIFEST.in ofPython Distutils, default value is:
global-include*.py
It means all.py files anywhere in thesrc tree matching.
Multi manifest template commands are spearated by comma, for example:
global-include*.py,exclude__mainfest__.py,prunetest
The data files also could be selected by manifest, they’ll be copied tooutput path when building the project.
Refer tohttps://docs.python.org/2/distutils/sourcedist.html#commands
is_package
Available values: 0, 1, None
When it’s set to 1, the basename ofsrc will be appended tooutput asthe final path to save obfuscated scripts, but runtime files are still inthe pathoutput
When init a project and no
--type
specified, it will be set to 1 ifentry script is__init__.py, otherwise it’s None.restrict_mode
entry
A string includes one or many entry scripts.
When build project, insert the following bootstrap code for eachentry:
frompytransformimportpyarmor_runtimepyarmor_runtime()
The entry name is relative tosrc, or filename with absolutepath.
Multi entries are separated by comma, for example:
main.py,another/main.py,/usr/local/myapp/main.py
Note that entry may be NOT obfuscated, ifmanifest does notspecify this entry.
output
A path used to save output of build. It’s relative to project path.
capsule
Warning
Removed since v5.9.0
Filename of project capsule. It’s relative to project path if it’snot absolute path.
obf_code
How to obfuscate byte code of each code object, refer toObfuscating Code Mode:
- 0
No obfuscate
- 1 (Default)
Obfuscate each code object by default algorithm
- 2
Obfuscate each code object by more complex algorithm
wrap_mode
Available values: 0, 1, None
Whether to wrap code object withtry..final block.
The default value is1, refer toWrap Mode
obf_mod
How to obfuscate whole code object of module, refer toObfuscating module Mode:
- 0
No obfuscate
- 1 (Default)
Obfuscate byte-code by DES algorithm
cross_protection
How to protect dynamic library in obfuscated scripts:
- 0
No protection
- 1
Insert protection code with default template, refer toSpecial Handling of Entry Script
- Filename
Read the template of protection code from this file other thandefault template.
runtime_path
None or any path.
When run obfuscated scripts, where to find dynamic library_pytransform. The default value is None, it means it’s within theRuntime Package or in the same path of
pytransform.py
.It’s useful when obfuscated scripts are packed into a zip file,for example, use py2exe to package obfuscated scripts. Setruntime_path to an empty string, and copyRuntime Files tosame path of zip file, will solve this problem.
plugins
None or list of string
Extend license type of obfuscated scripts, multi-plugins aresupported. For example:
plugins:["check_ntp_time","show_license_info"]
About the usage of plugin, refer toUsing Plugin to Extend License Type
package_runtime
How to save the runtime files:
- 0
Save them in the same path with the obufscated scripts
- 1 (Default)
Save them in the sub-pathpytransform as a package
enable_suffix
Note
New in v5.8.7
How to generate runtime package (module) and bootstrap code, it’s useful asimporting the scripts obfuscated by different developer:
- 0 (Default)
There is no suffix for the name of runtime package (module)
- 1
The name of runtime package (module) has a suffix, for example,
pytransform_vax_00001
platform
Note
New in v5.9.0
A string includes one or many platforms. Multi platforms are separated bycomma.
Leave it to None or blank if not cross-platform obfuscating
license_file
Note
New in v5.9.0
Use this license file other than the default one.
Leave it to None or blank to use the default one.
bootstrap_code
Note
New in v5.9.0
How to generateBootstrap Code for the obfuscated entry scripts:
- 0
Do not insert bootstrap code into entry script
- 1 (Default)
Insert the bootstrap code into entry script. If the script name is
__init__.py
, make a relative import with leading dots, otherwise makeabsolute import.- 2
The bootstrap code will always be made an absolute import without leadingdots in the entry script.
- 3
The bootstrap code will always be made a relative import with leading dotsin the entry script.