将 cython 扩展反编译回 python
我使用 cythonize 来编译我的 python 模块。这种方式提高了代码速度,并且代码也无法被开发人员阅读。但是我怀疑某些 python 开发人员是否可以破解 cython 模块来破解代码。
问题是,有人可以将它们反编译回 python 或其他可读格式来破解代码吗?
I have used cythonize to compile my python modules. This way speed of code is increased and also the code can not be read by developers. However I have doubts if some python developer can crack that cython module to hack the code.
Question is, can someone decompile them back to python or other readable format to crack the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有 C 反编译器可以将 Cython 扩展恢复为(在某种程度上可读)C。它不会与 Cython 生成的 C 代码相同,但很可能可以计算出算法的详细信息。您将无法很容易地将其恢复为原始的 Python/Cython 代码(但考虑到 Cython 以相当可预测的方式生成代码,这可能是可能的......)
特别是,像字符串常量这样的事情将相当容易从C文件中提取(甚至直接从so文件中提取)。由于许多 Python 代码都是基于字符串常量的属性查找(例如
np.ones(...)
使用字符串常量"np"
查找全局变量,然后使用字符串常量"ones"
查找属性,然后查找PyObject_Call
的一些变体),那么该代码将相当容易反编译。因此,典型的 Cython 扩展模块可能比典型的 C 程序更容易反编译。简而言之,您应该假设:
There are C decompilers which will get the Cython extension back to (somewhat readable) C. It won't be the same C code that Cython generated, but it will likely be possible to work out the details of your algorithm. You wouldn't be able to get it back to the original Python/Cython code very easily (but given that Cython generates code in a fairly predictable way it might be possible...)
In particular, things like string constants will be fairly easy to extract from the C file (or even directly from the so file). Since a lot of Python code is based around attribute lookups from string constants (e.g.
np.ones(...)
looks up a global with the string constant"np"
, then looks up an attribute with the string constant"ones"
, then some variation ofPyObject_Call
), then that code will be fairly easy to decompile. Because of this, a typical Cython extension module is probably a little easier to decompile than a typical C program.In short you should assume: