|
| 1 | +============ |
| 2 | + 概念和定义 |
| 3 | +============ |
| 4 | + |
| 5 | +.. highlight:: console |
| 6 | + |
| 7 | +.. _pyarmor-cli: |
| 8 | + |
| 9 | +Pyarmor 命令行工具 |
| 10 | +================== |
| 11 | + |
| 12 | +Pyarmor 命令行工具是提供了命令行操作方式的一个应用程序 |
| 13 | + |
| 14 | +.. graphviz:: |
| 15 | + :caption: 生命周期图 |
| 16 | + :align: center |
| 17 | + :name: graph-pyarmor-cli-lifecycle |
| 18 | + |
| 19 | + digraph G { |
| 20 | + node [shape=box, style=rounded] |
| 21 | + |
| 22 | + package [label="Python 包 pyarmor.cli\n发布在 PyPI"] |
| 23 | + install [label="在构建设备上面安装 pyarmor 命令\npip install pyarmor.cli"] |
| 24 | + pyarmor [label="执行命令 pyarmor\n实现 Pyarmor 的功能"] |
| 25 | + |
| 26 | + package -> install -> pyarmor |
| 27 | + } |
| 28 | + |
| 29 | +组成 |
| 30 | +---- |
| 31 | + |
| 32 | +.. graphviz:: |
| 33 | + :align: center |
| 34 | + :name: g-pyarmor-cli-components |
| 35 | + |
| 36 | + digraph G { |
| 37 | + node [shape=box, style=rounded] |
| 38 | + |
| 39 | + subgraph C { |
| 40 | + cluster=true |
| 41 | + label="子命令" |
| 42 | + style="setlinewidth(0)" |
| 43 | + |
| 44 | + init [label="pyarmor init"] |
| 45 | + env [label="pyarmor env"] |
| 46 | + build [label="pyarmor build"] |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | +功能结构图 |
| 51 | +---------- |
| 52 | + |
| 53 | +.. graphviz:: |
| 54 | + :caption: 功能结构图 |
| 55 | + :align: center |
| 56 | + :name: g-pyarmor-cli-functions |
| 57 | + |
| 58 | + digraph G { |
| 59 | + node [shape=box, style=rounded] |
| 60 | + |
| 61 | + init [label="pyarmor init"] |
| 62 | + env [label="pyarmor env"] |
| 63 | + build [label="pyarmor build"] |
| 64 | + |
| 65 | + project [label="工程"] |
| 66 | + miniscript [label="迷你型加密脚本"] |
| 67 | + rftscript [label="重构型加密脚本"] |
| 68 | + license [shape=component, label="Pyarmor 许可证", href="https://pyarmor.readthedocs.io/zh/latest/licenses.html"] |
| 69 | + joint [shape=point] |
| 70 | + |
| 71 | + init -> project [label="创建"] |
| 72 | + env -> project [label="配置"] |
| 73 | + |
| 74 | + project -> build [label="输入脚本和选项"] |
| 75 | + build -> miniscript [label="生成"] |
| 76 | + joint -> rftscript [label="生成"] |
| 77 | + |
| 78 | + build -> joint [arrowhead=none, tailport=se] |
| 79 | + license -> joint [label="解锁重构功能", arrowhead=none] |
| 80 | + } |
| 81 | + |
| 82 | +.. _project: |
| 83 | + |
| 84 | +Pyarmor 工程 |
| 85 | +============ |
| 86 | + |
| 87 | +工程是脚本和选项的集合 |
| 88 | + |
| 89 | +.. graphviz:: |
| 90 | + :align: center |
| 91 | + :name: g-project-components |
| 92 | + |
| 93 | + digraph G { |
| 94 | + node [shape=box, style=rounded] |
| 95 | + rankdir="LR" |
| 96 | + |
| 97 | + subgraph C { |
| 98 | + cluster=true |
| 99 | + label="工程" |
| 100 | + |
| 101 | + scripts [label="脚本"] |
| 102 | + modules [label="模块"] |
| 103 | + package [label="包"] |
| 104 | + |
| 105 | + rftoptions [label="重构选项", shape=diamond] |
| 106 | + } |
| 107 | + |
| 108 | + edge [style=invis] |
| 109 | + scripts -> modules -> package -> rftoptions |
| 110 | + } |
| 111 | + |
| 112 | +.. _obf-scripts: |
| 113 | + |
| 114 | +加密脚本 |
| 115 | +======== |
| 116 | + |
| 117 | +.. graphviz:: |
| 118 | + :align: center |
| 119 | + :name: g-script-types |
| 120 | + |
| 121 | + digraph G { |
| 122 | + node [shape=box, style=rounded] |
| 123 | + rankdir="LR" |
| 124 | + |
| 125 | + subgraph C { |
| 126 | + cluster=true |
| 127 | + label="加密脚本类型" |
| 128 | + style="setlinewidth(0)" |
| 129 | + |
| 130 | + std [label="标准型", href="https://pyarmor.readthedocs.io/zh/latest/tutorial/getting-started.html"] |
| 131 | + rft [label="重构型", href="#rft-script"] |
| 132 | + mini [label="迷你型", href="#mini-script"] |
| 133 | + } |
| 134 | + |
| 135 | + edge [style=invis] |
| 136 | + std -> rft -> mini |
| 137 | + } |
| 138 | + |
| 139 | +.. flat-table:: 表-1. 加密脚本类型比较表 |
| 140 | + :widths: 10 10 10 10 60 |
| 141 | + :header-rows: 1 |
| 142 | + :stub-columns: 1 |
| 143 | + |
| 144 | + * - 加密类型 |
| 145 | + - 安全性 [#]_ |
| 146 | + - 运行速度 [#]_ |
| 147 | + - 扩展模块 [#]_ |
| 148 | + - 备注 |
| 149 | + * - 标准型 |
| 150 | + - 正常 |
| 151 | + - 正常 |
| 152 | + - 需要 |
| 153 | + - 能够设置加密脚本有效期和绑定加密脚本到固定设备,其他加密脚本类型都不具备此特性,适用于大多数的情况 |
| 154 | + * - 迷你型 |
| 155 | + - 较低 |
| 156 | + - 很高 |
| 157 | + - 需要 |
| 158 | + - 不可逆程度较低,但是执行速度较高,适用于 Web 服务等类型 |
| 159 | + * - 重构型 |
| 160 | + - 最低 |
| 161 | + - 最高 |
| 162 | + - 不需要 |
| 163 | + - 和普通 Python 脚本完全一样,主要是对 Python 语句进行了重构,所以不需要额外的扩展模块,适用范围更广,包括用于 WASM,也可以继续使用任意工具,例如 Nuitka,Cython 等进一步处理 |
| 164 | + |
| 165 | +.. rubric:: Notes |
| 166 | + |
| 167 | +.. [#] 安全性主要是指加密脚本的不可逆程度 |
| 168 | +.. [#] 运行速度是指加密脚本的运行速度和没有加密之前的脚本运行速度的比较 |
| 169 | +.. [#] 运行加密脚本是否需要额外的扩展模块,除了重构型脚本之外,其他类型的都需要 |
| 170 | +
|
| 171 | +
|
| 172 | +.. _mini-script: |
| 173 | + |
| 174 | +迷你型加密脚本 |
| 175 | +-------------- |
| 176 | + |
| 177 | +迷你型加密脚本由一个普通 Python 脚本和一个扩展模块 pyarmor_mini.so 组成 |
| 178 | + |
| 179 | +例如,一个 Python 脚本 `foo.py` |
| 180 | + |
| 181 | +.. code:: python |
| 182 | +
|
| 183 | + print('Hello') |
| 184 | +
|
| 185 | +使用 Pyarmor 生成迷你型加密脚本之后,输出的 `dist/foo.py` 内容如下 |
| 186 | + |
| 187 | +.. code:: python |
| 188 | +
|
| 189 | + from pyarmor_mini import __pyarmor__ |
| 190 | + __pyarmor__(__name__, b'xxxx') |
| 191 | +
|
| 192 | +这就是一个普通的 Python 脚本,可以使用 Python 解释器直接执行 |
| 193 | + |
| 194 | +运行迷你型加密脚本需要使用下面的命令安装扩展模块 `pyarmor_mini <https://pypi.org/project/pyarmor.mini/>`_:: |
| 195 | + |
| 196 | + $ pip install pyarmor.mini |
| 197 | + |
| 198 | +.. _rft-script: |
| 199 | + |
| 200 | +重构型加密脚本 |
| 201 | +-------------- |
| 202 | + |
| 203 | +重构型加密脚本由一个普通的 Python 脚本,只是对其中的变量,函数和类,属性等进行了重命名 |
| 204 | + |
| 205 | +例如,一个 Python 脚本 `foo.py` |
| 206 | + |
| 207 | +.. code:: python |
| 208 | + :linenos: |
| 209 | +
|
| 210 | + msg = 'Hello' |
| 211 | + print(msg) |
| 212 | +
|
| 213 | +使用 Pyarmor 生成重构型加密脚本之后,输出的 `dist/foo.py` 内容如下 |
| 214 | + |
| 215 | +.. code:: python |
| 216 | + :linenos: |
| 217 | +
|
| 218 | + pyarmor__1 = 'Hello' |
| 219 | + pyarmor__2(pyarmor__1) |
0 commit comments