枚举 DLL 函数?
是否可以枚举 DLL 中存在的每个函数? 得到它的签名怎么样? 我可以在 C# 中执行此操作吗? 或者我必须降低级别才能做到这一点?
问候和感谢, 何塞
Is it possible to enumerate every function present in a DLL ? How about getting its signature ?
Can I do this in C# ? Or do I have to go low level to do this?
Regards and tks,
Jose
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果它是 .NET DLL RedGate 的 Reflector 可以列出方法,甚至尝试反汇编代码。 对于任何开发人员来说,它都是一个很棒的工具箱,而且是免费的
编辑:如果您尝试在运行时读取类型和方法,您将需要使用反射。 您必须加载
Assembly
和GetExportedTypes
。 然后,迭代Members
到Methods
和Properties
。 这是来自 MSDN 的一篇文章,其中有一个迭代 的示例MemberInfo
信息。 另外,这里还有一篇 MSDN 杂志文章,从 .NET 程序集中提取数据。最后,这是我编写的一个小测试方法,用于在加载的对象上执行方法。
在此示例中,ClassLibrary1 有一个 Class1 类:
下面是测试:
If it's a .NET DLL RedGate's Reflector can list the methods and even attempt to disassemble the code. It's a great item for any developer's toolbox and it's free
Edit: If you are trying to read the types and methods at runtime you'll want to use Reflection. You would have to load the
Assembly
andGetExportedTypes
. Then, iterate over theMembers
to the theMethods
andProperties
. Here is an article from MSDN that has an example of iterating over theMemberInfo
information. Also, here is an MSDN Magazine article, Extracting Data from .NET Assemblies.Finally, Here is a little test method I wrote for executing a method on a loaded object.
In this example ClassLibrary1 has one class of Class1:
And here is the test:
如果它是托管 dll:使用反射
如果它是非托管:您需要枚举 DLL 导出表
If its a managed dll: Use reflection
If its unmanaged: You need to enumerate the DLL export table
您可以使用 Dependency Walker 查看 dll 中的所有导出,这是 Microsoft 的免费程序:http ://en.wikipedia.org/wiki/Dependency_walker
You can see all of the exports in a dll by using Dependency Walker, which is a free program from Microsoft: http://en.wikipedia.org/wiki/Dependency_walker
对于常规 win32 DLL,请参阅Dumpbin 实用程序。 它包含在 Visual-C++ 中(我相信包括免费的“express”版本)。
例子:
For regular win32 DLLs, see the Dumpbin utility. It is included with Visual-C++ (including the free "express" version I believe).
example: