Piggybacking an .EXE File


My SEA files use the .EXE extension to tell MS-DOS that they are executable files. However, they are not normal .EXE files; they've been extended. MS-DOS still executes them without any difficulty. An .EXE file has three parts: a program file header, relocation tables and a relocatable image of the program. The relocation table contains the information MS-DOS uses to adjust references to memory locations in the executable image. The program file header contains, among other things, information about how much RAM the executable image needs to run. Note that the file size returned by DIR and the amount of memory needed to run the program are not related. The .EXE file does not even know how much room it takes up on disk. This is the trick I used to build an archive file. Adding bytes to the end of a .EXE file does not change the information in the program file header, so when you run a SEA, only the extraction module (i.e., the original extr.exe) gets loaded.

You can investigate this further using a utility called exehdr.exe that Microsoft includes with C. It allows you to examine and change a program file header. (Versions of C before 6.0 included a slightly different version called exemod.exe.) If you run exehdr.exe on extr.exe, the extraction module, and then on out.exe, a SEA that contains the extraction module, all of the numbers displayed are the same, except for the file size, which is obtained from the disk, rather than the program file header.