From ProjectWiki
Jump to: navigation, search

Hexdump code

What is it?

Wrote this a few years ago, thought it may be useful to someone, so here. :D

These functions will display the contents of memory in the form:

aaaaaaaa dd dd dd dd dd dd dd dd dd dd dd dd ........

where aaaaaa is the adresss being displayed, dd is the data, and '.' is the ascii representation (if within range)

most variables are self expanitory...

Source code

Example program, this may be copied and saved as main.c or such, compiled and tested. Or copy/pasta the parts you need. ^^

/*Prints one line only of hex, used by c_dump()*/
/* like xx xx xx xx xx xx xx xx xx xx xx xx ........*/
int hexline(unsigned char *bytes, int cnt) {
                int col=0;
                if(cnt>0x10) cnt=0x10;
                while(col < cnt) {
                        printf("%02x ",bytes[col++]);
                while(col++ < cnt) {
                        if(*bytes>=0x20 && *bytes<0x80) {
                        } else {
                return col-1;
void hexdump(unsigned char *addr, int len) {
	unsigned char *end=addr+len;
	while (addr<end) {
		printf("%08x: ",addr);
void main(void) {
	char buff[]="hai2u^_^blah blah balh hai hai hello kitty meow purr \n";
Personal tools
irssi scripts
eggdrop scripts