How To run as 32bit executable on a 64bit machine

One of the problems I've encountered while working on a x64 machine is that I need to run NUnit as 32bit if I want to run a test assembly that was compiled as a x86 assembly. In fact I had several similar occasions when I needed to run applications on my computer as 32bit executables.

For this exact purpose a CorFlags Conversion Tool (CorFlags.exe) tool was created.

Corflags was shipped with .NET Framework SDK (2.0) it is a tool that allows the user to view and configure the corflags section of a PE image (The corflags section of the file is where all the platform related data is stored).

Getting information for a .NET assembly is very easy just use start the visual studio command prompt and write: corflags.exe filename.

The output should look something like:

image

Version - .NET version that the binary was built with.

CLR Header - 2.0 means either 1.0 or 1.1 while 2.5 means 2.0.

PE & 32bit - The platform this binary was compiled to run with:

AnyCPU - PE = PE32 and 32bit = 0

X86 - PE = PE32 and 32Bit = 1

64-bit - PE = PE32+ and 32bit = 0

CorFlags - This is computed by OR’g specific flags to indicate whether the image is ILONLY, its bitness etc. and is used by the loader.

ILONLY - 0 if the managed assembly contains unmanaged code 1 otherwise.

Signed - whether this assembly was signed using a strong key.

 

We can change the values of those variables inside the corflags section by using the tool with one of its arguments - see corflags.exe MSDN page for more details.

 

To cut a long story short  - using /32bit+ argument a .NET executable can be set to run as a x86 application.

NUnit is a .NET executable and as such it can be set run as  x86 using corflags.exe /32bit+ nunit.exe and now I can use it to run tests as 32bit.

Labels: