home *** CD-ROM | disk | FTP | other *** search
- This file written 970102 by David Ashley (dash@netcom.com).
-
- This program prints out the header of an EXE file.
-
- When DOS loads a program it decides where in memory the program is going to
- be loaded. This means choosing the initial segment in memory. DOS examines
- the header to figure out how big the header itself is. The word at offset 8
- tells the # of 16 byte paragraphs the header contains. Usually this contains
- 20h, meaning there are 32 16 byte paragraphs for a total of 512 bytes (200hex).
-
- Call the segment DOS initially loads the program ISEG.
-
- The EXE file after the header gets loaded at segment ISEG+10h, at offset
- 0 (ISEG+10h:0). The number of bytes that will be loaded is determined by
- header words at offsets 4 and 2. Take the word at offset 4, subtract 1, then
- multiply by 512. Then add the word at offset 2. This is the total number of
- bytes to be loaded.
-
- After loading, the file is relocated if necessary. The word at offset 6 tells
- the number of places that need to be relocated. The word at offset 18h tells
- where the relocation list is as an offset from the start of the header (which
- is also the start of the EXE file).
-
- Each entry in the relocation list is a segment:offset pair. The location to
- patch is ISEG+10h+segment:offset. This points to a word that must be fixed.
- Dos fixes it by adding the value of ISEG+10h to the contents of the word and
- storing the result back into the word's location. That's all there is to it!
-
- The program is ready to run in memory, all dos has to do is set up the
- registers and jump to it.
-
- Dos sets up the DS,SS, SP (and I think ES) registers as follows:
- DS = ISEG
- ES = DS (it always seems to match ds)
- SS = ISEG + 10h + word at offset 0eh in the header
- SP = word at offset 10h in the header
-
- Now we need to jump into the code. The location is determined by:
-
- CS = ISEG + 10h + word at offset 16h in the header
- IP = word at offset 14h in the header
-
- ---------------------------
- The EXE.C program contains the structure of the header.
-
- Hope this helps.
- -Dave
-