Hand Crafting .Com Dos files

Started by
9 comments, last by Washu 19 years, 6 months ago
I have tried to hand craft .com dos files(I am a looney, I know) just to see what I could do. I started out trying to make Interrupt 21h(I think that is the one that makes a message box pop up and say "This won't run in dos blah blah blah."). So I opened up my hex-editor, entered in the two hexadecimals for it: 0xCD 0x21 It doesn't work! So my question is, is there some sort of file format, like for the win32? Because I always thought it was pure binary. Or am I just doing something else wrong? Or,as is far more likely, am I doing both wrong? Thanks for your help.
Advertisement
No, there is no special format. It's just that you have no idea what the various interrupts do. While the raw binary for calling Int 0x21 is 0xCD21, Int 0x21 has nothing to do with putting up a message about not running in DOS.

Open up your hex editor and enter this:

B4 09 BA 09 01 CD 21 CD 20 49 20 6E 65 65 64 20 74 6F 20 6C 65 61 72 6E 20 6D 6F 72 65 20 61 62 6F 75 74 20 44 4F 53 20 69 6E 74 65 72 72 75 70 74 73 24

then save as .COM file
or just b8 00 4c cd 21 for a simple app (just quits)

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

If it helps, I believe interrupt 21h is the interrupt you would use to run various DOS related functions... I'm betting that it's "this won't run in DOS" output you got (and thus, why it seemed to you that that was its function) is probably based on the way that modern Windows OSes prefer to deal with interrupts, and computer codes in general.

Remember, interrupts are basically ways of telling the computer to do something at its most basic level (BIOS, or in the case of 21h basic DOS functions). If you do a search on interrupt 21h you'll find some of those functions. I'd reccommend using Assembly programming to access those functions however, as hex editing to make a program is pretty much doing the same thing except denying you the naming conventions (which, of course, is why Assembly was created in the first place; to replace hard to remember opcodes with easy to remember commands, among other things of course).

Anyways, give Assembly a shot. You'll essentially be doing the same thing.
-Vendal Thornheart=) Programming for a better tomorrow... well,for a better simulated tomorrow. ;)
Okay, thanks. Now, another question. What does the extra stuff do? I kinda like to know what is going on. Are there any tutorials about this kinda thing.

I am pwned by your knowledge.

Here
Quote:Original post by smitty1276

Here


You dare to use Yahoo! instead of Google!!!???

BTW, Michalson, You changed it! It did only have "ned" instead of "need". If only I had tried your program out earlier.

Edit: Michalson, you have "teh" greatest avatars.
What exactly those opcodes are and what they stand for are also something you could look up. Perhaps try "Intel Opcodes" or something? Anyways, the opcodes themselves have convoluded meanings because many of them are likely shorthand for registers, memory, or other important internal components. They won't all map directly to functions (that is, to something that is being done), a lot will map to the things being done to, if that makes sense. =)

Anyways, as I was saying before, I would suggest keeping it at Assembly level. you're essentially doing what you wanted to do before, but without having to manage physical memory locations and without errors costing you big... I'll explain.

I'm assuming that Windows probably has protections against these kinds of things, but programming directly with opcodes is very dangerous in general, and even moreso on a Multitasking operating system.

In both cases, you'll have the problem of writing the wrong opcode = deleting parts of hard drive, erasing BIOS, invalidating your FAT table, and causing any sort of a million other permanent and nonpermanent problems.

However, in multitasking, you'll also have the problem that memory is already being used by other threads that are running. If you're writing to Opcodes, I'd assume that you are skipping over the protection that languages from Assembly up give in that they won't assign memory to variables that are already in use by variables. In Opcodes, variables themselves don't exist: you are literally writing to a physical memory (drive, etc) location. If that location has something there, something important, then you'll be screwing up something important. Now, I would imagine that Windows wouldn't allow that to happen, but I've never actually tried it myself... and quite honestly, I'd rather not give it a try. Some things in computing just arent' worth the hassle, especially when there's something else that does the exact same thing but with built-in protections (IE Assembly). You must understand that, in essence, you are doing the same thing as writing opcodes with Assembly; you're just given some conveniences to protect your computer as well as to protect your brain from having to remember a bunch of worthless junk.

So in the end, I'd reccommend that you learn Assembly. That's really the way to go, I promise! Besides, Assembly is cooler than Opcodes in general. ;)
-Vendal Thornheart=) Programming for a better tomorrow... well,for a better simulated tomorrow. ;)
I thought the executable part of a com file started at 100h?

Open a command shell and type 'debug'. I forget the DOS code for it now, but you can enter code to save a file and then use debug to hand craft assemlby (it's like narcotic-free dental work).
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Thought I had moved this earlier.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement