Skip to content

Commit 1a5412b

Browse files
committed
Doc readonly module and usage
1 parent 2cd4095 commit 1a5412b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/tutorial/obfuscation.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@ Pyarmor 使用 :ref:`pyarmor gen` 加密不同的脚本,它提供了丰富的
164164
... import joker OK
165165
... import joker.queens
166166

167+
.. _using readonly module:
168+
169+
使用只读模式保护包
170+
------------------
171+
172+
.. versionadded:: 8.1.9
173+
174+
对于包的保护也可以使用只读模式,这种模式允许外部模块导入和使用加密包中模块,但是不允许外部模块修改加密模块的属性和方法,是一种相对简单的保护模式。
175+
176+
使用下面的配置命令启用只读模式::
177+
178+
$ pyarmor cfg readonly_module=1
179+
180+
然后在加密整个包::
181+
182+
$ pyarmor gen --enable-jit --mix-str joker/
183+
184+
简单测试一下::
185+
186+
$ cd dist
187+
$ python
188+
>>> import joker
189+
>>> dir(joker)
190+
>>> joker.aaa = 1
191+
Traceback (most recent call last):
192+
File "<stdin>", line 1, in <module>
193+
RuntimeError: protection exception (16782406)
194+
195+
如果是仅仅需要输出模块 `joker.card` 以及 `joker.__init__` ,包中的其中模块依旧需要其它保护,那么可以启用只读模式,把需要输出的模块增加到配置项 `exclude_restrict_modules` 中,然后在进行加密。例如::
196+
197+
$ pyarmor cfg readonly_module=1
198+
$ pyarmor cfg exclude_restrict_modules="joker.card joker.__init__"
199+
$ pyarmor gen --enable-jit --mix-str --assert-call --assert-import --restrict joker/
200+
201+
因为使用 `--private/restrict` 或者 `--assert-call/import` 加密的模块,默认情况下是不允许外部模块导入的,所以必须把输出模块增加到配置项 `exclude_restrict_modules` 中。
202+
167203
拷贝数据文件
168204
============
169205

0 commit comments

Comments
 (0)