Customizing the Microsoft .NET Framework Common Language Runtime

The default host for running managed executables is implemented in the function _CorExeMain in the CLR startup shim (mscoree.dll). Control is passed to _CorExeMain differently depending on the operating system on which you're running. On computers running Microsoft Windows XP and later, the operating system loader has explicit knowledge of managed code executables and calls _CorExeMain directly when a managed executable is launched.

For earlier versions of the Windows operating system, the process for getting to _CorExeMain isn't as direct. When a compiler emits a managed executable, it sets the main routine (in the Portable Executable [PE] header) to a small stub that calls _CorExeMain instead of the executable's "real" entry point. Launching the executable thereby passes control to the CLR startup shim, where the process of running the program begins.

How Does Windows XP Determine Whether a File Contains Managed Code?

Managed executable files are stored in the standard PE format. An additional directory entry has been added to the standard file header that identifies whether the file contains managed code. You can see this directory entry by looking for the COM Descriptor Directory in the output from running dumpbin /headers on a file.

If a nonzero address is specified for the COM Descriptor Directory, the file contains managed code as shown in the following output from dumpbin:

[View full width]

OPTIONAL HEADER VALUES 10B magic # (PE32) 6.00 linker version 1000 size of code 2000 size of initialized data 0 size of uninitialized data 265E entry point (0040265E) 2000 base of code 4000 base of data 400000 image base (00400000 to 00407FFF) 2000 section alignment 1000 file alignment 4.00 operating system version 0.00 image version 4.00 subsystem version 0 Win32 version 8000 size of image 1000 size of headers 13331 checksum 3 subsystem (Windows CUI) 400 DLL characteristics No safe exception handler 100000 size of stack reserve 1000 size of stack commit 100000 size of heap reserve 1000 size of heap commit 0 loader flags 10 number of directories 0 [ 0] RVA [size] of Export Directory 2604 [ 57] RVA [size] of Import Directory 4000 [ 860] RVA [size] of Resource Directory 0 [ 0] RVA [size] of Exception Directory 0 [ 0] RVA [size] of Certificates Directory 6000 [ C] RVA [size] of Base Relocation Directory 20A0 [ 1C] RVA [size] of Debug Directory 0 [ 0] RVA [size] of Architecture Directory 0 [ 0] RVA [size] of Global Pointer Directory 0 [ 0] RVA [size] of Thread Storage Directory 0 [ 0] RVA [size] of Load Configuration Directory 0 [ 0] RVA [size] of Bound Import Directory 2000 [ 8] RVA [size] of Import Address Table Directory 0 [ 0] RVA [size] of Delay Import Directory 2008 [ 48] RVA [size] of COM Descriptor Directory[1] 0 [ 0] RVA [size] of Reserved Directory

[1] A nonzero value identifies a managed code file.

[1] A nonzero value identifies a managed code file.

    Категории