You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/man.rst
+23-9Lines changed: 23 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,7 +149,7 @@ Generate obfuscated scripts and all the required runtime files.
149
149
--assert-import assert module is obfuscated :option:`... <--assert-import>`
150
150
--assert-call assert function is obfuscated :option:`... <--assert-call>`
151
151
152
-
--pack BUNDLE repack bundle with obfuscated scripts :option:`... <--pack>`
152
+
--pack <onefile|onedir>Obfuscate scripts then pack:option:`... <--pack>`
153
153
154
154
--use-runtime PATH use shared runtime package :option:`... <--use-runtime>`
155
155
@@ -562,19 +562,33 @@ The function :func:`__assert_armored__` is a builtin function in obfuscated scri
562
562
563
563
This option neither touches statement ``from import``, nor the module imported by function ``__import__``.
564
564
565
-
.. option:: --packBUNDLE
565
+
.. option:: --pack<onefile,onedir>
566
566
567
-
Repack bundle with obfuscated scripts
567
+
Obfuscate script first, then pack the obfuscated scripts to bundle
568
568
569
-
Here ``BUNDLE`` is an executable file generated by PyInstaller_
569
+
.. versionchanged:: 8.5.4
570
570
571
-
Pyarmor just obfuscates the script first.
571
+
Before v8.5.4, user need first generate an executable file by PyInstaller_
572
572
573
-
Then unpack the bundle.
573
+
Now everything is done by Pyarmor
574
574
575
-
Next replace all the ``.pyc`` in the bundle with obfuscated scripts, and append all the :term:`runtime files` to the bundle.
575
+
The old method still works, but it's deprecated.
576
576
577
-
Finally repack the bundle and overwrite the original ``BUNDLE``.
577
+
Once this option is used, pyarmor will analysis the source of main script, and find all the imported modules and packages which are in the same path of main script. All of these used modules and packages will be obfuscated automatically
578
+
579
+
Then pyarmor will call PyInstaller_ to pack the obfuscated scripts to one file or one folder bundle.
580
+
581
+
For example, generate one file bundle::
582
+
583
+
pyarmor gen --pack onefile foo.py
584
+
585
+
ls dist/
586
+
587
+
Sometimes it need specify option :option:`-r` to make sure all the child packages are obfuscated. For example::
588
+
589
+
pyarmor gen --pack onefolder -r foo.py
590
+
591
+
.. seealso:: :doc:`../topic/repack`
578
592
579
593
.. option:: --use-runtimePATH
580
594
@@ -759,7 +773,7 @@ Set option to boolean value::
759
773
$ pyarmor cfg wrap_mode 0
760
774
$ pyarmor cfg wrap_mode=1
761
775
762
-
Set option to string value::
776
+
Set option to string value, it must leave blank around ``=``::
Copy file name to clipboardExpand all lines: docs/topic/repack.rst
+96-14Lines changed: 96 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,29 +6,86 @@ Insight Into Pack Command
6
6
7
7
.. program:: pyarmor gen
8
8
9
-
Pyarmor 8.0 has no command pack, but option :option:`--pack`. It could specify an executable file generated by PyInstaller_::
9
+
Pyarmor 8.0 has no command pack, but option :option:`--pack`, once it's set, pyarmor will automatically pack the scripts into one bundle.
10
10
11
-
pyinstaller foo.py
12
-
pyarmor gen --pack dist/foo/foo foo.py
11
+
Packing Scripts Automatically
12
+
=============================
13
13
14
-
If this option isn't set, pyarmor only obfuscates the scripts.
14
+
.. versionadded:: 8.5.4
15
15
16
-
If this option is set, pyarmor first obfuscates the scripts, then does extra work:
16
+
It accept 2 values: ``onefile`` and ``onedir``, just as PyInstaller_
17
17
18
-
* Unpacking this executable to a temporary folder
19
-
* Replacing the scripts in bundle with obfuscated ones
20
-
* Appending runtime files to the bundle in this temporary folder
21
-
* Repacking this temporary folder to an executable file and overwrite the old
18
+
Actually Pyarmor need call PyInstaller_ to generate final bundle, so first install PyInstaller_::
22
19
23
-
In Darwin, let obfuscated scripts work in both intel and Apple Silicon by extra option ``--platform darwin.x86_64,darwin.arm64``::
20
+
pip install pyinstaller
24
21
25
-
pyarmor gen --pack dist/foo/foo --platform darwin.x86_64,darwin.arm64 foo.py
22
+
Suppose our project tree like this::
26
23
27
-
.. important::
24
+
project/
25
+
├── foo.py
26
+
├── queens.py
27
+
└── joker/
28
+
├── __init__.py
29
+
├── queens.py
30
+
└── config.json
28
31
29
-
Only listed scripts are obfuscated, if need obfuscate more scripts and sub packages, list all of them in command line. For example::
32
+
Let's check what happens when the following commands are executed::
30
33
31
-
pyarmor gen --pack dist/foo/foo -r *.py dir1 dir2 ...
34
+
cd project
35
+
pyarmor gen --pack onefile foo.py
36
+
37
+
1. Pyarmor first open `foo.py`, then find it need `queens.py` and package `joker`
38
+
2. Then obfuscate all of them to one temporary path `.pyarmor/pack/dist`
39
+
3. Next pyarmor call PyInstaller with plain script `foo.py`, to get all the system packages used by `foo.py`, and save all of them to hiddenimports table.
40
+
4. Finally pyarmor call PyInstaller again but with obfuscated scripts and all of hidden imports to generate final bundle.
41
+
42
+
Now let's run the final bundle, it's `dist/foo` or `dist/foo.exe`::
43
+
44
+
ls dist/foo
45
+
dist/foo
46
+
47
+
If need one folder bundle, just pass `onedir` to pack::
48
+
49
+
pyarmor gen --pack onedir foo.py
50
+
ls dist/foo
51
+
dist/foo/foo
52
+
53
+
Checking Obfuscated Scripts Have Been Packed
54
+
--------------------------------------------
55
+
56
+
Add one line in the script ``foo.py`` or ``joker/__init__.py``
57
+
58
+
.. code-block:: python
59
+
60
+
print('this is __pyarmor__', __pyarmor__)
61
+
62
+
If it's not obfuscated, the final bundle will raise error. Because builtin name ``__pyarmor__`` is only available in the obfuscated scripts.
63
+
64
+
Using More PyInstaller Options
65
+
------------------------------
66
+
67
+
If need extra PyInstaller options, using configuration item ``pack:pyi_options``. For example, reset it with one PyInstaller option ``-w``::
68
+
69
+
pyarmor cfg pack:pyi_options = "-w"
70
+
71
+
Let's append another option ``-i``, note that it must be one whitespace between option ``-i`` and its value, do not use ``=``. For example::
In Darwin, let obfuscated scripts work in both intel and Apple Silicon by extra option ``--platform darwin.x86_64,darwin.arm64``::
85
+
86
+
pyarmor gen --pack onefile --platform darwin.x86_64,darwin.arm64 foo.py
87
+
88
+
You can use any other obfuscation options to improve security, but some of them may not work. For example, :option:`--restrict` can't be used with :option:`--pack`.
32
89
33
90
Packing obfuscated scripts manually
34
91
===================================
@@ -134,6 +191,31 @@ If it's not obfuscated, the final bundle will raise error.
134
191
.. [#] Just let PyInstaller could find runtime package without extra pypath
135
192
.. [#] Most of the other PyInstaller options could be used here
136
193
194
+
Packing with PyInstaller Bundle
195
+
===============================
196
+
197
+
.. deprecated:: 8.5.4
198
+
199
+
Use :option:`--pack` ``onefile`` or ``onedir`` instead.
200
+
201
+
The option :option:`--pack` also could accept an executable file generated by PyInstaller_::
202
+
203
+
pyinstaller foo.py
204
+
pyarmor gen --pack dist/foo/foo foo.py
205
+
206
+
But only PyInstaller < 6.0 works by this method. If this option is set, pyarmor first obfuscates the scripts, then:
207
+
208
+
* Unpacking this executable to a temporary folder
209
+
* Replacing the scripts in bundle with obfuscated ones
210
+
* Appending runtime files to the bundle in this temporary folder
211
+
* Repacking this temporary folder to an executable file and overwrite the old
212
+
213
+
.. important::
214
+
215
+
Only listed scripts are obfuscated, if need obfuscate more scripts and sub packages, list all of them in command line. For example::
216
+
217
+
pyarmor gen --pack dist/foo/foo -r *.py dir1 dir2 ...
Copy file name to clipboardExpand all lines: docs/tutorial/obfuscation.rst
+20-16Lines changed: 20 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -286,41 +286,45 @@ And then obfuscate the scripts again.
286
286
Packing obfuscated scripts
287
287
==========================
288
288
289
-
Pyarmor need PyInstaller to pack scripts first, then replace plain scripts with obfuscated ones in bundle.
289
+
Pyarmor need PyInstaller to pack the obfuscated scripts, so first make sure PyInstaller has been installed. If not, simple install it by this command::
290
+
291
+
pip install pyinstaller
290
292
291
293
Packing to one file
292
294
-------------------
293
295
294
-
First packing script to one file by PyInstaller with option ``-F``::
296
+
.. versionchanged:: 8.5.4
297
+
298
+
Before v8.5.4, it need more work, please check old version documentation (v8.5.3).
295
299
296
-
$ pyinstaller -F foo.py
300
+
Packing script to one file only need one command::
297
301
298
-
It generates one bundle file ``dist/foo``, pass this to pyarmor::
302
+
pyarmor gen --pack onefile foo.py
299
303
300
-
$ pyarmor gen -O obfdist --pack dist/foo foo.py
304
+
Run the final bundle::
301
305
302
-
This command will obfuscate ``foo.py`` first, then repack ``dist/foo``, replace the original ``foo.py`` with ``obfdist/foo.py``, and append all the runtime files to bundle.
306
+
dist/foo
303
307
304
-
The final output is still ``dist/foo``::
308
+
Pyarmor will automatically obfuscate `foo.py` and all the other used modules and packages in the same path, then pack the obfuscated to one bundle.
305
309
306
-
$ dist/foo
310
+
.. important::
311
+
312
+
Please pass plain script in command line, for example, `foo.py` should not been obfuscated.
307
313
308
314
Packing to one folder
309
315
---------------------
310
316
311
-
First packing script to one folder by PyInstaller::
312
-
313
-
$ pyinstaller foo.py
317
+
.. versionchanged:: 8.5.4
314
318
315
-
It generates one bundle folder ``dist/foo``, and an executable file ``dist/foo/foo``, pass this executable to pyarmor::
319
+
Before v8.5.4, it need more work, please check old version documentation (v8.5.3).
316
320
317
-
$ pyarmor gen -O obfdist --pack dist/foo/foo foo.py
321
+
Packing script to one folder::
318
322
319
-
Like above section, ``dist/foo/foo`` will be repacked with obfuscated scripts.
323
+
pyarmor gen --pack onefolder foo.py
320
324
321
-
Now run it::
325
+
Run the final bundle::
322
326
323
-
$ dist/foo/foo
327
+
dist/foo/foo
324
328
325
329
More information about pack feature, refer to :doc:`../topic/repack`
0 commit comments