@@ -9,16 +9,13 @@ All of first,
99
1010Then following the steps below to learn how to use [ Pyarmor]
1111
12- ## Import encrypted module
13-
14- The common usage for Pyarmor is to encrypted some python modules,
15- import them in normal python environments.
12+ ## Run and Import encrypted module
1613
1714[ pybench] ( examples/pybench ) is a collection of tests that provides a
1815standardized way to measure the performance of Python
19- implementations. It's an exactly one package to verify this
20- feature. We'll encrypted 2 scripts [ Strings.py ] ( examples/Strings.py )
21- and [ Lists.py ] ( examples/Lists.py ) , then import them by pybench.
16+ implementations. It's an exactly one package to verify this feature.
17+
18+ First,
2219
2320### Generate a project capsule
2421
@@ -39,43 +36,51 @@ Generally, one capsule is only used for one project.
3936Use command "encrypt"
4037
4138``` bash
42- python pyarmor.py encrypt --with-capsule=pybench.zip --in-place --output=dist --src=examples/pybench Lists.py Strings.py
39+ python pyarmor.py encrypt --with-capsule=pybench.zip --output=dist/pybench --src=examples/pybench " *.py"
40+ python pyarmor.py encrypt --with-capsule=pybench.zip --output=dist/pybench/package --src=examples/pybench/package " *.py"
4341```
4442
4543* --with-capsule specifies project capsule generated above. It's required.
46- * --in-place tell pyarmor save encrypted files in the same path of original file
4744* --src specifies relative path of scripts
45+ * Quotation mark is required for argument "* .py", otherwise selected files is in the current path other than ** src** path.
4846
49- This command will encrypt two scripts saved to
47+ This command will encrypte all scripts of pybench and saved to "dist/pybench"
5048
5149```
52- examples/pybench/Lists.pye
53- examples/pybench/Strings.pye
50+ ls dist/pybench
51+
52+ _pytransform.dll Dict.py Lookups.py pyimcore.py systimes.py
53+ Arithmetic.py Exceptions.py NewInstances.py pyshield.key Tuples.py
54+ Calls.py Imports.py Numbers.py pyshield.lic Unicode.py
55+ clockres.py Instances.py package pytransform.py With.py
56+ CommandLine.py license.lic product.key Setup.py
57+ Constructs.py Lists.py pybench.py Strings.py
58+
5459```
5560
56- and generate some extra files in the output path "dist" :
61+ All of the .py files here are obfuscated like this :
5762
5863```
59- pyshield.key
60- pyshield.lic
61- product.key
62- * license.lic
64+ __pyarmor__(__name__, b'xxxxxxxxxxx')
65+ ```
6366
64- pyimcore.py
65- pytransform.py
66- _pytransofrm.dll or _pytransofrm.so
67+ ### Run and Imported encrypted module
68+
69+ * Edit ** dist/pybench/pybench.py** , insert a line "import pyimcore" like this:
70+
71+ ```
72+ import pyimcore
73+ __pyarmor__(__name__, b'xxx...')
74+
6775```
6876
69- ### Imported encrypted module
77+ * Run obfuscated script
7078
71- * Copy all the files in the path "dist/" to "examples/pybench"
72- * Add one line "import pyimcore" in the file "examples/pybench/pybench.py"
73- * Remove "examples/pybench/Lists.py" and "examples/pybench/Strings.py"
74- * Run pybench.py
79+ ```
80+ cd dist/pybench
81+ python pybench.py
7582
76- Both Lists.py and Strings.py are removed, they are replaced with
77- "Lists.pye" and "Strings.pye". pybench.py still works, that's what
78- pyarmor does.
83+ ```
7984
8085## Bind encrypted script to fix machine or expired it
8186
@@ -84,9 +89,9 @@ machine, or expired it at some point. Pyarmor command "license" is
8489just for this case.
8590
8691Command "encrypt" generates some extra files include "license.lic". In
87- above example, it's in the output path "dist". It's necessary to run
88- or import encrypted scripts. This file is a part of project capsule,
89- can be used in any machine and never expired.
92+ above example, it's in the output path "dist/pybench ". It's necessary
93+ to run or import encrypted scripts. This file is a part of project
94+ capsule, can be used in any machine and never expired.
9095
9196Command "license" will generate special "license.lic", which could be
9297bind to fixed machine or expired.
@@ -103,94 +108,158 @@ Now let's generate a license file bind to this machine, first got
103108
104109Run command "license"
105110```
106- python pyarmor.py encrypt --with-capsule=pybench.zip --bind-disk "100304PBN2081SF3NJ5T"
111+ python pyarmor.py license --with-capsule=pybench.zip --bind-disk "100304PBN2081SF3NJ5T"
107112```
108113
109114This command will generate a "license.lic.txt" in the current path.
110115
111116Continue above example, replace "examples/pybench/license.lic" with this "license.lic.txt"
112117```
113- cp license.lic.txt examples /pybench/license.lic
118+ cp license.lic.txt dist /pybench/license.lic
114119```
115120
116121Run pybench.py again
117122
118123``` bash
119- cd examples /pybench
124+ cd dist /pybench
120125 python pybench.py
121126```
122127
123- It should work in this machine. If you copy "examples/pybench" to
124- other machine, it will failed to run pybench.py because encrypted
125- modules "Strings.pye" and "Lists.pye" could not be imported
128+ It should work in this machine. If you copy "dist/pybench" to
129+ other machine, it will failed to run pybench.py.
126130
127131### Generate a expired license
128132```
129- python pyarmor.py encrypt --with-capsule=pybench.zip --expired-date=2018-05-30
133+ python pyarmor.py license --with-capsule=pybench.zip --expired-date=2018-05-30
130134```
131135The "license.lic.txt" generate by this command will expired on May 30, 2018
132136
133137### Combined license
134138```
135- python pyarmor.py encrypt --with-capsule=pybench.zip --expired-date=2018-05-30 --bind-disk "100304PBN2081SF3NJ5T"
139+ python pyarmor.py license --with-capsule=pybench.zip --expired-date=2018-05-30 --bind-disk "100304PBN2081SF3NJ5T"
136140```
137141
138142The "license.lic.txt" generate by this command will expired on May 30,
1391432018 and only could be used in this machine.
140144
141- ## Run encrypted script
145+ ## Examples
142146
143- [examples/queens.py](examples/queens.py) is a script to solve eight
144- queens problem. This example show you how to run encrypted queens.py
147+ ### Use odoo with obfuscated module scripts
148+
149+ There is a odoo module "odoo_web_login":
145150
146- ### Generate a project capsule
147151```
148- python pyarmor.py capsule project
152+ odoo_web_login/
153+ __init__.py
154+ mod_a.py
155+ mod_b.py
156+
157+ controller/
158+ __init__.py
159+ mod_c.py
160+
149161```
150162
151- This command will generate "project.zip" in current path.
163+ Now run the following command in the src path of Pyarmor:
152164
153- ### Encrypt script
154165```
155- python pyarmor.py encrypt --with-capsule=project2.zip --main=queens --output=examples/runtime examples/queens.py
166+ # Generate capsule at first
167+ python pyarmor.py capsule myodoo
168+
169+ # Obfuscate scripts, assume ${src} is the parent path of "odoo_web_login"
170+ python pyarmor.py encrypt --with-capsule=myodoo.zip --output=dist/odoo_web_login --src=${src}/odoo_web_login "*.py"
171+ python pyarmor.py encrypt --with-capsule=myodoo.zip --output=dist/odoo_web_login/controller --src=${src}/odoo_web_login/controller "*.py"
172+
173+ # Edit "dist/odoo_web_login/__init__.py", insert a line "import pyimcore" before the first line
174+
175+ # Copy obfuscated scripts and all extra files to ${src}. Note: it will overwrite original scripts
176+ cp dist/odoo_web_login/* ${src}/odoo_web_login
177+ cp dist/odoo_web_login/controller/* ${src}/odoo_web_login/controller
178+
179+ # Restart odoo again.
156180```
157- * --main tells pyarmor generate a wrapper script named "queens.py" in output path.
158181
159- After this command, the script "queens.py" will be encrypted and saved
160- to "examples/runtime/queens.pye" , and all the extra files to run
161- encrypted "queens.pye" in the output path "examples/runtime".
182+ ### Use py2exe with obfuscated scripts
162183
163- The file list of "examples/runtime"
184+ First install py2exe, run py2exe-0.6.9.win32-py2.7.exe
164185
186+ There is an example of py2exe: **C:/Python27/Lib/site-packages/py2exe/samples/simple**
187+
188+ Edit **setup.py**, comment line 33 if you don' t have wxPython installed
189+
190+ ```
191+ # windows = ["test_wx.py"],
192+ console = ["hello.py"],
165193```
166- pyshield.key
167- pyshield.lic
168- product.key
169- license.lic
170194
171- pyimcore.py
172- pytransform.py
173- _pytransofrm.dll or _pytransofrm.so
195+ Run py2exe,
196+
197+ ```
198+ cd C:/Python27/Lib/site-packages/py2exe/samples/simple
199+ C:/Python27/python setup.py py2exe
200+ ```
174201
175- queens.py
176- queens.pye
202+ Then encrypt python scripts
177203
204+ ```
205+ cd ${pyarmor_installed_path}
206+ C:/Python27/python pyarmor.py capsule myproject
207+ C:/Python27/python pyarmor.py encrypt --with-capsule=myproject.zip --output=dist \
208+ --src=C:/Python27/Lib/site-packages/py2exe/samples/simple \
209+ hello.py
178210```
179211
180- ### Run encrypted script
212+ Edit **dist/hello.py**, insert "import pyimcore" at the begin of this
213+ script. Only main script need this patch, all the other modules need nothing to do.
214+
215+
216+ Copy all the py file to source path **simple**
181217
182- ``` bash
183- cd examples/runtime
184- python queens.py -n 8
185218```
219+ cd dist
220+ cp pyimcore.py pytransform.py hello.py C:/Python27/Lib/site-packages/py2exe/samples/simple
186221
187- Note that this queens.py is wrapper to run encrypted queens.pye, the
188- content of it would be
222+ ```
223+
224+ Copy all the others file to py2exe's dist
225+
226+ ```
227+ cp _pytransform.dll pyshield.lic pyshield.key product.key license.lic \
228+ C:/Python27/Lib/site-packages/py2exe/samples/simple/dist
229+ ```
230+
231+ Edit **setup.py** again, add an extra line:
189232
190- ``` python
191- import pyimcore
192- from pytransform import exec_file
193- exec_file("queens.pye")
233+ ```
234+ py_modules = ["pyimcore", "pytransform"],
235+ ```
236+
237+ Patch **pytransform.py**,
238+
239+ ```
240+ 1. Comment line 188~189
241+
242+ # if not os.path.abspath('.') == os.path.abspath(path):
243+ # m.set_option('pyshield_path'.encode(), path.encode())
244+
245+ 2. Replace line 181 with
246+
247+ m = cdll.LoadLibrary('_pytransform.dll')
248+
249+ ```
250+
251+ Run py2exe again:
252+
253+ ```
254+ cd C:/Python27/Lib/site-packages/py2exe/samples/simple
255+ C:/Python27/python setup.py py2exe
256+ ```
257+
258+ Now run "hello.exe"
259+
260+ ```
261+ cd dist
262+ ./hello.exe
194263```
195264
196265# Command Line Options
0 commit comments