Tag: hexed

Hexed bugfix #1

Hexed had a problem on Windows with CR, LF line conversion. Hexed opened the file using the ‘r+b’ file mode but MinGW seemed to ignore the file mode and opened the file in text mode. I’m now setting the _fmode from fcntl.h to _O_BINARY. This fix only compiles on Windows for the MinGW compiler and is done in a separate file, bfcntl.c, to stop any warnings about DLL settings.

Hexed now also shows the version number on the help screen with the command hexed -?

The last thing is I’ve added a Support section to the Sourceforge site for hexed. This should be used to report bugs and request new features.… more...

hexed – commands move & word

The last few commands have been added to hexed today, these are move, move overwrite and word size. Move is similar to the copy command with 2 modes of operation, while the word command sets the word size between 8 bit, 16 bit, 32 bit and 64 bit word sizes.

The Command List

Move: -m

Moves data from the source to the destination

-m 100 200 20

Will move 32 bytes from 0x100 to 0x200 and move everything from 0x120 to 0x220 down by 32 bytes.

Move Overwrite: -mo

Moves the data from the source to the destination over writing the original data at destination

-mo 100 200 20

This will move 32 bytes from 0x100 to 0x200 but will insert zeroes into the file below the destination. This way the data will appear where you expect it to be after the move.

Word size: -w

Sets the data word size for most commands like dump, enter, insert etc.

-w 2

This will set the word size to 16 bit so when used with a command like dump will display the data as 2 bytes long as in this example:

hexed -w 2 -e 18 ffff abcd 1234 dead -d
00000000  0000 0000 0000 0000  0000 0000 0000 0000  ................

hexed – command copy

The copy command was added to hexed a little while ago. This command has 2 modes of operation: copy (c) or copy overwrite (co).

The Command List

Copy: -c

Copies data from the source inserting it at the destination

-c 100 200 20

This will copy 32 bytes from 0x100 to 0x200 moving everything at 0x200 up by 32 bytes.

Copy Overwrite: -co

Copies data from the source overwriting the destination

-co 100 200 20

Copy 32 bytes from 0x100 to 0x200 overwriting the original data.… more...

hexed – commands insert & remove

A small update with 2 new commands, insert and remove, having been added to hexed. Insert first moves any data at the end of the file then inserts the bytes from a buffer and removes deletes bytes from the buffer.

The Command List

Insert: -i

Inserts bytes in the file at the destination, repeating the bytes for a number of times.

-i 100 10 01 02 03

This will insert the bytes 0x01 0x02 0x03 at 0x100 16 times.

Remove: -r

Removes a number of bytes from the file starting at the source.

-r 10 100

Removes 0x100 bytes from the file at 0x10 to 0x110.… more...

hexed – commands help, dump & enter

Command control has been added to hexed and the first 3 commands are help, dump and enter. Command control is handled by a Command struct and a Cmdoptions struct. Each command is set with an ID, flags and any options in the Cmdoptions area. Cmdoptions is general purpose and shares common names for values between all the commands. Any extra data is stored in a buffer before being copied to the file. Multiple commands can be set on the command line and these are performed in the order they are found.

hexed -d 0 100 -e 40 10 20 30 40 -d 0 100 test.hex

This will display the file test.hex, enter 4 values at 0x40, display the file again then save the file and quit.

The Command List

Help: -?

Help simply displays the command list and how to use each command:

hexed - Hexadecimal File Editor

  hexed [options] [file]

  -?                            Shows this help screen
  -d [src] [len]                Display hex values from [src] for [len] bytes
  -e [dest] [...]               Enter hex values [...] at [dest]

Dump: -d

The dump command displays a range of values and their ascii symbols:

-d 0 100

Displays values starting from 0x0 for 0x100 (256) bytes, all options to commands are set in hex values.… more...

Buffered file access – Bfile

There may already be a method or library for handling files in memory but I wrote this to easily add and remove bytes without constantly reading or writing to a file. Bfile reads the whole file into memory before working on it by using the bfread, bfwrite, bfclip and bfinsert functions.

bfopen() opens a file and sets the initial values in the Bfile struct.
bfclose() flushes the buffer to the file and closes the file.
bfflush() flushes the buffer to the file.
bfread() reads the entire file into a Bfile buffer.
bfwrite() writes from memory to the Bfile buffer, but not to the file.
bfclip() removes data from the Bfile and adjusts the file size.
bfinsert() inserts data from memory into the Bfile and adjusts the file size.

Writing to the file needs to end with a bfflush and this is done automatically when the file is closed with bfclose.


Source: bfile.hbfile.cmore...

Project: hexed

Well the current project is hexed, a command line HEXadecimal file EDitor. The first update is a simple test for cmdargs, a command line argument parser. Cmdargs is released as public domain software so you can use it in other projects without restrictions. Cmdargs can handle both long and short arguments with options. For long arguments cmdargs can accept either ‘‐’ or ‘‐‐’ as the argument switch. Any short arguments that don’t require an option can be set in the same switch (-a -b -c  or -abc). Options can be set either by ‘:’, ‘=’ or with whitespace as in (-e:10 -b=100 -f filename). The accepted arguments are passed as a single struct array called Arglist with longer args listed before shorter ones in alphabetical order.

Arglist arglist[] = {
{"bar", 0},       // set the bar arg
{"b", 0},         // set the b arg
{"foobar", 0},    // set the foobar arg
{"foo", 0},       // set the foo arg
{"f", 0},         // set the f arg
{NULL, 0}         // must be the last entry

This struct and argv from main() are sent to parsecmdargs() in a loop until the end of the arguments are reached.… more...