如何加密python代码

王盈 [email protected]
发件人当地时间 发送时间 08:09 (GMT+08:00)。发送地当前时间:上午8:19。 ✆
回复      [email protected]
发送至     [email protected]
日期      2011年7月20日 上午8:09
主题      Re: [CPyUG] Re: 如何加密python代码?

这几天也碰到类似的问题。需要实现不能自由拷贝,锁定在特定计算机上运行。 我用的方法是:cython + mingw32 + VMProtect

用cython把.py的python源文件转换成C然后修改这个C的源程序, 加入

#include "VMProtectSDK.h"
VMProtectBeginUltra("xxx");
VMProtectGetCurrentHWID(hwid_buf,100);
....

等用于保护和硬件特征的校验代码。 然后再用mingw32编译,

c:\mingw\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python26\include 
    -IC:\Python26\PC -c hello.c 
    -o build\temp.win32-2.6\Release\hello.o
    c:\mingw\bin\gcc.exe -mno-cygwin -shared 
    -s build\temp.win32-2.6\Release\hello.o build\temp.win32-2.6\Release\hello.def 
    -LC:\Python26\libs -LC:\Python26\PCbuild -lpython26 
    -lmsvcr90 VMProtectSDK32.lib -o hello.pyd
 

最后用VMProtect加壳处理,让VMProtectGetCurrentHWID等函数生效。

请大家批评指正! 违背了开源精神,我有罪!


反馈

创建 by -- ZoomQuiet [2011-07-20 00:21:57]

MiscItems/2011-07-20 (last edited 2011-07-20 00:21:56 by ZoomQuiet)