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.
I've been trying to determine the easiest way to detect the type of a DLL, what do you think of this:
COM dll => I do a LoadLibrary, then GetProcAddress for "DllRegisterServer". If I get a valid return, it's a COM file.
.NET dll => If the dll depends on MSCOREE.DLL it's always a .NET dll?
Win32 dll => If both the above tests fail, it's a Win32 dll?
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.
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?
You can list function names for a specific DLL, such as user32. dll, by running a variety of command-line tools. For example, you can use dumpbin /exports user32. dll or link /dump /exports user32.
Launch depends.exe, go to File, click Open... and open the desired DLL file. In the Module section find the Module with the name of the DLL that you opened. The CPU column tells if the file was compiled for 32 bits or 64 bits.
If the DLL is listed in the Windows registry in the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\KnownDLLs key, Windows searches for the DLL in the following locations in order: The %SystemRoot%\SYSTEM32 directory. The .exe file directory. The current directory.
EXE is an extension used for executable files while DLL is the extension for a dynamic link library. 2.An EXE file can be run independently while a DLL is used by other applications. 3. A DLL file can be reused by other applications while an EXE cannot.
You must check the PE Header of these files. All DLL and executables, Win32 and .NET, have a PE header.
An In-Depth Look into the Win32 Portable Executable File Format
The .NET File Format
Portable Executable
DllRegisterServer is not required, the only required export for a COM dll is DllGetClassObject
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With