← Back to context

Comment by johannes1234321

3 years ago

A .com file is an old form of DOS executables with only code and data. No fancy headers or anything. Only thing specified is that execution will start at a specific address (0100h) and if you put a JMP you got enough space to put other headers around it.

A com file is different from a typical dos/Windows exe, which requires a specific file header. Each exe begins with the two bytes MZ followed by specific information on page sizes etc. and there is no way around.

The challenge a program like APP has is that it should be recognized by all operating systems, so to Linux it should look like an ELF executable, on Windows like a windows executable, etc.

Now if you take this APP perl.com file and load it with Linux, Linux will read the ELF header and be happy. If you load it into Windows, it will see the .com ending and thus just put the code into memory, jump to address 0100h and start executing. The program then can ignore the elf header. And if you open it with some (unzip) Programm such a Programm will look at the end of the file, where it will find a zip file header info and will think it's an zip archive. (Zip files have the header at the end mostly for historic reasons, as all information was only available once compression was done, but as you span multiple disks you can't reach the front anymore)

In the end it is a trick to make it look like different kind of file, depending on who looks at it.