获取 DLL 中导出函数的签名

发布于 2024-07-10 12:40:33 字数 410 浏览 6 评论 0原文

是否可以从 DLL 获取导出(C 风格?)函数的签名(参数计数/类型、返回类型)? 我可以使用 DLL 导出查看器 查看函数名称、地址、序数等列表但我看不到签名。 我只有 dll 文件,没有 .h 和 .def 文件。

更新:使用名为API Monitor的工具,我可以附加到使用提到的 dll 并查看对函数的调用。 这让我可以看到参数的数量、返回值及其整数值(指针?),但这并没有多大帮助。 我可能应该找到一种方法来确定这些指针在调用时指向的结构类型。

Is it possible to get an exported (C style?) function's signature (parameter count/types, return type) from a DLL? I can view the list of function names, addresses, ordinals, etc. with DLL Export Viewer but I can't view the signatures. I only have the dll file and don't have neither .h nor .def files.

UPDATE: Using a tool called API Monitor, I can attach to a process that uses the mentioned dll and see the calls to the functions. This lets me to see the number of parameters, return value and their integer values (pointers?) but this doesn't help a lot. I probably should find a way to determine what type of structures those pointers are pointing to at the call time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

长不大的小祸害 2024-07-17 12:40:33

DLL 不存储它们导出的函数的签名。 其他答案提到了 C++,当 C++ 函数导出为 C++ 时,名称确实会被破坏。 使用正确的编译器的损坏方案对其进行损坏,您将获得签名。 但大多数 DLL 不使用其 C++ 名称导出 C++ 函数。 相反,DLL 选择导出的函数是使用 C 样式名称导出的,因此即使 DLL 是用 C++ 编写的,导出的函数仍然不会有任何签名信息。

你没有标题吗? 大多数供应商都在他们的 SDK 中包含了此类内容。 如果您没有收到,请向供应商投诉。 如果你不应该得到一个,那么也许你以错误的方式完成你的任务; 你确定你应该直接使用那个DLL吗?

如果您没有头文件,那么您可能还会问自己是否真的合法地允许您在程序中使用 DLL。 如果它只是您在系统上找到的任意 DLL,那么即使您可以为其编写代码,在发布程序时也可能不允许重新分发它。

DLLs do not store the signatures of the functions they export. Other answers have mentioned C++, and when a C++ function is exported as C++, then the name will indeed be mangled. Demangle it with the right compiler's mangling scheme, and you'll have the signature. But most DLLs do not export C++ functions using their C++ names. Instead, the functions a DLL chooses to export are exported using C-style names, so even if the DLL was written in C++, the exported functions still won't have any signature information.

You don't have the header? Most vendors include that sort of thing in their SDKs. If you didn't get one, then complain to the vendor. If you weren't supposed to get one, then maybe you're going about your task the wrong way; are you sure you're supposed to use that DLL directly?

If you do not have the header file, then you might also ask yourself whether you're really allowed, legally, to use the DLL in your program anyway. If it's just an arbitrary DLL you found on your system, then even if you can write code for it, you're probably not allowed to redistribute it when you ship your program.

风筝在阴天搁浅。 2024-07-17 12:40:33

对于 C 函数,此信息根本不存储在 DLL 中。 我唯一可以建议的是反汇编该函数并查看它如何与堆栈上的变量交互,然后尝试确定签名。

祝你好运!

For C functions, this information is not stored in the DLL at all. The only thing I can suggest is to disassemble the function and look at how it interacts with variables on the stack and then try to determine the signature.

Good luck!

浅紫色的梦幻 2024-07-17 12:40:33

在 C++ 中,函数签名以依赖于编译器的方式“mangled”到名称中。 这在 C 中不会发生。因此,如果 DLL 中有 C 函数,您将看到未损坏的名称。 如果它是 C++ 的,你会看到损坏的。

C++ 需要重整名称以允许链接器解析具有不同签名的重载函数。

我认为没有任何方法可以从“C”DLL 中获取函数签名。 他们根本不存在。

In C++, the function signatures are "mangled" into the name in a compiler-dependent way. This doesn't happen in C. So, if you have C functions in your DLL, you'll see unmangled names. If it's a C++ one, you'll see mangled ones.

C++ needs mangled names to allow the linker to resolve overloaded functions with different signatures.

I don't think there's any way for you to get the function singatures from a "C" DLL. They simply aren't present.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文