Creating a COM file from text
The answer provided here is a pretty awesome trick. Just for my own edification, I'd like to learn to create that type of program.
Is there a nice library that I can use to ensure my output is entirely ASCII? Or what tools would I begin to use to generate that type of output? I understand that I would likely be creating a 16-bit application, but can I generate 32-bit applications as well?
I've found MSFT's debug.exe
program has an assembler that works with this, but the output I receive from that is not entirely ASCII. Also, when disassembling the program provided in 谢继雷'Lenik's answer I don't see where he calls int 21
to write to the screen. Is there more documentation somewhere for this type of program?
Can anyone else me sort out these mysteries, pl开发者_JS百科ease?
The text-to-com file is a very neat trick. It takes advantage of the fact that the 16-bit loader will load the image at offset 0x0100 and start executing at that address.
An exe file includes a binary header that cannot be represented as text. As a result, you can't create a 32-bit or 64-bit executable that is strictly text.
A classical example of a .COM file using only printable characters is EICAR, a file used to test antivirus. Some time ago, there was a discussion thread about EICAR at bugtraq.
There's not really a "trick" here, except for careful use of machine code that happens to all map to ASCII characters. I'm not in a position to disassemble that code at the moment, but 谢继雷'Lenik indicates that that there is some self-modifying code involved.
In the day of MSDOS programs, simple programs were written using assembly, or maybe compiled and linked to .COM—though that was not as common as assembling directly to .COM.
To know what to do (pre-www) one obtained two or three reference books, including Peter Norton's Programmer's Guide to the IBM PC, aka ''The Pink Shirt Book''.
Ralf Brown's Interrupt List is a reasonable substitute and is online here.
Unless you have an old computer available, it might be challenging to find a valid execution environment for an MSDOS .COM file.
精彩评论