Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, please?

like image 897
mrduclaw Avatar asked Dec 16 '22 16:12

mrduclaw


2 Answers

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.

like image 138
Jim Mischel Avatar answered Dec 29 '22 16:12

Jim Mischel


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.

like image 36
ninjalj Avatar answered Dec 29 '22 14:12

ninjalj