I was puzzled by how the "AnyCPU" function works in .NET: it loads the executable file as a native 32-bit if the system is 32-bit and 64-bit if the system is 64-bit (which you can easily confirm with the task manager). Therefore, obviously, this is not possible.
The question is, how exactly did Microsoft do it? Windows did not initially know about the .NET platform, so the Windows PE loader cannot look for any additional features in the PE headers for the CLR header; this function must be added by some kind of kernel extension. But the .NET framework doesn’t seem to install such a thing ... I will completely lose the way the same executable can be native 32-bit and 64-bit at the same time, especially since disassembling mscoree.dll doesn’t even show links to undocumented native functions.
Does anyone have any knowledge and / or reasonable assumptions about how this was done? Obviously, this is possible (so things like “this is not possible” do not say), and it makes me want to write my own cross-platform EXE ...
Edit:
As a note, note how you cannot run 32-bit executables in a 64-bit Windows PE environment ... there has to be some way to extend or change the PE loader with some kind of “plugins”, right?
Mehrdad Jan 10 '11 at 3:28 2011-01-10 03:28
source share