Monday, 6 July 2009

silly james, quick c hexdump

Not AGAIN! DOH. ended up writing a quick c hexdump AGAIN :(.


void hexdump(char *msg, char *buf, int len)
{
int i;
char c;
char str[0x11];
if (msg != NULL) printf("%s: %s\n", __func__, msg);
i=0;
while(i<len){
if (i%0x10 == 0) printf("%08x: ",i);
c = *(buf+i);
printf("%02x", (int)c);
str[i%0x10] = '.';
if (c >= 32 && c<=120) str[i%0x10] = c;
if (i%2 == 0) printf(" ");
if (i%0x10 == 0xf) {
str[i%0x10+1] = 0;
printf(" %s\n",str);
}
i++;
}
if (i%0x10 != 0xf) {
str[i%0x10+1] = 0;
printf(" %s\n",str);
}

}

No comments: