逆向工程 .pyd 文件有多难? [英] How hard to reverse engineer .pyd files?

查看:200
本文介绍了逆向工程 .pyd 文件有多难?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读如何保护 Python 代码?后,我决定在 Windows 上尝试一个非常简单的扩展模块.我之前在Linux上编译过自己的扩展模块,但这是我第一次在Windows上编译.我期待得到一个 .dll 文件,但我得到了一个 .pyd 文件.文档说它们有点相同,但它必须有一个 init[insert-module-name]() 函数.

After reading How do I protect Python code? , I decided to try a really simple extension module on Windows. I compiled my own extension module on Linux before, but this is the first time I compiled it on Windows. I was expecting to get a .dll file, but instead, I got a .pyd file. Docs says they are kind of same, but it must have an init[insert-module-name]() function.

可以假设,对它们进行逆向工程与 dll 文件一样困难.如果不是,他们在从 .pyc 文件到 .dll 文件的规模上进行逆向工程的难度是多少?

Is it safe to assume, it is as hard to reverse engineer them as dll files. If not, what is their hardness to reverse engineer in a scale from .pyc file to .dll files?

推荐答案

正如您已经发现的,它们相当于具有特定结构的 DLL 文件.原则上,它们同样难以逆向工程,它们是机器代码,只需要很少的元数据,并且代码可能已经优化到无法识别.

They are, as you already found out, equivalent to DLL files with a certain structure. In principle, they are equally hard to reverse-engineer, they are machine code, need very little metadata, and the code may have been optimized beyond recognition.

但是,所需的结构,并且知道许多函数将处理 PyObject * 和其他定义良好的 CPython 类型,可能会产生一些影响.它不会真正帮助将汇编代码映射到 C(如果有的话,由于 CPython 特定的宏,它变得更加困难).主要与 Python 类型交互的代码看起来与操作 C 结构的代码大不相同(并且相对臃肿).这可能会使它更难以理解,或者它可能会泄露没有任何意义的代码,并允许逆向工程师跳过它并更早地获取您的商业机密.

However, the required structure, and knowing that many functions will be handling PyObject *s and other well-defined CPython types, may have some effect. It won't really help with mapping the assembly code to C (if anything, it gets harder due to CPython-specific macros). Code that mostly interacts with Python types will look quite different from code manipulating C structs (and comparatively bloated). This may make it even harder to comprehend, or it may give away code which does nothing interesting and allows an reverse engineer to skip over it and get to your trade secrets earlier.

这些问题都不适用于纯 C 代码(即不与 Python 交互)的代码段.你可能有很多这样的.所以最终应该不会有太大的不同.

None of these concerns apply to pieces of code which are pure C code (i.e. do not interact with Python). And you probably have a lot of those. So it shouldn't make a significant difference in the end.

这篇关于逆向工程 .pyd 文件有多难?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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