Is that possible? Yes, it is. It’s just a matter of redirecting echo output to a file. Writing the program with echo should be a straightforward task if we are able to produce the sequence of characters corresponding to the intended binary, executable file. Is that useful? Surely not. But it’s a healthy way to waste your time 🙂 This can be achieved by writing the characters of the executable file, using a simple text editor like notepad or even the old MS-DOS Editor. Of course, the program should be relatively small or we would adventure into the dangerous lands of masochism. By using the echo command of DOS we will be following the conceited style of doing things 🙂 But we’ll restrict this post to the simple hello, world! program we have been reviewing in previous entries.
The hexadecimal code of our program is:
EB 12 0D 0A 68 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D 0A 24 B4 09 BA 02 01 CD 21 B4 00 CD 21 0D
Now, we only have to input and redirect these hexadecimal values to a file, that we’ll name hello.com
.
That would be fairly easy except for some values such as 00
and 09
, which represent the NULL and TAB characters, respectively. How do you input those characters as parameters for the echo command? I found no way of doing that. If you know a way, please explain in the comments. Therefore, I changed the code of the program in two ways:
- The
09
character comes from the instructionmov ah,9
. I replaced that by two instructions:mov ah,7
andadd ah,2
. The semantic stays intact, but the contrived approach allows us to discard the 09 character. - Regarding the NULL character (
00
), it’s a consequence of the linemov ah,00
. But we can accomplish the effect of clearingah
by executingxor ax,ax
instead. And that’s it.
Take a look at the complete command I used:
Nice 🙂
mmmm… are you sure it’s not possible to input a 00 character in a file? There has to be way… without editing the file directly, of course
we can simply open the file in a hexadecimal editor and input the zero, but that’s not what you are trying to do…
wow, this is more advanced and well, WEIRD!
lol
I did not understand… what’s this for?
> But it’s a healthy way to waste your time
I’m curious about your definition of “healthy” 🙂
Very cool, I’m impressed.
Crazy 😉
Very good !! Здорово!
Thanks a lot!
wow, just wow
awesome!
Contrived yet cool piece of code 😀
😀 es el codigo ms extraño q voy a leer esta semana….