How to Edit Binary Files in MS-DOS 6.22
In MS-DOS 6.22, the primary built-in utility for inspecting and
modifying binary files directly from the command line is
DEBUG (DEBUG.EXE). This article covers how
DEBUG functions as a command-line hex editor and machine code debugger,
provides the essential subcommands required to inspect and alter binary
data, and walks through a practical step-by-step example of editing a
file safely.
Understanding the DEBUG Utility
DEBUG is a 16-bit program provided natively with MS-DOS to test,
alter, and debug executable files and raw binary data. Unlike text
editors like EDIT.COM, which corrupt binary files by
interpreting control characters, DEBUG interacts directly with raw
hexadecimal bytes in memory.
To load a file into DEBUG, pass the filename as an argument directly from the DOS prompt:
DEBUG FILENAME.BIN
Once loaded, DEBUG displays a hyphen prompt (-),
indicating it is ready to receive internal commands.
Essential Commands for Binary Modification
Navigating and changing bytes within DEBUG requires only a few core single-letter commands:
D(Dump): Displays memory contents in both hexadecimal and ASCII representation. RunningDsequentially pages through the file, or you can specify an offset range (e.g.,D 100 120).E(Enter): Modifies memory starting at a specified address. You can provide replacement bytes in hexadecimal notation directly.R(Register): Displays or modifies CPU registers. When saving files, theBXandCXregisters define the file size in bytes (BXholds the high word,CXholds the low word).W(Write): Writes the loaded or modified data from memory back to the disk.Q(Quit): Exits the DEBUG program back to the standard MS-DOS prompt without saving unlessWwas issued previously.
Step-by-Step Binary Editing Example
To change specific bytes within a target file:
- Load the File: Type
DEBUG TARGET.DATand press Enter. - Locate the Target Data: Type
D 100to dump memory starting at offset0100h(the standard entry offset for files loaded in DEBUG). Note the memory offset where you wish to make changes. - Edit the Bytes: Type
Efollowed by the offset (for example,E 010A). DEBUG will display the current byte followed by a period. Type the new two-digit hexadecimal value and press Space to advance to the next byte, or press Enter to finish editing that address. - Save the Changes: Type
Wand press Enter. DEBUG will report "WritingXXXXbytes" to confirm the changes have been written to disk. - Exit: Type
Qand press Enter to return to the MS-DOS prompt.
Limitations
DEBUG was designed primarily for small 16-bit .COM
programs and raw memory segments. By default, it operates comfortably
within a single 64KB segment. Modifying files larger than 64KB requires
manually managing segment registers and file length pointers, making it
best suited for targeted binary patches, firmware alterations, and small
binary utilities.