Useful DLL utilities on Windows

A current project involves moving from a 32 bit to 64 bit system.  Some self contained exes are required to remain 32 bit while the rest of the system will move to 64 bit.  Some .NET assemblies are also “any cpu”.

As in all cases where the projects get complicated and you inherit code, it is easy to lose what gets installed where especially of different types (32 bit, 64 bit,  any-cpu).

DLL Information using Dumpbin.exe

To get the dump of all the DLL headers recursing all subdirectories, the following is useful in a command prompt.

for /f "tokens=*" %i in ('dir /s /b /a-d *.dll') do call dumpbin.exe /headers "%i"

If you use dumpbin.exe and need to move it to a target machine, you will also need to copy link.exe and mspdb100.dll.  (This version is Visual Studio 2010 and located in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64.  I was targeting a 64 bit machine.)

Notice that a .NET assembly set to “any cpu” will look like a 32 bit assembly.

Part of the output looks like this:

Dump of file C:\turd.dll

PE signature found

File Type: DLL

14C machine (x86)
3 number of sections
4F6A184B time date stamp Wed Mar 21 14:04:59 2012
0 file pointer to symbol table
0 number of symbols
E0 size of optional header
2102 characteristics
32 bit word machine

10B magic # (PE32)
8.00 linker version
2A000 size of code

.NET Assembly Type using Corflags.exe

An equally useful feature is to find out if an .NET assembly is 32 bit, 64 bit, or any cpu (or ILASM only) using corflags.exe.  (This version is located here on my machine: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools.)

for /f "tokens=*" %i in ('dir /s /b /a-d *.dll') do call echo "%i" >> out.txt & corflags.exe /nologo "%i" >> out.txt

The output looks like this:

Version   : v4.0.30319
CLR Header: 2.5
PE        : PE32
CorFlags  : 3
ILONLY    : 1
32BIT     : 1
Signed    : 0
Version   : v2.0.50727
CLR Header: 2.5
PE        : PE32
CorFlags  : 1
ILONLY    : 1
32BIT     : 0
Signed    : 0
corflags : error CF008 : The specified file does not have a valid managed header

To interpret the results…

PE 32BIT Type of Assembly
PE32 0 Any CPU
PE32 1 x86
PE32+ 0 x64

Assembly Versions

To get the version of assemblies recursing all subdirectories, the following is useful in a power shell. This will not truncate the line.

ls -fi *.dll -r | % { $_.versioninfo } | Ft -autosize | out-string -width 4096

The output looks like this:

ProductVersion FileVersion  FileName
-------------- -----------  --------      C:\poo.dll      C:\caca.dll

So there you go. Some useful utilities.

Leave a Reply

Your email address will not be published. Required fields are marked *