Python 代码的加密混淆

时间:2023-03-09 08:46:17
Python 代码的加密混淆

py 脚本编译成 c 文件(cython)

用 cython 将核心代码 py 模块文件转化成 .c 文件,再用 gcc 编译成 so(unix)文件,或者将其编译成 pyd(windows)文件。

编译过程:

1、服务器安装依赖

pip install python
yum install python-devel gcc

2、编写 setup.py 文件,内容如下:

from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("test.py",language_level=2)
) # 批量编译
setup(
ext_modules = cythonize(["test.py","test2.py".......],language_level=2)
)

3、运行以下命令

python setup.py build_ext --inplace