Skip to content

🔧 A library to print a buffer as typical hex-view with highlighted regions on the console screen.

License

Notifications You must be signed in to change notification settings

rstemmer/libprinthex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libPrintHex

libprinthex provides a function to print a hex dump with colored sections.

Example output

Project State: Alive and maintained

Tested on Linux with Konsole and MacOS with Terminal

Installation

You should check the install.sh script before executing. The default installation path is /usr/local/{lib,include}

./build.sh
sudo ./install.sh

Usage

int printhex(void* buffer, int size, int bytesperline, ... );

This function prints the bytes of a buffer as a typical hex-view to the screen.

void* buffer

buffer points to the bytes that will be printed by printhex. This can be anything as long as there is read access to size bytes started at the address buffer points to.

int size

The size is the number of bytes that will be printed in total. It should be less or equal to the buffer buffer points to.

int bytesperline

This parameter determines how many bytes will be printed in each line. A good argument would be 16.

...

The optional arguments are in alternating offset and color. There can be as many pairs of offset and color as there are bytes in the buffer. When the internal index to the values inside the buffer reached offset, the new text color gets read from the argument list. Furthermore the next offset will be read. So the algorithm expects an infinite list of offsets and colors. The last value has to be an offset that will never be reached (a good value is -1).

The offset must be an integer between 0 and bytesperline - 1. Furthermore it must be greater than the previous offset given in the list or arguments. It determines the offset from which a new color will be used to print the values of the buffer.

The color is the ANSI escape sequence for the color that will be used to print the values of the buffer after the offset related to that color is reached.

return value

This function always returns 0

Example

// Display Hello World, with World in green letters
char *helloworld = "Hello World";
printhex(helloworld, strlen(helloworld), 16, 
        6, "\e[1;32m",   // Green World
        -1);             // (end of offset/color list)
printf("\n");

You will find a real example in the test.c file.

About

🔧 A library to print a buffer as typical hex-view with highlighted regions on the console screen.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published