tags:

views:

837

answers:

2

If I set the platform flags of MyApp.exe to be x64 I still can run the corflags utilty like this:
corflags /32bit+ MyApp.exe
corflags will happily set the 32bit flag to 1. Of course when I'll try to run the application I'll get an error: 0xC000007B = STATUS_INVALID_IMAGE_FORMAT

My question is: Is there a way that an assembly which is built to x64 can run as x86 or it is just that corflags utility doesn't 'care'?

A: 

Because if you don't load a native DLL, there's no reason that you couldn't remark it as 32-bit. If it's pure MSIL, the decision doesn't mean as much.

Paul Betts
Hmm not true Paul. Try a simple test: Create a console application with nothing inside. Build it as x64 application than use corflags to set it to x86. Now try to run the application - You'll get the 0xC000007B error.
Ohad Horesh
+1  A: 

Compiling your binary by setting the "Platform Type" to x64 also changes the image PE header to make it 64 bits only. You can see this by using the Dependency Walker, for instance.

Having a 64Bits PE header does seem to take precedence over the 32 bits only corflags. The win32 bootstrapper for .NET seems to see that the PE header is not compatible with the current system (64 bits on a 32 bits system). That prevents the native image from loading, and incidentally also the .NET assembly part of the image.

I don't know any tool capable of updating the PE header this way, though. This does not seem to be just a matter of changing a flag to set the image to 32 bits. (See this blog post)

Jerome Laban