These utilities are provided under the GNU license. They are free to use. Please
pass any changes, modifications or suggestions to the author Phil Braham:

realtime@mpx.com.au

================================================================================
bdump Version 3.5

bdump dumps a file in hex or ascii. 

To make simply enter:
	make bdump

Copy bdump to /usr/bin (You will need root access for this).

Better version than the Linux od command as bdump can display hex and ASCII side
by side. It has a number of formatting parameters.

For help enter:

	$ bdump -h

Dump a file to the terminal in hex and ASCII format.
./bdump [-abcdDfhlmnorRsvwxzZ01u] [-] [<filename to dump>] [...]
	-b Byte.     Display in sets of 1 byte
	-s Short.    Display in sets of 2 bytes
	-l Long.     Display in sets of 4 bytes (default)
	-n Narrow.   Display 16 bytes per line
	-m Medium    Display 32 bytes per line (default)
	-w Wide.     Display 64 bytes per line
	-a Ascii.    Display ascii only
	-x Hex.      Display hex only
	-f Full.     Display both hex and ascii (default)
	-0 0-pad.    Pad with leading zeros (Number 0)
	-1 0-pad*.   Don't pad with leading zeros (number 1)
	-z Zero.     Skip display A of lines containing only zero (NULL) bytes
	-Z Zero*.    Don't skip display A of lines containing only zero (NULL) bytes
	-d Display.  Display the name of each file before the output
	-D Display*. Don't display the name of each file before the output
	-r Reset.    Reset the byte count for each file dumped
	-R Reset*.   Don't reset the byte count for each file dumped
	-o<s>:<e>    Starts and ends the dump from the specified offsets
	-c[<char>].  Set formatting (See note)
	-u<char>     In ascii mode, specifies the unprintable character. See note
	-h Help.     Print this help
	-v Vers.     Print version number

If no filename is supplied or filename is - then stdin is used.
If more than one filename is supplied then each is processed in turn.

Note that -1 turns off -0 and similarly the options -R, -D and -Z turn off their
counterparts -r, -d and -z

The option -u must be on its own (eg -u -z or -u* -z). By default a . is
displayed to represent unprintable characters. -u on its own uses a space,
otherwise the specified character is used.

The option -c must be on its own (eg -c -z or -cr -z). -c on its own disables
formatting (as does -cn). The format defines how all characters not part of the binary
(including filenames and ascii unprintable characters) are displayed. The uppercase character
reverses this. Allowable characters are:
	eE - Emphasis (black)
	rR - Red
	gG - Green
	yY - Yellow
	bB - Blue
	mM - Magenta
	cC - Cyan
	wW - White

The option -o specifies the start and end offsets for the dump (in hex). By default
dumping is from the start of the file to the end. The start and end are separated by :,
eg -o1000:4400. Either start or end can be left out. eg -o:FFFF, -o1000.

To change default options set up an alias. Eg:

        alias bdump='/usr/bin/bdump -dcr'

Note that colour fommatting can interfere with the 'more' command. Use 'less -r'. eg:
	bdump -cR testfile | less -r

=========================================================================================
bdumpr version 1.1 22-DEC-2004  Phil Braham

Converts the output of bdump back to a binary file.

To make simply enter:
	make bdumpr

Copy bdump to /usr/bin (You will need root access for this).

Converts the output of bdump back to a binary file.
bdumpr [-bhlmno:svw] [<input filename>] [-]
	Where <input filename> in the output of bdump. If no filename
	is supplied or filename is - then stdin is used.

	-b Byte.     InputFile is in sets of 1 byte
	-s Short.    InputFile is in sets of 2 bytes
	-l Long.     InputFile is in sets of 4 bytes (default)
	-n Narrow.   InputFile is 16 bytes per line
	-m Medium    InputFile is 32 bytes per line (default)
	-w Wide.     InputFile is 64 bytes per line
	-o<bytes>    Specify max number of bytes to output
	-h Help.     Print this help
	-v Vers.     Print version number

The formatting command correspond to the commands in bdump so that bdumpr is able
to determine the format of the input file.

Note that if the file format is not -b (bytes) then it may not be possible
for bdumpr to determine the exact number of bytes in the file if the size is not
an exact multiple of the format size (ie, 4 for for long, 2 for bytes). In this
case bdumpr may output unnecessary null bytes at the end of the file. Using
the -o option forces bdump to only output the necessary number of bytes.

Output is to stdout.

bdumpr allows a user to produce a human-readable hex file from a binary file, edit it and then
turn it back into a binary file.

Usually bdumpr can work out the format of the input file from the length of the first line but it
will not be able to do this in some situations. For example where the -x was used or where the file
is very short. The options to bdumpr can be used to override the format that bdumpr has determined,
or where it is unable to determine a format. The options used must correspond with the options used
to produce the file with bdump. For example, if the file was produced as follows:

	$bdump -bw testfile >testfile.bd

Then the command to bdumpr would be:

	$bdumpr -bw testfile.bd >testfile_v2

Caveats:
    bdumpr is not yet able to process files which have colour formatting characters.
    If the input file was produced from concatenating a number of files, the output will be
        unpredictable.
    The ascii portion of the input file is currently ignored but is used to determine the format.
    The byte offset part of the input file is currently ignored. If the file was produced
        using the -o option the output will start from offset 0 regardless.
    Using the incorrect formet (eg -b for a file produced with -l) will garble the output
        (usually the bytes will be swapped)

Example:

The C program as follows:

    int main (int argc, char *argv[])
    {
            int i =7;

            printf ("Value = %d\n", i);
    }

This is compiled into an executable called testfile:
    $testfile
    Value = 7

The file is converted to readable form with:

    $bdump -bn testfile >testfile.bd

Offset 0440 is as follows:

0440:  3  0  0  0  1  0  2  0 56 61 6C 75 65 20 3D 20    ........Value =

We edit the file as follows:

0440:  3  0  0  0  1  0  2  0 54 68 69 73 20 3D 20 20    ........Value =

Note that the ascii section of the file is ignored.

Convert back to binary and make executable:

    $bdumpr -bn testfile.bd >testfile_v2
    $chmod +x testfile_v2

Now run it:

    $testfile_v2
    This =  7
