如何检查PE文件(DLL、EXE)是否是COM组件?
我需要编写一个存根模块,当给定 PE(DLL/EXE)作为输入时,它将确定它是普通的 Win32 DLL/EXE 还是 COM DLL/EXE。我需要以编程方式确定这一点。
是否有任何用于此目的的 Windows API?
I need to write a stub module which, when given a PE (DLL/EXE) as input, will determine whether it is a normal Win32 DLL/EXE or COM DLL/EXE. I need to determine this programatically.
Are there any Windows APIs for this purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑这很难做到接近 100% 的准确度。但有一些想法:
COM DLL 将导出 DllRegisterServer 和 DllUnregisterServer 等函数。您可以使用 LoadLibrary() 加载 Dll,然后使用 GetProcAddress() 检查这些函数是否存在。如果它们在那里,那么它很可能是一个 COM dll。
普通的 win32 Dll 将导出 DllMain。您可以使用相同的技术来检查这一点。如果您找到它,那么它很可能是 win32。
我不知道有什么方法可以发现 exe 是否是 COM 服务器。使用 ATL 编写的服务器通常在其资源表中嵌入一个注册脚本,但它们不是必须的。而且你不需要使用ATL来编写COM服务器。使用“无注册表 com”的服务同样会有一个嵌入式清单。您可以扫描注册表(在 HKLM/Classes/Software/ 下)以查看该 exe 是否已注册,但该 exe 可能正在使用无注册表的 com,或者只是尚未注册。
希望有帮助。
I suspect that this is something that would be very hard to do with near 100% accuracy. Some thoughts though:
A COM DLL will export functions like DllRegisterServer and DllUnregisterServer. You could use LoadLibrary() to load the Dll, and then GetProcAddress() to check for the presence of these functions. If they're there then its highly likely that its a COM dll.
A plain win32 Dll will export DllMain. You could use the same technique to check for that. If you find it then its very likely that its win32.
I'm not aware of a way to discover if an exe is a COM server. Servers written using ATL often have a registration script embedded in their resource table, but they don't have to. And you don't need to use ATL to write a COM server. Services using "registry-less com" will similarly have an embedded manifest. You could scan the registry (below HKLM/Classes/Software/) to see if the exe is registered, but it may be that the exe is using registry-less com or just hasn't been regisered yet.
Hope that helps.
对于传统的 COM DLL,您可以查找众所周知的导出方法(在 msdn 上搜索这些方法)
我不确定 EXE COM 服务器,因为它们通常使用命令行参数进行注册/注销以及类对象EXE 启动时调用 CoRegisterClassObject。
大多数 COM 服务器传统上也在注册表中注册,但您现在可以创建免注册服务器。
您是否也在寻找带有一些 COM 可见类的 .NET 程序集?
For traditional COM DLL, you can look for the wellknown exported methods (search on msdn for these methods)
I am not sure about EXE COM servers though because they generally use command line parameters for registration/unregistration and for class object usually calls CoRegisterClassObject when the EXE starts.
Most of the COM servers traditionally also registered in the Registry but you can create registration free servers now.
Are you also looking for a .NET assembly with some COM visible classes?