This is a English version of my original post in Chinese.
中文版本请看这里
Please keep the original address of the post when reprinting. http://blog.csdn.net/ir0nf1st/article/details/61962197
There are several ways to protect Python source. Some of them are not so effective and some of them are effective but with side effects. This post gives a brief analysis of these ways and then gives out a solution to effectively protect Python code without side effect.
<0x01> Source code obfuscation
I tried two source code obfuscation tools. One is pyminifier and the other one is http://pyob.oxyry.com/. These two tools work in a similar way, they rename the class/function/variables and even scramble some Python constants (for example, True, False and None). Once the source is obfuscated, it becomes difficult for human reading and understanding. But this kind of obfuscation can barely confront with simple text searching&replacement. Generally a source code obfuscator will have no effect on source protection until it supports abstract syntax tree analysis and modification. Check this post for a deeper analysis on Python source obfuscation using ASTs.
<0x02> Packing source code into executable
py2exe and PyInstaller can pack Python source and Python Interpreter into a executable, so that your Python code can be executed on a target machine without Python installation. py2exe packs source code and its dependency files into a zip file. Unzip the file and all pyc files are there and ready to be de-compiled. PyInstaller is more secure than py2exe, it supports encryption of the source with AES, but the plain-text AES key also can be easily found in the packed file.
Another choice is Cython. It enables Python and C co-existency. You can call your module written in C from Python. The C module is built into native binary code, the binary code could be X86-PE on Windows platform or ARM-elf on ARM machine running with Linux. Reverse engineering on a C module is somewhat more difficult than on Python module, so that Cython may protect your C code but not Python code. Two side effects of using Cython are:
1. The C module is built into native binary code and makes your whole application no longer platform in-dependable.
2. Developing with C is a

本文探讨了保护Python源代码的几种方法,包括源代码混淆、将源代码打包成可执行文件、定义私有Python字节码集以及字节码混淆。通过字节码混淆可以有效防止简单的反编译,但更高级的逆向工程仍可能突破。文章还提到了Cython作为保护C代码的选项,但会牺牲平台独立性和增加开发难度。
最低0.47元/天 解锁文章
1087

被折叠的 条评论
为什么被折叠?



