如何保护和编译python源代码到.so库? [英] How to protect and compile python source code into a .so library?

查看:901
本文介绍了如何保护和编译python源代码到.so库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保护我的python源代码,我知道没有绝对的保护可能,但仍然应该有一些手段,使它很难做到或相当耗时。我想要

I would like to protect my python source code, I know there is no absolute protection possible, but still there should be some means to make it difficult enough to do or quite time-consuming. I want

1)自动删除所有文档和评论。

1) to remove all documentation, comments automatically and

strong> 2)以系统地更改模块中的变量和函数的名称(混淆?),以便我可以保留一个外部接口(有意义的名称),而变量和函数的内部名称不可能发音。

2) to systematically change the names of variables and functions within a module (obfuscation?), so that I can keep an external interface (with meaningful names) while the internal names of variables and functions are impossible to pronounce.

也许最好的解决方案会使1)和2)多余,是以下

Perhaps the best solution, which would make 1) and 2) redundant, is the following:

3)有一个简单的将python模块编译为.so库的方法,它有一个清晰的界面,其他python模块?这将类似于使用distutils构建C和C ++扩展,除了源代码是python本身而不是C / C ++。这个想法是将所有的密码组织成模块,编译它们,然后将它们导入到不被认为是秘密的其余python代码中。

3) Is there a simple way to compile python modules to .so libraries, with a clear interface and which can be used by other python modules? It would be similar as building C and C++ extensions with distutils, except that the source code is python itself rather than C/C++. The idea is to organize all "secret code" into modules, compile them, and then import them in the rest of the python code which is not considered secret.

我知道一切都可以逆向工程,我认为在实用术语中,大多数普通开发人员将无法反向工程代码,即使他们能够,伦理/法律/时间的原因,会让他们三思。

Again, I am aware that everything can be reverse-engineered, I think in pragmatic terms, most of the average developers would not be able to reverse-engineer code and even if they would be able, ethical/legal/timing reasons would make them think twice if they really want to work on this.

推荐答案

正如mgilson在评论中提到的,Cython可能是你最好的选择。一般来说,你可以使用它将纯Python源代码转换为编译的扩展模块。虽然Cython的主要目的是提高性能,但使用它来实现源代码保护不应该有任何障碍。它输出的扩展模块不受任何特殊方式的限制,所以你能够从Python之前做的任何事情,你应该能够从Cython生成的扩展模块做。 Cython在支持的功能方面有一些已知的限制,可能需要解决,但总的来说,它看起来很适合于您的目的。

As mgilson mentioned in the comments, Cython is probably your best bet here. Generally speaking, you can use it to convert your pure-python source code into compiled extension modules. While the primary intent of Cython is for enhanced performance, there shouldn't be any barriers for using it for source-code protection. The extension modules it outputs aren't limited in any special ways so anything you were able to do from within Python before, you should be able to do from the Cython-generated extension modules. Cython does have a few known limitations in terms of supported features that may need to be worked around but, overall, it looks well suited to serving your purpose.

这篇关于如何保护和编译python源代码到.so库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆