It's still there because there's no easy way to remove it without breaking the file format, and nobody seems to think 38 bytes per executable is worth the trouble. The requirements on section alignment nearly always "waste" a lot more than that anyway.
当 PE 格式推出时(1994 年,Windows NT 3.1),MS-DOS 仍然很流行。 Windows EXE 错误地从 DOS 运行的风险是非常真实的。因此他们需要使 Windows EXE 与 DOS 加载程序表面兼容。因此,在这种情况下,程序会执行某些操作(即打印消息并退出),而不是随机崩溃或让加载程序说“这甚至不是程序”。
显然,以某种方式追溯修改 DOS 加载程序以识别 Windows EXE 并不是一种选择。而且 DOS exe 标头中没有“平台/体系结构”标识符,就像在 PE 中一样 - 没有内置机制来防止将来引入不兼容性。此外,还有一些第三方 MS-DOS 兼容操作系统,带有自己的 EXE 加载程序(特别是 DR-DOS)。无论如何,“这是一个 Windows 程序,请在 Windows 下运行”是一条更友好的消息,而不是一般的“此程序与您的系统不兼容”。一方面,它为 Windows 做广告。
DOS 存根也是较旧的 16 位 Windows EXE 格式(“NE”代表“新可执行文件”)的一部分。存根的路径甚至是一个可设置的链接器参数,因此可以制作某种“胖二进制文件” - Windows 位将是您的 Windows 程序,而 DOS 存根将是相同的程序(即相同的功能)对于DOS。 AFAIK,很少有人利用过这一点。
When the PE format was introduced (year 1994, Windows NT 3.1), MS-DOS was still very much around. The risk that a Windows EXE would be run from DOS by mistake was very real. So they needed to make Windows EXE's superficially compatible with the DOS loader. So that in such a scenario the program would do something (i. e. print a message and quit) instead of crashing randomly or having the loader say "this is not even a program".
Obviously, somehow retroactively modifying the DOS loader to recognize the Windows EXE's was not an option. And there was no "platform/architecture" identifier in the DOS exe header, like in PE - there was no built-in mechanism for future introduction of incompatibility. Also, there were some third party MS-DOS compatible operating systems out there, with their own EXE loaders (notably, DR-DOS). And anyway, "This is a Windows program, please run under Windows" is a much friendlier message that a generic "This program is not compatible with your system". For one thing, it advertises Windows.
The DOS stub was also a part of the older 16-bit Windows EXE format ("NE" for "New Executable"). The path to the stub was even a settable linker parameter, so that making a "fat binary" of a sorts was possible - the Windows bits would be your program for Windows, and the DOS stub would be the same program (i. e. same functionality) for DOS. AFAIK, very few people ever took advantage of that.
虽然磁盘操作系统 (DOS) 如今已不再使用,但基本上是命令行(或控制台模式)的 DOS 模式仍然存在并且非常流行。 DOS-MODE 可能意味着命令行模式。控制台应用程序非常流行,并且随处使用,尤其是在测试和开发环境中。
While Disk Operating System (DOS) is not in use these days, DOS-mode which is basically command line (or console mode) still exists and very popular. By DOS-MODE it probably means commandline mode. Console Application are very popular and used everywhere esp in test and development environment.
发布评论
评论(4)
它仍然存在,因为没有简单的方法可以在不破坏文件格式的情况下删除它,而且似乎没有人认为每个可执行文件 38 字节值得这么麻烦。无论如何,对部分对齐的要求几乎总是“浪费”更多很多。
It's still there because there's no easy way to remove it without breaking the file format, and nobody seems to think 38 bytes per executable is worth the trouble. The requirements on section alignment nearly always "waste" a lot more than that anyway.
在某个地方,有人仍在使用 DOS。而且,为了向后兼容问题,38 字节仍然需要存在。即使没有人使用 DOS。
您会惊讶地发现 Windows 代码为了保持向后兼容而经历了多少麻烦。
Somewhere, someone is still using DOS. And, for backwards compatibility issues, the 38 bytes still need to be there. Even if no one is using DOS.
You would be amazed to know how many hoops the Windows code jumps through to remain backwards compatible.
当 PE 格式推出时(1994 年,Windows NT 3.1),MS-DOS 仍然很流行。 Windows EXE 错误地从 DOS 运行的风险是非常真实的。因此他们需要使 Windows EXE 与 DOS 加载程序表面兼容。因此,在这种情况下,程序会执行某些操作(即打印消息并退出),而不是随机崩溃或让加载程序说“这甚至不是程序”。
显然,以某种方式追溯修改 DOS 加载程序以识别 Windows EXE 并不是一种选择。而且 DOS exe 标头中没有“平台/体系结构”标识符,就像在 PE 中一样 - 没有内置机制来防止将来引入不兼容性。此外,还有一些第三方 MS-DOS 兼容操作系统,带有自己的 EXE 加载程序(特别是 DR-DOS)。无论如何,“这是一个 Windows 程序,请在 Windows 下运行”是一条更友好的消息,而不是一般的“此程序与您的系统不兼容”。一方面,它为 Windows 做广告。
DOS 存根也是较旧的 16 位 Windows EXE 格式(“NE”代表“新可执行文件”)的一部分。存根的路径甚至是一个可设置的链接器参数,因此可以制作某种“胖二进制文件” - Windows 位将是您的 Windows 程序,而 DOS 存根将是相同的程序(即相同的功能)对于DOS。 AFAIK,很少有人利用过这一点。
When the PE format was introduced (year 1994, Windows NT 3.1), MS-DOS was still very much around. The risk that a Windows EXE would be run from DOS by mistake was very real. So they needed to make Windows EXE's superficially compatible with the DOS loader. So that in such a scenario the program would do something (i. e. print a message and quit) instead of crashing randomly or having the loader say "this is not even a program".
Obviously, somehow retroactively modifying the DOS loader to recognize the Windows EXE's was not an option. And there was no "platform/architecture" identifier in the DOS exe header, like in PE - there was no built-in mechanism for future introduction of incompatibility. Also, there were some third party MS-DOS compatible operating systems out there, with their own EXE loaders (notably, DR-DOS). And anyway, "This is a Windows program, please run under Windows" is a much friendlier message that a generic "This program is not compatible with your system". For one thing, it advertises Windows.
The DOS stub was also a part of the older 16-bit Windows EXE format ("NE" for "New Executable"). The path to the stub was even a settable linker parameter, so that making a "fat binary" of a sorts was possible - the Windows bits would be your program for Windows, and the DOS stub would be the same program (i. e. same functionality) for DOS. AFAIK, very few people ever took advantage of that.
虽然磁盘操作系统 (DOS) 如今已不再使用,但基本上是命令行(或控制台模式)的 DOS 模式仍然存在并且非常流行。 DOS-MODE 可能意味着命令行模式。控制台应用程序非常流行,并且随处使用,尤其是在测试和开发环境中。
While Disk Operating System (DOS) is not in use these days, DOS-mode which is basically command line (or console mode) still exists and very popular. By DOS-MODE it probably means commandline mode. Console Application are very popular and used everywhere esp in test and development environment.