pyc的破解相对容易,使用cython将python文件编译成.so文件,能在一定程度上增强python源码的私密性。
编译成.so文件
- 环境准备:cython
- 测试脚本准备:test.py
#-*-coding: UTF-8 -* -
class test:
def say(self):
print 'hello'
- 脚本编译准备:
3.1 编写compile.py文件,内容如下:
#-*-coding: UTF-8 -* -
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("test.py") #注意这里推荐使用相对路径,编译出的so文件在引用其他模块时可能会出现路径问题
)
3.2 编译出的so文件(test.so)在调用compile.py时所在目录的build/lib下
使用方式
- 编写useTest.py脚本:
#-*-coding: UTF-8 -* -
from test import test #注意test.so文件要在可访问到的路径下
test.say()
- 执行验证