我在一次采访中被问及 Windows 操作系统如何区分常规 EXE 和 .NET EXE。
我的回答是,当构建 .NET exe 时,编译器会将一些信息放入 header 中。信息为PE32或PE32+。 Windows 验证 header 以确定它是否需要加载加载 CLR 并执行 EXE 的 MSCOREE.dll。
我的回答正确吗?
最佳答案
我认为以下两个链接是了解 PE 文件结构和 Windows 加载程序的良好资源。
- An In-Depth Look into the Win32 Portable Executable File Format (MSDN Mag 2002 年 2 月)
- An In-Depth Look into the Win32 Portable Executable File Format, Part 2 (MSDN Mag 2002 年 3 月)
2002 年 3 月那篇文章的确切引述是:
The primary purpose of a .NET executable is to get the .NET-specific information such as metadata and intermediate language (IL) into memory. In addition, a .NET executable links against MSCOREE.DLL. This DLL is the starting point for a .NET process. When a .NET executable loads, its entry point is usually a tiny stub of code. That stub just jumps to an exported function in MSCOREE.DLL (_CorExeMain or _CorDllMain). From there, MSCOREE takes charge, and starts using the metadata and IL from the executable file. This setup is similar to the way apps in Visual Basic (prior to .NET) used MSVBVM60.DLL.
关于.net - Windows 如何区分常规 EXE 和 .NET exe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2638883/