是否可以重新创建 C++使用给定的 .dll/.so/.dylib 需要头文件吗?
是否可以重新创建使用给定 .dll/.so/.dylib 所需的 C++ 头文件?
如果是的话,人们会如何去做呢?
Is it possible to recreate the C++ header files needed to use a given .dll/.so/.dylib?
If it is, how would one go about doing that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一般来说,没有。头文件中有很多动态库中没有的信息(结构布局、数字常量等)。
如果库导出“修饰的”C++ 函数名称,您也许能够恢复一些函数参数信息。然而,即使这样,您也无法获得足够的信息来重建有用的头文件。
如果库导出未修饰的名称(使用
extern "C"
),那么您就很不走运了。此时您所知道的只是函数名称。In general, no. There is a lot of information in header files (structure layouts, numeric constants, etc) that are not available in the dynamic library.
You may be able to recover some function parameter information if the library exports "decorated" C++ function names. However, even with that, you won't be able to get enough information to reconstruct a useful header file.
If the library exports undecorated names (with
extern "C"
), then you're pretty much out of luck. All you know at that point is the function names.这就是所谓的逆向工程,它本身并不是一件容易的任务,由于 C++ 名称修改,获取函数名称和参数很容易,但恢复库使用的其他数据(例如枚举、常量和#defines)可能有点困难。痛苦,因为该数据将嵌入到库的程序集中。
That's called reverse engineering, and by itself is not an easy task, getting the function names and parameters is easy because of C++ name mangling, but recovering other data such as enumerations, constants and #defines used by the library can be a bit of a pain, because that data will be embedded into the assembly of the library.
为了扩展 Matias 的答案,逆向工程需要一些不同主题的知识。对于初学者来说,至少必须进行基本的组装。根据您正在做的事情的复杂程度,您需要学习越来越多的知识,但至少要了解该语言的基础知识。第二件事是调试。有多种工具可以帮助您,Windows 上最著名的可能是 OllyDBG,在 Linux 上我喜欢 EDB 或 Evan's Debugger。您最不需要的就是一个好的反汇编程序,例如 IDA Pro(价格昂贵,但我相信有一个免费版本)。如果您确实对逆向工程感兴趣,可以通过大量书籍和在线资源来了解逆向工程。祝你好运!
To expand on Matias' answer, reverse engineering requires a few different topics of knowledge. For starters, at least basic assembly is a must. You'll need to learn more and more depending on the complexity of what you're doing but at least understand the basics of the language. The second thing is debugging. There are various tools to assist you, probably the most prominent on Windows is OllyDBG, on Linux I like EDB or Evan's Debugger. The last thing you'll need is a good disassembler such as IDA Pro (pricey but there's a free version I believe). There's plenty of books and online resources to learn about reverse engineering if you're really interested in it. Good luck!