C++ PE文件中的MZ签名有什么用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/957057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the MZ signature in a PE file for?
提问by samoz
I'm working on a program that will parse a PE object for various pieces of information.
我正在开发一个程序,该程序将解析 PE 对象的各种信息。
Reading the specifications though, I cannot find out why the MZ bytes are there, as I cannot find this on the list of machine types that these 2 bytes are supposed to represent.
虽然阅读规范,但我不知道为什么 MZ 字节在那里,因为我在这 2 个字节应该代表的机器类型列表中找不到它。
Can anyone clarify?
任何人都可以澄清吗?
回答by Michael Burr
The MZ signature is a signature used by the MS-DOS relocatable 16-bit EXE format.
MZ 签名是 MS-DOS 可重定位 16 位 EXE 格式使用的签名。
The reason a PE binary contains an MZ header is for backwards compatibility. If the executable is run on a DOS-based system it will run the MZ version (which is nearly always just stub that says you need to run the program on a Win32 system).
PE 二进制文件包含 MZ 标头的原因是为了向后兼容。如果可执行文件在基于 DOS 的系统上运行,它将运行 MZ 版本(这几乎总是表示您需要在 Win32 系统上运行程序的存根)。
Of course this is not as useful nowadays as it was back when the world was transitioning from DOS to whatever would come after it.
当然,这在今天已经不像在世界从 DOS 过渡到它之后的任何东西时那样有用了。
Back then there were a few programs that would actually bind together a DOS version and a Win32 version in a single binary.
当时有一些程序实际上可以将 DOS 版本和 Win32 版本绑定到一个二进制文件中。
And as with most things dealing with Windows history, Raymond Chen has some interesting articles about this subject:
与大多数处理 Windows 历史的事情一样,Raymond Chen 有一些关于这个主题的有趣文章:
回答by samoz
Thety are the initials of a Microsoft programmer and identify the file as a DOS executable see http://en.wikipedia.org/wiki/DOS_executablefor a bit more info.
Thety 是 Microsoft 程序员的首字母缩写,并将文件标识为 DOS 可执行文件,请参阅http://en.wikipedia.org/wiki/DOS_executable了解更多信息。
回答by Daniel Wedlund
As I see it, by reading the wikipedia articleand Iczelion's PE Tutorial, it is there just to keep up compatibility and enable dos or HX DOS Extender to execute certain code next to the MZ header.
在我看来,通过阅读维基百科文章和Iczelion 的 PE 教程,它只是为了保持兼容性并启用 dos 或 HX DOS Extender 来执行 MZ 标头旁边的某些代码。
From devsourceone can find more information like MZ stands for Mark Zbikowski, one of MS-DOS's developers. And how the operating system behaves and handles the data from the MZ header.
从devsource可以找到更多信息,例如 MZ 代表 Mark Zbikowski,MS-DOS 的开发人员之一。以及操作系统如何表现和处理来自 MZ 标头的数据。
回答by Michael
Mark Zbikowskiput his initials into the original MS-DOS exe format. This signature was necessary to distinguish .EXE files from the much simpler .COM format on DOS.
Mark Zbikowski将他的姓名首字母写成原始的 MS-DOS exe 格式。这个签名是区分 .EXE 文件和 DOS 上简单得多的 .COM 格式所必需的。
Every PE file also contains a 16-bit DOS program and thus starts with this .EXE header. This DOS program would typically print out "This program requires Microsoft Windows" or similar. I don't know if modern compilers still produce the DOS stub, but the PE standard still says a PE starts with a 16-bit EXE header.
每个 PE 文件还包含一个 16 位 DOS 程序,因此以这个 .EXE 头文件开头。此 DOS 程序通常会打印出“此程序需要 Microsoft Windows”或类似内容。我不知道现代编译器是否仍然生成 DOS 存根,但 PE 标准仍然说 PE 以 16 位 EXE 标头开头。
回答by zfmsoftware
In the early days of Microsoft? Windows, The Windows? 1.x, 2.x and 3.xx OS not only existed in the same volumes as Microsoft? DOS, but also ran on top of an MS-DOS OS. It was not only possible, but very probable that a user might attempt to run some of the Windows? programs under DOS. Therefore, Microsoft? programmers made sure all Windows? programs would have a simple 16-bit DOS program placed at the front of each Windows executable that would alert the user if they were attempting to run a Windows? program under DOS. This is all the DOS "Stub" program does. resource: http://thestarman.pcministry.com/asm/debug/DOSstub.htm
在微软的早期?窗户,窗户?1.x、2.x 和 3.xx 操作系统不仅与 Microsoft 存在于同一卷中?DOS,但也运行在 MS-DOS 操作系统之上。这不仅是可能的,而且很有可能用户可能会尝试运行某些 Windows?DOS下的程序。因此,微软?程序员确定所有Windows?程序将有一个简单的 16 位 DOS 程序放置在每个 Windows 可执行文件的前面,如果用户试图运行 Windows,它会警告用户?DOS下的程序。这就是 DOS“Stub”程序所做的全部。资源:http: //thestarman.pcministry.com/asm/debug/DOSstub.htm
回答by John Smith
It's the "magic number" of dos executable. Legacy stuff you can ignore.
它是 dos 可执行文件的“神奇数字”。您可以忽略的遗留内容。