# Hex File Dump/Edit Utility

Topics
Usage | Compiling

Usage

The Hex Dump utility is a console-based program used to display the contents of a binary file in hexadecimal format. This program can also be used to edit a binary file using any text editor. To use the utility, enter the name of the program followed by the name of the binary file. NOTE: If you do not specify an output file name, the program will write to stdout.

    hexdump -p myfile.bin (Write to console)

    hexdump myfile.bin myfile.txt (Write to myfile.txt file)

    hexdump myfile.bin > myfile.txt (Redirect to file under UNIX and DOS)

    hexdump myfile.bin >> myfile.txt (Append to file under UNIX and DOS)

You can pass one of several switches to the program from the command line. For a list of switches, execute the program with no arguments or with a "-?" argument: "hexdump" or "hexdump -?".

    Hexadecimal file dump program version 1031.101
    Usage: hexdump [switches] infile outfile (optional)
    Switches:  -?      = Display this help message.
               -c      = Display 32-bit CRC checksum value.
               -C      = Display 16-bit CRC checksum value.
               -d      = Display in decimal mode (Default is HEX).
               -p#     = Prompting after displaying # line: -p10
               -r      = Rebuild binary file from hex dump text file.
                         Only works for files created in hex mode.
               -s      = Strip comments from output.

               -x      = Convert 32-bit HEX number to DEC: -Xfefe
               -X      = Convert signed 32-bit HEX number to DEC.
               -B      = Convert 32-bit HEX number to binary: -Bfefe
               -D      = Convert DEC number to HEX: -D23

The "-c" switch is used to display a 32-bit checksum for a file.

The "-C" switch is used to display a 16-bit checksum for a file.

The "-d" switch is used to display the binary file in decimal format. The default is hexadecimal format. NOTE: A text file created in decimal format cannot be used to perform a hex edit.

The "-p#" switch is used to enable prompting when dumping a binary file to the console. You must specify the number of lines to scroll when dumping a file. If the "-p#" option is not specified, the entire file will be dumped.

The "-s" switch is used to strip the comments from the hex dump output.

The "-x", "-X", "-B", and "-D" switches are used to convert values between different number systems.

The "-r" switch is used to build a binary file from a hex dump text file.

All hex dump text files have 16 bytes per line. A tab, a semicolon, and then any printable characters follow the end of the byte string. All non-printable characters will be represented by a dot. The rebuild function will truncate any characters following the byte string before building the binary file. A single tab or a semicolon always represents the endof the byte string. Each byte in the byte string is represented by two characters and must be separated by a single space, with a maximum of 255 bytes per string. The rebuild function parses the byte string and writes each byte to the specified output file. If no output file name is specified, the rebuild function will create a file named "outfile.bin".

In order to perform a hex edit on a binary file you must first create a hex dump text file:

    hexdump landb.pod landb.txt

After creating the hex dump text file, use any text editor to edit the file:

    edit landb.txt
    emacs landb.txt
    vi landb.txt

    00 00 00 00 8D 00 00 00 1C 00 00 00 1C 00 00 00         ;................
    56 42 44 46 49 4C 45 20 00 04 00 00 FE FE 00 00         ;VBDFILE.........
    71 00 00 00 4E 00 00 00 00 00 00 00 E9 03 00 00         ;q...N......._...
    2C 00 00 00 08 00 00 00 6C 6F 6F 70 62 61 63 6B         ;,.......loopback
    09 00 00 00 31 32 37 2E 30 2E 30 2E 31 03 00 00         ;....127.0.0.1...
    00 4E 2F 41 03 00 00 00 4E 2F 41 03 00 00 00 4E         ;.N/A....N/A....N
    2F 41 03 00 00 00 4E 2F 41 03 00 00 00 4E 2F 41         ;/A....N/A....N/A
    03 00 00 00 4E 2F 41 12 00 00 00 6C 6F 63 61 6C         ;....N/A....local
    68 6F 73 74 2F 6C 6F 6F 70 62 61 63 6B                  ;host/loopback

After editing the file, rebuild the binary file with the "-r" option:

    hexdump -r landb.txt newfile.pod

Compiling

Console Base Utility Program

:
Four makefiles are provided in the "utils" directory to compile the source code on one of four different compilers.

    "msvc40.mak"  - Makefile for Microsoft visual C/C++ 4.2
    "djgpp.mak"   - Makefile for DJGPP gcc 2.7.2.1
    "gnu_gcc.mak" - Makefile for GNU g++ 2.7.2.1
    "hpux10.mak"  - Makefile for HPUX C++ A.10.24

Building the Executable:

To compile use the "make -f" option followed by the makefile name. To compile using MSVC use the "nmake -f" option. The resulting executable will be named after the name set by the PROJECT macro in the makefile. By default the program will be named "hexdump" under UNIX or "hexdump.exe" under Windows 95/DOS.

Installing:

Execute a "make -f (makefile name) install" to move the executable to the "bin" directory.

Removing the Object Files and the Executable:

To remove the object files and the executable use the "make -f" option followed by the makefile name, followed by "clean": make -f hpux10.mak clean

Under MSVC use the "nmake -f" option followed by the makefile name, followed by "clean": nmake -f msvc40.mak clean

End Of Document