June 5, 2009

Your Very Own ZIP File Creator, Part III

Filed under: Main — admin @ 12:01 am

Nerd Warning! This blog entry is part of a series on creating a command line utility to build a ZIP file. It’s technical stuff!

From the last post, you read that an empty ZIP file could be created by using the DOS DEBUG utility. The object is to use various DEBUG commands to build the ZIP file’s contents from scratch, then save those bytes to a file on disk. DEBUG is utterly capable of that.

If you’d like to, you can follow along with these instructions using the command prompt window on your PC. The end result is that a ZIP file will be created on your computer:

1. Open a Command Prompt window. It’s found in the All Programs, Accessories menu on the Start button menu.

2. At the command prompt, type DEBUG and press Enter.

The DEBUG prompt is a hyphen. Yes, it’s a very unfriendly program.

The E command in DEBUG is used to input bytes, to actually assign values to memory locations. You want to create the bytes, the raw data, for the ZIP file at memory location 100:

3. Type E100 and press Enter.

Now you need to input the bytes. It’s not that hard because you need only carefully type in the first four values. The rest of the values are zeros.

4. Type 50 and press the Spacebar.

Pressing the Spacebar hops the input over to the next byte in memory. Do not press Enter or you’ll have to start all over with Step 3.

5. Type 4B and press the Spacebar.
6. Type 5 and press the Spacebar.
7. Type 6 and press the Spacebar.

Now you need to type the zeros. There are 18 of them, so you’ll need to type 0 and then press the Spacebar 18 times:

8. Type 0 and press the Spacebar.
9. Repeat Step 8 eighteen times.

10. Press Enter to exit the input mode.

When you’re done, the screen should look something like this:

debug2

You’ve input the data, but you need two other pieces of information to create a file in DEBUG: the file size and the file name.

To set the file size, you must assign a value to the processor’s CX register. Yes, this is machine language programming. Ta-da!

11. Type RCX and press Enter.

The RCX command allows you to set the value of the CX register.

12. Type 16 and press Enter.

The value 16 is hexadecimal; it’s decimal value is 22, which is the size of an empty ZIP file.

To name the file, use DEBUG‘s N command:

13. Type N NEW.ZIP and press Enter

The filename is now set to NEW.ZIP and the size is 22 bytes.

14. Type W and press Enter.

W is the Write command. You’ve just created a new, empty ZIP file.

15. Type Q and press Enter to quit DEBUG and return to the command prompt.

You can use the DIR command to verify that you created an empty ZIP file named NEW.ZIP. It’s there. It exists. It’s empty. Congratulations!

Next blog entry I’ll show you how to create a simple script to save you a ton of typing time.

2 Comments

  1. I really like where this is going. I am really an old DOS guy at heart; I almost had to be forceably dragged into the world of Windows. I use batch files EXTENSIVELY in XP. The ability to create ZIP archives without having to use WinZip would be a great advantage to me.

    On an unrelated note, I wish the Command Prompt window could be configured to both translate ANSI escape sequences AND allow Windows programs to be run from the prompt. Considering the amount of attention Microsoft has given to improving batch power in recent years, I find it odd that this has not been addressed.

    Comment by sean bernard — June 5, 2009 @ 3:28 pm

  2. There is an ANSI display driver for the CMD prompt in Windows. I believe it’s called ZANSI.SYS, though I haven’t checked up on it in a while. I don’t know whether you can run Windows commands while using it.

    Comment by admin — June 5, 2009 @ 6:21 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.


Powered by WordPress