MZ file

from Wikipedia, the free encyclopedia
MZ file
File extension : .exe
Magic number : 4D 5A hex
MZ
Initial release: 1981
Type: Executable files ( EXE ) for MS-DOS

The term MZ file is derived from a magic number in the administrative data at the beginning ( header ) of a program file . An executable file with the file extension “ EXE ” for the MS-DOS operating system is therefore also referred to as an “MZ file”.

term

The magic number is a byte sequence with the hexadecimal values ​​4D and 5A, which corresponds to the letters "M" and "Z". These are the initials of Mark Zbikowski , a long-time Microsoft software developer who has worked on MS-DOS, among other things. "MZ" forms the beginning of a data structure which is correspondingly referred to as "MZ header".

MZ header

The MZ header, with a fixed structure, forms the beginning of an EXE program file and contains administrative information that the operating system needs to load and start the program. It is filled with corresponding data by the linker when the EXE file is completed on the basis of its specific content structure and, if necessary, other requirements (e.g. overlay ). The header has the following structure:

Offset number Type content
0000h 2 char Identifier 'MZ'
0002h 1 word Bytes in the last page
0004h 1 word Number of 512-byte pages
0006h 1 word Number of entries in the relocation table
0008h 1 word Size of the header in paragraphs (16 bytes)
000Ah 1 word Minimum number of paragraphs required
000Ch 1 word Maximum number of paragraphs required
000Eh 1 word Start value of SS (Stack Segment Register) relative to the program start
0010h 1 word Start value of SP (stack pointer)
0012h 1 word Checksum or 0
0014h 1 dword Start value of CS: IP (code segment and instruction pointer) relative to the program start
0018h 1 word Offset of the relocation table or 40h for new EXE formats (NE, LE, LX, W3, PE etc.)
001Ah 1 word Overlay number or 0

Loading and execution

The MZ header cannot be found in DOS programs with the ending “ COM ”. They are - adopted by the CP / M operating system - loaded into the memory with a maximum size of 63.75 KiB (64 KB) at offset 100h of a segment and executed there. EXE programs are not limited to a segment and can be loaded anywhere in memory. Therefore, the addresses in the code are created in such a way that the segment values ​​are only assigned when loading. Where this has to be done is listed in the relocation table. First the required memory size is calculated from the MZ header and then the program code is loaded from the file to the beginning of the start segment from the end of the header. According to the number of entries in the relocation table, this is processed and the corresponding positions of the program code in the RAM are adjusted. After setting up the stack and loading the stack segment register (SS) and stack pointer (SP), the program is executed with a jump to CS: IP.

Further MZ usage

The letter sequence “MZ” can also be found at the beginning of newer EXE formats ( New Executable and Portable Executable ) under OS / 2 and Windows as well as in DLLs ( dynamic link libraries ). This is due to the fact that, for the sake of simplicity, these later programs generally contain an EXE program in the old DOS format as a so-called stub at the beginning of the file. This prevents an attempt to start an EXE program under MS-DOS that is not suitable for DOS. In this case, only the stub is executed, which is usually programmed in such a way that it only outputs a simple error message and then ends. Such stubs are integrated either by default by the compiler system or individually by the programmer when linking. Mostly it is a short message like "This program cannot run in DOS mode" (or similar).

Hexdump of an MZ file used as a stub as an example:

00000000:   4D 5A 50 00 02 00 00 00 04 00 0F 00 FF FF 00 00    MZP.............
00000010:   B8 00 00 00 00 00 00 00 40 00 1A 00 00 00 00 00    ........@.......
00000020:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00000030:   00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00    ................
00000040:   BA 10 00 0E 1F B4 09 CD 21 B8 01 4C CD 21 90 90    ........!..L.!..
00000050:   54 68 69 73 20 70 72 6F 67 72 61 6D 20 63 61 6E    This program can
00000060:   6E 6F 74 20 72 75 6E 20 69 6E 20 44 4F 53 20 6D    not run in DOS m
00000070:   6F 64 65 0D 0D 0A 24 37 00 00 00 00 00 00 00 00    ode...$7........
00000080:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
00000090:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000000A0:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000000B0:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000000C0:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000000D0:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000000E0:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
000000F0:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................

Other stub variants were also in use:

  • In the case of smaller programs, a pure DOS version was occasionally implemented as a stub in real mode , while a second version for protected mode under OS / 2 formed the main part of the EXE program.
  • In order to overcome the memory limit in PCs running MS-DOS, so-called DOS extenders were integrated, via which more RAM could be accessed in protected mode .
  • It was also possible to run programs for text mode using what is known as Family Application Mode, both under DOS and under OS / 2. In this case, a library from Microsoft (Family Application Program Interface, FAPI) was integrated via the header with MZ identifier, which redirected OS / 2 system calls to corresponding DOS functions. The full range of functions of OS / 2 was not available; however, allowed these "DOS programs" to take advantage of the modern operating system.

See also

Individual evidence

  1. a b Christian Baumgarten: System-oriented programming with Borland Pascal . Vieweg, Braunschweig / Wiesbaden 1994, ISBN 978-3-322-87239-5 .

Web links