问题描述
我需要处理一个文件夹中的多个 dll 和 exe 文件,并确定我正在处理的文件类型:.NET、COM、Win32 或其他一些外星生命形式.
I need to process a number of dll's and exe files in a folder and determine what type of file I am dealing with: .NET, COM, Win32 or some other alien life form.
我一直在尝试确定检测 DLL 类型的最简单方法,您对此有何看法:
I've been trying to determine the easiest way to detect the type of a DLL, what do you think of this:
COM dll=> 我做了一个 LoadLibrary,然后 GetProcAddress 用于DllRegisterServer".如果我得到一个有效的回报,那就是一个 COM 文件.
COM dll => I do a LoadLibrary, then GetProcAddress for "DllRegisterServer". If I get a valid return, it's a COM file.
.NET dll=> 如果 dll 依赖于 MSCOREE.DLL 它总是一个 .NET dll?
.NET dll => If the dll depends on MSCOREE.DLL it's always a .NET dll?
Win32 dll=> 如果上述两个测试都失败了,那是 Win32 dll 吗?
Win32 dll => If both the above tests fail, it's a Win32 dll?
肯定有更好的方法来检测我们正在处理的 dll 类型.以上内容非常笨重,不适用于EXE文件?一定有其他我没有想到的方法.
Surely there must be a better way to detect what type of dll we are dealing with. The above is very clunky, and won't work for EXE files? There must be some other way that I am not thinking of.
理想情况下,我希望能够让解析器确定文件是用什么编译器编译的,以及它使用了哪些功能,例如 MFC、Atl、Stl 等……但我怀疑这在预反思中是可能的时代?
Ideally I'd like to be able to make the parser determine what compiler the file was compiled with, and what features it uses such as MFC, Atl, Stl etc... But I doubt that's possible in the pre-reflection era?
推荐答案
你必须检查这些文件的PE Header.所有 DLL 和可执行文件,Win32 和 .NET,都有一个 PE 头.
You must check the PE Header of these files. All DLL and executables, Win32 and .NET, have a PE header.
一个深入了解 Win32 可移植可执行文件格式
.NET 文件格式
便携式可执行文件
这篇关于如何检测 dll 的类型?(COM、.NET、WIN32)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!