### Install Pyarmor on Windows Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/getting-started.html Use the command prompt to install or upgrade Pyarmor on Windows. ```bash C:\> pip install -U pyarmor ``` -------------------------------- ### Original Script Example Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/advanced.html An example of a Python script before RFT mode encryption. ```python import sys def sum2(a, b): return a + b def main(msg): a = 2 b = 6 c = sum2(a, b) print('%s + %s = %d' % (a, b, c)) if __name__ == '__main__': main('pass: %s' % data) ``` -------------------------------- ### Install Pyarmor from PyPI (Windows) Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/installation.html Use this command in the Windows command prompt to install Pyarmor. ```batch C:\> pip install pyarmor ``` -------------------------------- ### Example Plugin Script Source: https://pyarmor.readthedocs.io/zh/latest/_sources/reference/environments.rst.txt A simple example of a plugin script named `fooplugin.py` that prints information when the `post_runtime` method is called. ```APIDOC ## Example Plugin Script (`fooplugin.py`) ### Description This script demonstrates how to define a plugin class `EchoPlugin` with a `post_runtime` method. When this plugin is enabled and PyArmor processes runtime extensions, this method will be executed, printing details about the process. ### Code ```python __all__ = ['EchoPlugin'] class EchoPlugin: @staticmethod def post_runtime(ctx, source, dest, platform): print('-------- test fooplugin ----------') print('ctx is', ctx) print('source is', source) print('dest is', dest) print('platform is', platform) ``` ### Usage 1. Save the code as `fooplugin.py`. 2. Place it in a PyArmor configuration directory (e.g., `.pyarmor/fooplugin.py`). 3. Enable the plugin using the command: `pyarmor cfg plugins + "fooplugin"`. 4. Encrypt a script (e.g., `pyarmor gen foo.py`) to see the plugin's output. ``` -------------------------------- ### PyArmor Global Options Examples Source: https://pyarmor.readthedocs.io/zh/latest/reference/man.html Examples demonstrating the usage of global options like --silent, --debug, and --home. ```APIDOC ## PyArmor Global Options Examples ### Description Examples demonstrating the usage of global options like --silent, --debug, and --home. ### Usage Examples #### Silent Mode ``` pyarmor -q gen foo.py ``` #### Debug Mode ``` pyarmor -d gen foo.py cat pyarmor.debug.log ``` #### Setting Home Directory ##### Modifying the root directory to `~/.pyarmor2/`: ``` $ pyarmor --home ~/.pyarmor2 ... ``` This command also modifies: * Global configuration directory to `~/.pyarmor2/config/` * Directory for registration files to `~/.pyarmor2/` ##### Modifying only the global configuration directory to `~/.pyarmor/config2/`: ``` $ pyarmor --home ,config2 ... ``` ##### Modifying only the local configuration directory to `/var/myproject`: ``` > $ pyarmor --home ,,/var/myproject/ ... ``` #### Using Multiple Licenses with Different Home Directories ``` $ pyarmor --home ~/.pyarmor1 reg pyarmor-regfile-2051.zip $ pyarmor --home ~/.pyarmor2 reg pyarmor-regfile-2052.zip $ pyarmor --home ~/.pyarmor1 gen project1/foo.py $ pyarmor --home ~/.pyarmor2 gen project2/foo.py ``` #### Testing with Default Configurations ``` $ pyarmor --home ,x,x, gen foo.py ``` ### See Also `PYARMOR_HOME` ``` -------------------------------- ### Set Configuration Values Source: https://pyarmor.readthedocs.io/zh/latest/reference/man.html Examples for updating integer, boolean, and string configuration options. ```bash $ pyarmor cfg obf_module 0 $ pyarmor cfg obf_module=0 $ pyarmor cfg obf_module =0 $ pyarmor cfg obf_module = 0 ``` ```bash $ pyarmor cfg wrap_mode 0 $ pyarmor cfg wrap_mode=1 ``` ```bash $ pyarmor cfg outer_keyname "sky.lic" $ pyarmor cfg outer_keyname = "sky.lic" ``` -------------------------------- ### Check Device Compatibility for Group License Source: https://pyarmor.readthedocs.io/zh/latest/how-to/register.html Install Pyarmor trial version and run this command to get the machine identifier. Restart the device and run again to check if the identifier remains consistent, which is required for Group licenses. ```bash $ pyarmor reg -g 1 ... INFO current machine id is "mc92c9f22c732b482fb485aad31d789f1" INFO device file has been generated successfully ``` -------------------------------- ### Install PyArmor via pip (Windows) Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt On Windows, open a command prompt and use this command to install PyArmor from PyPI. ```doscon C:\> pip install pyarmor ``` -------------------------------- ### Install Pyarmor in CI/CD Source: https://pyarmor.readthedocs.io/zh/latest/how-to/ci.html Install Pyarmor using pip. Ensure you specify the version if required for compatibility. ```bash pip install pyarmor ``` ```bash # Please replace 9.X.Y with the current Pyarmor version pip install pyarmor==9.X.Y parmor reg pyarmor-ci-xxxx.zip ``` -------------------------------- ### Install PyInstaller Source: https://pyarmor.readthedocs.io/zh/latest/_sources/topic/repack.rst.txt Install PyInstaller using pip. This is a prerequisite for using PyArmor's packing features. ```console $ pip install pyinstaller ``` -------------------------------- ### Install Pyarmor on Docker Host Source: https://pyarmor.readthedocs.io/zh/latest/how-to/register.html Install Pyarmor and its core CLI on the Docker host machine. Ensure the correct wheel file for the host's Python version is used. ```bash python3 --version Python 3.8.10 pip install pyarmor.cli.core-5.4.1-cp38-none-manylinux1_x86_64.whl pip install pyarmor-8.4.1.tar.bgz ``` -------------------------------- ### Install PyArmor on Docker Host (Linux) Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/register.rst.txt Install PyArmor and its core components on a Linux Docker host to enable group license functionality for containers. ```bash python3 --version Python 3.8.10 ``` ```bash pip install pyarmor.cli.core-5.4.1-cp38-none-manylinux1_x86_64.whl pip install pyarmor-8.4.1.tar.bgz ``` -------------------------------- ### Execute Pyarmor Command via Shell Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Shows the equivalent command-line interface usage for the programmatic example. ```bash $ python tool.py ``` ```bash $ pyarmor gen -O dist --platform linux.x86_64,windows.x86_64 foo.py ``` -------------------------------- ### Install PyArmor platform-specific core packages Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Install auxiliary runtime packages for cross-platform script distribution. Choose packages based on your target platform. ```bash $ pip install pyarmor.cli.core.windows ``` ```bash $ pip install pyarmor.cli.core.themida ``` ```bash $ pip install pyarmor.cli.core.linux ``` ```bash $ pip install pyarmor.cli.core.darwin ``` ```bash $ pip install pyarmor.cli.core.freebsd ``` ```bash $ pip install pyarmor.cli.core.android ``` ```bash $ pip install pyarmor.cli.core.alpine ``` -------------------------------- ### Install Pyarmor Platform-Specific Packages Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/installation.html Install auxiliary runtime packages for cross-platform script distribution. Choose packages based on your target deployment environments. ```bash $ pip install pyarmor.cli.core.windows ``` ```bash $ pip install pyarmor.cli.core.themida ``` ```bash $ pip install pyarmor.cli.core.linux ``` ```bash $ pip install pyarmor.cli.core.darwin ``` ```bash $ pip install pyarmor.cli.core.freebsd ``` ```bash $ pip install pyarmor.cli.core.android ``` ```bash $ pip install pyarmor.cli.core.alpine ``` -------------------------------- ### Check PyArmor Version and Registration Info Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/register.rst.txt Verify the PyArmor installation and check the current registration status and license information. ```console $ pyarmor -v ``` -------------------------------- ### Run Docker Container with Host Networking Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/register.rst.txt Start a Docker container, ensuring it can communicate with the Docker host by adding the host's internal IP address. This is necessary for PyArmor authentication. ```bash $ docker run -it --add-host=host.docker.internal:host-gateway python bash ``` -------------------------------- ### Start Pyarmor Authentication Service Source: https://pyarmor.readthedocs.io/zh/latest/how-to/register.html Launch the pyarmor-auth service on the Docker host to handle authentication requests from containers. This service requires the device registration file. ```bash pyarmor-auth pyarmor-device-regfile-6000.1.zip 2023-06-24 09:43:14,939: work path: /root/.pyarmor/docker 2023-06-24 09:43:14,940: register "pyarmor-device-regfile-6000.1.zip" 2023-06-24 09:43:15,016: listen container auth request on 0.0.0.0:29092 ``` -------------------------------- ### setup.cfg 配置 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/wheel.rst.txt 配置包的元数据和包含的模块。 ```ini [metadata] name = parent.child version = attr: parent.child.VERSION [options] package_dir = =dist/ packages = parent parent.child parent.pyarmor_runtime_00xxxx include_package_data = True ``` -------------------------------- ### 构建错误堆栈 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/wheel.rst.txt setuptools 静态解析加密脚本时产生的错误。 ```python * Building sdist... Traceback (most recent call last): File "/usr/lib/python3/dist-packages/setuptools/config/expand.py", line 81, in __getattr__ return next( ^^^^^ StopIteration The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/setuptools/config/expand.py", line 191, in read_attr return getattr(StaticModule(module_name, spec), attr_name) ``` -------------------------------- ### Offline installation on Android Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Install PyArmor offline on an Android system. This requires installing the core package, the Android-specific core package, and the main PyArmor package. ```bash $ pip install pyarmor.cli.core-3.2.9.zip $ pip install pyarmor.cli.core.android-3.2.9-cp310-none-any.whl $ pip install pyarmor-8.2.9.zip ``` -------------------------------- ### Offline installation on Linux for Python 3.10 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Install PyArmor offline on a 64-bit Linux system for Python 3.10 by first installing the core package and then the main package. ```bash $ pip install pyarmor.cli.core-3.2.9-cp310-none-manylinux1_x86_64.whl $ pip install pyarmor-8.2.9.zip ``` -------------------------------- ### 封装加密包 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/getting-started.rst.txt 将加密后的包与数据文件整合,以便使用 setuptools 等工具进行分发。 ```console $ cd projects $ mkdir dist6 $ cp -a src/mypkg dist6/ $ pyarmor gen -O dist6 -i src/mypkg ``` -------------------------------- ### 使用插件自动化修改 Source: https://pyarmor.readthedocs.io/zh/latest/how-to/wheel.html 创建并启用插件以在加密后自动修改 __init__.py 文件。 ```python __all__ = ['VersionPlugin'] class VersionPlugin: @staticmethod def post_build(ctx, inputs, outputs, pack): script = os.path.join(outputs[0], 'parent', 'child', '__init__.py') with open(script, 'a') as f: f.write("\nVERSION = '0.0.1'") ``` ```bash $ pyarmor cfg plugins + "myplugin" ``` ```bash $ pyarmor gen --recursive --prefix parent.child src/parent $ python -m build --skip-dependency-check --no-isolation ``` -------------------------------- ### 配置文件内容 Source: https://pyarmor.readthedocs.io/zh/latest/how-to/wheel.html 项目所需的 MANIFEST.in, pyproject.toml 和 setup.cfg 配置文件。 ```text recursive-include dist/parent/pyarmor_runtime_00xxxx *.so ``` ```text [build-system] requires = [ "setuptools>=66.1.1", "wheel" ] build-backend = "setuptools.build_meta" ``` ```text [metadata] name = parent.child version = attr: parent.child.VERSION [options] package_dir = =dist/ packages = parent parent.child parent.pyarmor_runtime_00xxxx include_package_data = True ``` -------------------------------- ### Example Bug Report Structure for Runtime Issues Source: https://pyarmor.readthedocs.io/zh/latest/_sources/questions.rst.txt When reporting issues with running encrypted scripts, follow this structure. Include the exact command used for encryption, how to run the script, the resulting error message and stack trace, and your expected outcome. ```text 标题: [Bug] 错误描述 ### 加密脚本的完整命令 pyarmor gen ... ### 运行加密脚本以及异常信息和错误堆栈 python dist/foo.py ### 期望的结果 以及其他需要补充的相关信息 ``` -------------------------------- ### Offline installation on special architectures Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Install PyArmor on special architectures like ppc64le, mips32el, mips64el, riscv64, loongarch64. This involves installing the core Linux or Alpine package and the main PyArmor CLI package. ```bash $ pip install pyarmor.cli.core-8.5.9.zip $ pip install pyarmor.cli.core.linux-6.5.2-cp310-none-any.whl $ pip install pyarmor-8.5.9.zip ``` -------------------------------- ### Install or Upgrade Pyarmor Source: https://pyarmor.readthedocs.io/zh/latest/how-to/register.html Standard pip command to install or upgrade Pyarmor to the latest version. ```bash $ pip install -U pyarmor ``` -------------------------------- ### 自定义运行时包名称配置 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/wheel.rst.txt 修改 MANIFEST.in 和 setup.cfg 以自定义运行时包名称。 ```text recursive-include dist/parent/child/libruntime *.so ``` ```ini [options] ... packages = parent parent.child parent.child.libruntime ... ``` -------------------------------- ### Prepare and Generate Offline Device Registration File Source: https://pyarmor.readthedocs.io/zh/latest/how-to/register.html Prepare the environment by creating a directory for group files and copying the group file. Then, use the 'pyarmor reg -g' command with the path to the initial registration file to generate a device-specific offline registration file. ```bash $ mkdir -p .pyarmor/group $ cp pyarmor-group-file.1 .pyarmor/group/ $ pyarmor reg -g 1 /path/to/pyarmor-regfile-xxxx.zip ``` -------------------------------- ### Offline Installation of Pyarmor CLI Only Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/installation.html Install only the Pyarmor CLI package in an offline environment to minimize download size. ```bash $ pip install pyarmor.cli-8.2.9.zip ``` -------------------------------- ### Install PyArmor CLI only Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Install only the PyArmor CLI package to reduce download size if PyArmor 7 features are not needed. ```bash $ pip install pyarmor.cli ``` -------------------------------- ### Using Option Files Source: https://pyarmor.readthedocs.io/zh/latest/reference/man.html Reference a file containing a list of scripts and packages to encrypt using the @ prefix. ```bash pyarmor gen -r @filelist ``` ```text src/foo.py src/utils.py libs/dbpkg libs/config ``` -------------------------------- ### 配置函数排除规则 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/topic/bccmode.rst.txt 通过命令行配置 foo.py 中函数和方法的排除规则。 ```console $ pyarmor cfg -p foo bcc:excludes = "hello_a" $ pyarmor cfg -p foo bcc:excludes = "hello_a hello_b" $ pyarmor cfg -p foo bcc:excludes = "hello_*" ``` ```console $ pyarmor cfg -p foo bcc:excludes = "Test.hello_a" $ pyarmor cfg -p foo bcc:excludes = "Test.*" $ pyarmor cfg -p foo bcc:excludes = "Test.__*__" ``` ```console $ pyarmor cfg -p foo bcc:excludes = "hello_a Test.hello_a" ``` -------------------------------- ### Enable and Run Plugin Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/customization.html Commands to register the plugin and generate the obfuscated script. ```bash $ pyarmor cfg plugins + "myplugin" ``` ```bash $ pyarmor gen foo.py $ python dist/foo.py ``` -------------------------------- ### Install PyArmor via pip (Linux/macOS) Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Use this command to install PyArmor directly from PyPI on Linux and macOS systems. ```bash $ pip install pyarmor ``` -------------------------------- ### View All PyArmor Configuration Options Source: https://pyarmor.readthedocs.io/zh/latest/_sources/reference/man.rst.txt Display all available configuration items for PyArmor by running `pyarmor cfg` without any arguments. ```bash $ pyarmor cfg ``` -------------------------------- ### Install PyArmor for Specific Python Versions Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/advanced.html Installs PyArmor for Python 3.8 and Python 3.9 separately using their respective executables. ```bash $ python3.8 -m pip install pyarmor $ python3.9 -m pip install pyarmor ``` -------------------------------- ### 查看运行时扩展模块 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/getting-started.rst.txt 检查加密脚本运行所需的 pyarmor_runtime 扩展模块位置。 ```bash $ ls dist6/mypkg/pyarmor_runtime_000000 ... __init__.py ... pyarmor_runtime.so ``` -------------------------------- ### Example of Unsupported Functionality: Generator Function Source: https://pyarmor.readthedocs.io/zh/latest/_sources/topic/bccmode.rst.txt An example of a generator function that cannot be encrypted by PyArmor due to its use of unsupported features (yield). ```python def foo1(): for n range(10): yield n ``` -------------------------------- ### 模块版本定义 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/wheel.rst.txt 在 __init__.py 中定义版本号。 ```python VERSION = '0.0.1' ``` -------------------------------- ### Example of Unsupported Functionality: Async Function Source: https://pyarmor.readthedocs.io/zh/latest/_sources/topic/bccmode.rst.txt An example of an asynchronous function definition that cannot be encrypted by PyArmor due to its use of unsupported features. ```python async def nested(): return 42 ``` -------------------------------- ### Install PyArmor runtime package for Themida protection Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Install the specific runtime package required for PyArmor to protect scripts using Themida. ```bash $ pip install pyarmor.cli.themida-3.2.9-cp310-none-any.whl ``` -------------------------------- ### Install PyArmor from GitHub Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Clone the PyArmor repository from GitHub and install it locally using pip. This method is deprecated since version 8.2.9. ```bash $ git clone https://github.com/dashingsoft/pyarmor $ cd pyarmor $ pip install . ``` -------------------------------- ### Register PyArmor License (Initial) Source: https://pyarmor.readthedocs.io/zh/latest/_sources/reference/man.rst.txt Perform initial registration using a registration code file. The product name is required for non-commercial use, specify 'non-profits'. ```bash $ pyarmor reg -p NAME pyarmor-regcode-xxxx.txt ``` ```bash $ pyarmor reg pyarmor-regfile-xxxx.zip ``` -------------------------------- ### Initial License Registration Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/register.rst.txt Perform initial registration of a license by specifying the product name it will be bound to. This generates a registration file for subsequent uses. ```console $ pyarmor reg -p "EkeCloud" pyarmor-regcode-xxxx.txt ``` -------------------------------- ### 调试扩展模块导入 Source: https://pyarmor.readthedocs.io/zh/latest/topic/obfuscated-script.html 在加密脚本目录中测试扩展模块的导入情况,以排查运行环境问题。 ```bash cd dist/ python >>> import pyarmor_runtime Traceback (most recent call last): File "", line 1, in RuntimeError: the format of obfuscated script is incorrect ``` -------------------------------- ### Example of Unsupported Functionality: Frame Inspection Source: https://pyarmor.readthedocs.io/zh/latest/_sources/topic/bccmode.rst.txt An example of a function that calls `sys._getframe`, making it incompatible with PyArmor's ultimate mode encryption. ```python def foo2(): frame = sys._getframe(2) print('parent frame is', frame) ``` -------------------------------- ### Install Pyarmor Runtime for Windows on Linux Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/installation.html Install the Pyarmor runtime package on a Linux system to encrypt scripts intended to run on Windows platforms. ```bash $ pip install pyarmor.cli.windows-3.2.9-cp310-none-any.whl ``` -------------------------------- ### 自动打包模式命令 Source: https://pyarmor.readthedocs.io/zh/latest/topic/repack.html 使用 --pack 选项将加密脚本打包为单文件或单目录。 ```bash $ cd project $ pyarmor gen --pack onefile foo.py ``` ```bash $ ls dist/foo $ dist/foo ``` ```bash $ pyarmor gen --pack onedir foo.py $ ls dist/foo $ dist/foo/foo ``` -------------------------------- ### 验证脚本补丁执行 Source: https://pyarmor.readthedocs.io/zh/latest/reference/environments.html 通过绑定数据并运行加密脚本来测试 bootstrap 函数的逻辑。 ```bash $ pyarmor gen --bind-data 12345 foo.py $ python dist/foo.py user data is b'12345' Traceback (most recent call last): File "dist/foo.py", line 2, in ... RuntimeError: unauthorized use of script (1:10325) ``` -------------------------------- ### 申请管线注册文件 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/ci.rst.txt 在本地设备上申请 Pyarmor 的管线注册文件,该文件用于在 CI/CD 中注册 Pyarmor。 ```bash $ pyarmor reg -C pyarmor-regfile-xxxx.zip ``` -------------------------------- ### Install PyArmor CLI package as zip archive Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Install the PyArmor CLI package from a zip archive, which is recommended if PyArmor 7 compatibility is not needed. ```bash $ pip install pyarmor.cli-8.2.9.zip ``` -------------------------------- ### 设置 Pyarmor 7.x 兼容模式环境变量 Source: https://pyarmor.readthedocs.io/zh/latest/reference/man.html 在 Linux 或 Apple 系统中通过环境变量启用 Pyarmor 7.x 兼容模式。 ```bash export PYARMOR_CLI=7 pyarmor -h PYARMOR_CLI=7 pyarmor -h ``` -------------------------------- ### Initial License Registration Source: https://pyarmor.readthedocs.io/zh/latest/how-to/register.html Perform initial registration of a license by binding it to a product name. This generates a registration file for subsequent use. Use 'non-profits' as the product name for non-commercial use. ```bash $ pyarmor reg -p "EkeCloud" pyarmor-regcode-xxxx.txt ``` -------------------------------- ### Install PyArmor runtime package for Windows cross-platform encryption Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Install the PyArmor runtime package needed to encrypt scripts on Linux that will run on Windows. ```bash $ pip install pyarmor.cli.windows-3.2.9-cp310-none-any.whl ``` -------------------------------- ### Initial Registration for Group License Source: https://pyarmor.readthedocs.io/zh/latest/how-to/register.html Perform initial registration for a Group license on a networked device, specifying the product name. 'TBD' is not allowed for Group licenses. ```bash $ pyarmor reg -p XXX pyarmor-regcode-xxxx.txt ``` -------------------------------- ### Install a specific version of PyArmor Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/installation.rst.txt Specify a version number when installing PyArmor to use older versions. Refer to pip documentation for more version specification methods. ```bash $ pip install pyarmor==8.5.12 ``` -------------------------------- ### Initial Registration for Group License Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/register.rst.txt Perform the initial registration for a group license on a networked device, specifying the product name. 'TBD' is not allowed here. ```console $ pyarmor reg -p XXX pyarmor-regcode-xxxx.txt ``` -------------------------------- ### 集团版许可证升级 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/register.rst.txt 在联网设备上升级 Pyarmor 并为离线设备重新生成注册文件。 ```bash $ pip install -U pyarmor ``` ```bash $ pyarmor reg -g 1 /path/to/pyarmor-regfile-6000.zip ``` ```bash $ pyarmor reg pyarmor-device-regfile-6000.1.zip ``` -------------------------------- ### 临时使用默认配置 Source: https://pyarmor.readthedocs.io/zh/latest/reference/man.html 通过将配置目录指向不存在的路径,临时测试默认配置行为。 ```bash $ pyarmor --home ,x,x, gen foo.py ``` -------------------------------- ### Offline Installation on Special Architectures (e.g., ppc64le) Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/installation.html Install Pyarmor on less common architectures like ppc64le, mips32el, etc., using glibc or musl variants of the core package. ```bash $ pip install pyarmor.cli.core-8.5.9.zip ``` ```bash $ pip install pyarmor.cli.core.linux-6.5.2-cp310-none-any.whl ``` ```bash $ pip install pyarmor.cli-8.5.9.zip ``` -------------------------------- ### Install PyArmor and Register in Docker Container Source: https://pyarmor.readthedocs.io/zh/latest/_sources/how-to/register.rst.txt Install PyArmor within the Docker container and register it using the device registration file. This allows PyArmor to function within the container using the group license. ```bash pip install pyarmor.cli.core-5.4.1-cp311-none-manylinux1_x86_64.whl pip install pyarmor-8.4.1.tar.gz pyarmor reg pyarmor-device-regfile-6000.1.zip pyarmor -v ``` -------------------------------- ### 配置 PyInstaller 选项 Source: https://pyarmor.readthedocs.io/zh/latest/topic/repack.html 通过 pack:pyi_options 配置项向 PyInstaller 传递额外参数。 ```bash $ pyarmor cfg pack:pyi_options = " -w" ``` ```bash $ pyarmor cfg pack:pyi_options + " -i favion.ico" ``` ```bash $ pyarmor cfg pack:pyi_options + "--add-data joker/config.json:joker" ``` ```bash C:/User/test> pyarmor cfg pack:pyi_options + "--add-data joker/config.json;joker" ``` ```bash $ pyarmor cfg pack:pyi_options = " -w -i favion.ico --add-data joker/config.json:joker" ``` -------------------------------- ### Python Script Patch for Runtime Security Source: https://pyarmor.readthedocs.io/zh/latest/how-to/protection.html A Python script patch example designed to hook into PyInstaller's loading process to ensure its integrity. This example demonstrates how to check critical modules like `_frozen_importlib` and `pyimod03_importers`. Use with caution and adapt to your specific PyInstaller version. ```python 1# Hook script ".pyarmor/hooks/foo.py" 2 3def protect_self(): 4 from sys import modules 5 6 def check_module(name, checklist): 7 m = modules[name] 8 for attr, value in checklist.items(): 9 if value != sum(getattr(m, attr).__code__.co_code): 10 raise RuntimeError('unexpected %s' % m) 11 12 checklist__frozen_importlib = {} 13 checklist__frozen_importlib_external = {} 14 checklist_pyimod03_importers = {} 15 16 check_module('_frozen_importlib', checklist__frozen_importlib) 17 check_module('_frozen_importlib_external', checklist__frozen_importlib_external) 18 check_module('pyimod03_importers', checklist_pyimod03_importers) 19 20protect_self() ``` -------------------------------- ### 配置 __all__ 处理行为 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/topic/rftmode.rst.txt 控制 RFT 模式是否忽略 __all__ 定义。 ```console $ pyarmor cfg rft_export__all__ 0 ``` -------------------------------- ### Basic Usage of pyarmor gen Source: https://pyarmor.readthedocs.io/zh/latest/reference/man.html Examples of encrypting individual scripts, multiple files, and directories. ```bash pyarmor gen foo.py pyarmor gen foo.py goo.py koo.py pyarmor gen src/mypkg pyarmor gen src/pkg1 src/pkg2 libs/dbpkg pyarmor gen -r src/mypkg pyarmor gen -r main.py src/*.py libs/utils.py libs/dbpkg ``` -------------------------------- ### 使用 Pyarmor 加密并打包 Source: https://pyarmor.readthedocs.io/zh/latest/how-to/obfuscation.html 利用生成的 file.list 文件对脚本及其依赖库进行加密保护。 ```bash $ pyarmor gen --assert-call --assert-import --pack dist/foo/foo foo.py @file.list ``` -------------------------------- ### Import Module with Assertion Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/advanced.html Example of importing a module using `__import__` and then asserting it's armored using `__assert_armored__`. ```python m = __import__('abc') __assert_armored__(m) ``` -------------------------------- ### 跟踪 RFT 转换结果 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/topic/rftmode.rst.txt 在 Python 3.9+ 中启用跟踪以查看转换后的脚本内容。 ```console $ pyarmor cfg trace_rft 1 $ pyarmor gen --enable-rft foo.py $ ls .pyarmor/rft ``` ```console $ cat .pyarmor/rft/foo.py ``` ```console $ pyarmor cfg optimize 2 ``` -------------------------------- ### Handle `__all__` in RFT Mode Source: https://pyarmor.readthedocs.io/zh/latest/topic/rftmode.html Example showing how names defined in `__all__` are preserved and not renamed by RFT mode. ```python __all__ = ['foo'] def foo(msg): print(msg) def _private_foo(msg): print(msg) ``` -------------------------------- ### 拷贝数据文件 Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/obfuscation.html 处理加密包运行所需的数据文件。 ```bash $ mkdir dist/joker $ cp -a joker/* dist/joker $ pyarmor gen -O dist -r joker/ ``` ```bash $ pyarmor cfg data_files=* $ pyarmor gen -O dist -r joker/ ``` ```bash $ pyarmor cfg data_files="*.yaml *.json" ``` -------------------------------- ### Example of Restricted Package Import Failure Source: https://pyarmor.readthedocs.io/zh/latest/_sources/reference/man.rst.txt Demonstrates the runtime error when attempting to import a module from a restricted package that is not exposed by __init__.py. ```python import joker print('import joker should be OK') from joker import queens print('import joker.queens should fail') ``` -------------------------------- ### Enable Key Comment Plugin and Verify Source: https://pyarmor.readthedocs.io/zh/latest/tutorial/customization.html Commands to enable the comment plugin, generate a key, and inspect the resulting file header. ```bash $ pyarmor cfg plugins + "myplugin" $ pyarmor gen key -e 2023-05-06 ``` ```bash $ head -n 1 dist/pyarmor.rkey ``` -------------------------------- ### 启用 RFT 模式加密 Source: https://pyarmor.readthedocs.io/zh/latest/_sources/tutorial/advanced.rst.txt 使用 --enable-rft 选项启用 RFT 模式,该模式通过重命名函数、类和变量实现不可逆加密。 ```console $ pyarmor gen --enable-rft foo.py ``` -------------------------------- ### Register Pyarmor in CI/CD Pipeline Source: https://pyarmor.readthedocs.io/zh/latest/how-to/register.html Install the specified Pyarmor version and then register it using the pipeline registration file within a CI/CD environment. ```bash # 请替换 "9.X.Y" 为当前使用的 Pyarmor 的版本 pip install pyarmor==9.X.Y pyarmor reg pyarmor-ci-xxxx.zip ```