BEDIT Binary File Editor USER'S GUIDE Copyright 1990, 1993 by Gary C. Crider and Parity Solutions TABLE OF CONTENTS: What is BEDIT? ................................... 1.0 The BEDIT command line ........................... 2.0 Operational notes ................................ 3.0 The Keyboard and Display ......................... 4.0 Modifying Data ................................... 5.0 Deleting Data .................................... 6.0 Inserting Data ................................... 7.0 Locating Data .................................... 8.0 Go to a Position in the File ................... 8.1 Search for Data ................................ 8.2 Print the File ................................... 9.0 Save the File .................................... 10.0 Help ............................................. 11.0 A Useful Example - Modification of DOS 5's EDIT ................... 12.0 Installation ..................................... Appendix A Disclaimer ....................................... Appendix B Support .......................................... Appendix C Registration ..................................... Appendix D 1.0 What Is EXC? One thing most of us learned early on after working on our first PC was that EDLIN, while useful, stank (stunk?) as a editor of text files. Soon there were hundreds of full screen text editors available everywhere. Even Microsoft finally came around and include EDIT is DOS 5 to get us away from EDLIN. An early lesson that most who aspire to be power users learn is that not all changes we desire to make are in text files. Sooner or later we end up patching an executable program, database for strange format file that text editors will not handle. Enter DEBUG. Just as EDLIN was a pain for editing text files DEBUG is a pain for editing binary files. Strangely few people have jumped out with binary editors and the few I have seen are not much better than DEBUG. Even Microsoft is making us stick with DEBUG, and as a bonus, have taken the documentation for DEBUG out of the DOS documentation. I guess they feel it is too dangerous for ordinary mortals. My feeling is, it's my file and I'll corrupt it if I want to. BEDIT is a very easy-to-use full screen editor for binary (or text) files. You simply type over the hex or ASCII data much as you would with any text editor. BEDIT ensures that you enter hex characters (0-9 and A-F) while you are in hex entry mode. You be able to see the hex and ASCII representations at all times whether you are editing in hex or ASCII. Using BEDIT is so intuitive, I don't know why I'm writing this documen- tation or why you are reading it. Perhaps we both like to move cautiously. You see a full screen of data at all times, not just a few bytes. Paging through the file is as easy as hitting PgUp and PgDn, you don't have to enter hex displacements. I think you'll find, as we have at a Fortune 100 comapny (my day job), that BEDIT becomes one of the handiest tools you have. You will use it much more than you now expect that you will. BEDIT automatically detects and uses any available LIM 4.0 EMS expanded memory. 2.0 The BEDIT Command Line Format: BEDIT [path]filename [/N] The filename is the file name of the file that you want to edit. BEDIT does not make an automatic backup, so back it up if you think there could be problems. The path is required if the file is not in the current directory. Specify /N if you do not want BEDIT to use EMS memory. 3.0 Operational Notes It bears repeating at this point that BEDIT DEOS NOT MAKE AN AUTOMATIC BACKUP of the edited file. Since much of the usefulness of BEDIT is to just view or print the contents of a binary file, I did not want BEDIT cluttering up my directories with backup files. If you intend to modify a file with BEDIT, I highly recommend making a backup file first for obvious reasons. Since BEDIT will allow you to change any file in any way, it is obviously a very dangerous weapon in the hands of the unskilled as well as a very powerful tool in the hands of the skilled. Please be careful! BEDIT reads the entire file into memory before any edits are performed. All changes are made only to the copy in memory until a SAVE is done. If you have LIM 4.0 compatible EMS memory, you are limited in editable file size to the amount of free expanded memory. If you have no expanded memory, or use the /N parameter, the file is loaded into conventional memory. Depending on your memory configuration, you should be able to load a file of 400-500 Kbytes without the use of expanded memory. If your available expanded memory is less than your available conventional memory, use the /N option to load larger files. Usually there is more expanded memory than conven- tional, so excluding the /N option allows larger files to load. 4.0 The Keyboard and Display There are two modes of editing in BEDIT. When you first load a file, screen cursor appears with both hex data and its ASCII representation dis- played in seperate sections of the screen. The cursor is initially placed in the hex portion of the screen for editing in hex. The character (repre- sented by two hex digits) at the cursor location appears red on color mon- itors. The same character on the ASCII (right) side will be light cyan. All other data charcters are yellow. As the cursor moves, you will see the light cyan highlighting on the ASCII display move with the cursor and red letters of the hex display. Pressing F10 places the cursor in the ASCII portion and the display at the cursor becomes red. The corresponding position in the hex data becomes light cyan. F10 toggles the cursor back and forth between the two editing areas. The ASCII display does not display every displayable character, but only letters and numbers and the more common punctuation symbols that are common to most printers. You can only enter these characters on the ASCII side. To enter exotic characters you must use the hex representation on the hex side. Periods are place in the ASCII display for all non-displayable characters. If a blank appears, it is because there is a true blank (hex 20) at that position. The following keys function as shown during editing: Page Down - Display the next page of data. Page Up - Display the previous page of data. Home - Position the cursor at the start of the file. End - Position the cursor at the end of the file. Down Arrow - Move the cursor down one line. Up Arrow - Move the cursor up one line. Right Arrow - Move the cursor right one byte. If at the end of a line, move to the first byte of next line. Left Arrow - Move the cursor left one byte. If at the start of a line, move to the last byte of the previous line. Enter, Tab - Same as right arrow. Back Tab - Clears the byte. You must then type something in the byte before the cursor can be moved. Insert - Insert one byte. Everything beyond this byte is shifted one position and a hex 00 byte is inserted at the cursor. Delete - Delete one byte at the cursor. Function keys: F1 - Display the help screen. F2 - Save any changes to the file on disk. F3 - Insert a specified number of bytes at cursor. F4 - Delete a specified number of bytes at cursor. F5 - Move the cursor to a specified address within the file. F6 - Print the file to LPT1:. It appears in basically the same format as displayed. F7 - Not used. F8 - Specify a search argument and locate the first occurance of it in the file. F9 - Locate the next occurance of the search argument. F10 - Toggle the cursor between the hex entry area and the ASCII entry area. ESCAPE - Exit BEDIT. 5.0 Modifying Data Modifying data is very simple, just type over it. Use the F10 key to select the hex or ASCII area. When typing in the hex area, only valid hex characters, 0-9 and A-F are allowed and upper case is forced. When entering data in the ASCII portion, only common printable characters are allowed and upper or lower case may be used. 6.0 Deleting Data First place the cursor on the first byte of the data that you want to delete. Pressing the DELETE key deletes one byte of data at this position. Press DELETE repeatedly to delete several bytes. If a large block needs to be deleted, press the F4 key and reply to the prompt with the number of bytes you want to delete starting with the byte at the cursor. 7.0 Inserting Data BEDIT, rather using an insert mode, lets you insert bytes of binary zeros, hex 00, into the file. You can then type over the inserted bytes with the data that you require. Place the cursor at the byte where you want the data inserted. The data is inserted BEFORE the byte at the cursor. Pressing the INSERT key inserts one byte at a time. If a large block needs to be inserted, press F3 and specify the number of bytes you want inserted. Once the null bytes appear, type over them if required. In order to add bytes to the end of the file, press END to go to the last byte of the file then press the right arrow. Each press of the right arrow adds a byte to the file. To enter a large block at the end of the file, press the right arrow once, then press F3 and specify the number of bytes needed less one (since you already added one when you pressed the right arrow). 8.0 Locating Data There are basically three ways to move the cursor to an area you want to edit. First you can use Page Down and Page Up to visually look for that area you want. Primitive but effective. Second, if you know the offset into the program of the area you want to modify, press F5 and type the offset in hex. The third method is to let the computer search for a known byte config- uration. 8.1 Go to a Position in the File An offset or displacement is measured from the start of the file. The first byte is offset 0, the second is 1, etc. When you press F5, you are prompted for an offset which you provide in hex. The cursor is the placed at that address and display is updated to show the data at the cursor. This method is often used in applying documented patches supplied by a software vendor. 8.2 Search for Data Pressing F8 pops up a dialog box that request entry of a search argument. After supplying this argument, the cursor is positioned to the first occurance of that value in the file. If it is not found, the cursor will appear on the last byte of the file. If a first occurance is found, pressing F9 searches for the next occurance. If a second is found, pressing F9 again searches for the third occurance, and so on. If the cursor is in the hex editing area, you will be prompted for up to four hex bytes of search argument (eight hex digits). When the cursor is in the ASCII editing area, you may enter upt to 8 ASCII characters for a search argument. Admittedly the search arguments are small, but I have found that when editing binary files, you are generally not looking for long strings. Hex data is normally entered in sets of two hex digits (nibbles) since it takes two hex digits to represent one byte. If you enter an odd number of hex digits, a zero nibble is prepended to the argument. For example, if you enter 18A, the resulting two bytes that are located are 01 8A. No byte swapping is ever done to accomodate the PC's low-high storage scheme of interger data. So if you are looking for an interger value of 1000 (decimal), you would search for hex 3E8, which in turn is stored as hex E8 03. Thus, the search argument you would provide is E803. If you don't have a clue what this means, you probably don't need to be concered about using BEDIT in this manner. 9.0 Print the File Printing the file is easy. You just press F6 and the output is sent to stadard print (PRN). The format is side-by-side hex/ASCII like that dis- played on the screen with offsets at the start of each line. 896 (hex 380) bytes are printed on each page. The pages are numbered and the file name appears at the beginning of each page. 10.0 Saving the FIle Prior to pressing F2 to save the file all modifications are only done in memory. F2 writes the image in memory over the file that was originally loaded, and the changes become permanent. 11.0 Help Pressing F1 pops up a help screen decribing the editing and function keys. Pressing ESCAPE (or any key when last page is displayed) removes the help window and returns you to the editor. Page Down and Page Up can be used to move between help pages. 12.0 A Useful Example - Modification of DOS 5's EDIT I prefer DOS 5's EDIT command by leaps and bounds over the EDLIN of previous DOSes, but there is one thing I especially don't like about it. When you select File/Open, it comes up with a default file list specification of *.TXT, like that is the only extension ever used for ASCII text files. I would prefer *.* and let me choose from all of my files. After reviewing all of the options, it appeared to me that there was no way to set this value to *.*. My next thought is that since there doesn't appear to be any type of configuration file for EDIT, the *.TXT string must be in the program, so I'll just pull out my trusty BEDIT and zap it to *.*. Let's do it. Go to your directory where you keep DOS (usually C:\DOS). Type BEDIT EDIT.COM. Since we know we are looking for an ASCII string of *.TXT, press F10 to swap the cursor to the ASCII area and press F8 to search. Enter *.TXT and press ENTER. You now find that your cursor is positioned on the last byte of the file. This means it didn't find the string we were looking for. Strange. But look! Right above our cursor is some messages that EDIT.COM displays. One of the reads "Can not find file QBASIC.EXE." Oh yeah, I read somewhere that the EDIT editor with DOS 5 was a version of the QBASIC editor. Let's press ESCAPE, answer 'Y' and get back to the DOS prompt. Now let's enter BEDIT QBASIC.EXE. Aha! Again let's go the ASCII area with F10 and serach for *.TXT with F8. Bingo! We found it. If you are faint-of-heart (wise) you can exit at this point and make a backup of QBASIC.EXE by copying it to QBASIC.BKP or some such file name. The go back in BEDIT of QBASIC.EXE, and repeat the search to get back to where we were before. In my copy of DOS 5.0's QBASIC.EXE, I am now at a displacement of hex 3BCCA into the program and the cursor is positioned on the * of string *.TXT. Hit the right arrow twice to position the cursor on the first T. Type an asterisk (*). The string now shows *.*XT and the cursor is on the X. Lets change the X and T to hex 00s, which in most languages is used to terminate a string. Since we can't enter a binary zero field in the ASCII area, press F10 to switch the cursor back to the hex area. Now type four 0s. As you can see you have now changed the XT characters from hex 54 58 (the hex representation of X and T) to hex 00 00. This is what we wanted to do, so now let's save the file by pressing F2. Exit to DOS by pressing ESCAPE and Y. Now type EDIT and go to fie File/Open screen. Lo and behold! It now reads *.* and all of the files in the current directory are displayed in the pick list. If you made a backup, you can go delete it now. APPENDIX A Installation BEDIT is distributed in a ZIP file called BEDIT.ZIP. It contains the following files: BEDIT.EXE The executable file for BEDIT. BEDIT.DOC The documentation file. For best results, unzip the file into a directory on your PATH. If you don't use a directory in your path, you will have to designate the directory containing BEDIT.EXE when executing the program. If you have a utility directory that is on your PATH, this is an excellent location for BEDIT. An example installation would be: C: CD \UTIL COPY [path]BEDIT.ZIP PKUNZIP BEDIT DEL BEDIT.ZIP The PKUNZIP program is by PKWARE, Inc. and is available in many CompuServe forums under the file name of PKZ110.EXE. Since you are reading this doc files, you have obviously already managed to unZIP the distribution file. If it is not currently in your path, simply copy all of the files to a directory in your path. Keep the BEDIT.ZIP file anywhere you like, but give plenty of copies, as is, to your friends. If you register BEDIT, you are not licensed to give your serial number to anybody without first removing the serialization from your copy. APPENDIX B Disclaimer BECAUSE OF THE DIVERSE NATURE OF COMPUTER EQUIPMENT AND EXPERTISE OF USERS, PARITY SOLUTIONS AND GARY C. CRIDER MAKE NO WARRANTY ON THE BEDIT PROGRAM WHATSOEVER, EXPRESS OR IMPLIED. THE USER ASSUMES ALL RISK OF DAMAGE TO DATA OR EQUIPMENT RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OR MISUSE OF THIS PROGRAM PRODUCT. THE USER MUST BE AWARE THAT USING BEDIT TO MAKE ALTERATIONS TO PROGRAMS OR DATA CAN RENDER THAT PROGRAM OR DATA USELESS. USERS ARE ADVISED TO TEST MODIFICATIONS MADE WITH BEDIT THOROUGHLY ON FILES FOR WHICH A BACKUP EXITS. ANY LIABILITY OF THE AUTHOR OR PARITY SOLUTIONS IS LIMITED TO REPLACEMENT OR REFUND OF THE REGISTRATION FEE. APPENDIX C Support I have tried to test the program to the fullest, but I am limited as to systems and configurations with which to test. I have been programming for 18 years and the one thing I know for sure is that bug free programs are very few and far between. I can only promise to support the program to the best of my ability and provide fixes as expeditiously as possible. BEDIT has been used at my home and worksite extensively for several years and has proven to be a reliable tool. Anyone can report problems and suggest changes. Registered users get top priority in resolving their problems. There are three ways you can report problems. The preferred method is to contact me through CIS mail (not forum messages). My CIS ID is 71760,3413. You can also write me at: Gary C. Crider Parity Solutions 1105 Burgess Court Arlington, TX 76015 The last method is to phone (817) 467-7818. Since I am the sole technical support and the line is also used for my network consulting business, it is often hard to get through to me. Please call and leave a message between 7:30 am and 5:30 pm Central time. No matter which method you use, please give a brief description of your problem, your registration serial number if you are registered, and your phone number. If I need more information, I will contact you as soon as I can. When I have a solution, I will contact you however you prefer. I work full time, have a consulting business to run in my spare time and write programs instead of sleeping. So please be a little patient with me. APPENDIX D Registration I begin with an apology. I hate programs that in any way inhibit func- tionality or performance for the shareware version. But when it came down to feeding the family and paying the bills, I had a change of heart and inserted a pesky notice that pops up at the beginning and gets on your nerves. I chose this approach above that of limited functionality. The program's full capabilities are available for you to evaluate before you invest your hard- earned money. Registered users will receive a unique serial number and instructions on how to serialize the program. Serialization can be re-applied to updated versions and in no way hinders your use of the program. You can compress or decompress the program with no effect (LZEXE or PKLITE). I use Fabrice Bellard's LZEXE program on EXC.EXE before distribution. As a registered user, you will be able to update without re-registration or additional fees. You will also be kept on my PRIVATE mailing list to receive additional information on other Parity Solutions products. Registered users will be entitled to a discount on any present or future Parity Solutions software. To register your copy, please send $10 ($45 per file server on LANS) check or money order (sorry, no credit cards yet) to: Gary C. Crider Parity Solutions 1105 Burgess Court Arlington, TX 76015 Each license gives you or your company a single use permit for BEDIT. It is not restricted to a single machine as long as no two users can be simul- taneously using the program. As Borland says, "treat it like a book." As an example, if you register BEDIT for your home computer, but during the day you use a portable or a computer at work, you may keep BEDIT on both machines as long as no one is at home using it on your home computer. LAN licenses grant rights to all users of a file server. If inter- networking, a license must exist for each file server that contains a copy of BEDIT.EXE. If two or more file servers exist on a single LAN strictly for mirroring data and fault-tolerance, these will be counted as a single file server for licensing purposes. If in doubt, contact me. We can work out an agreement. Site licensing is also available on a negotiated price basis. I gaurantee it will be an economical alternative to buying licensines for each user. You may freely distribute the original BEDIT.ZIP file in any way you see fit other than selling it. Users' groups and shareware distribution services may charge a reasonable fee for the medium and duplication costs, not to exceed six dollars. Bulletin boards may not charge additional fees for downloading this specific program, other than normal connect-time and/or membership charges. You are NOT licensed to give anyone your serial number unless you first remove all serialization from your computer. You may then no longer use that serial number. Only Parity Solutions has the authority to issue serial numbers.