gaoithe ([info]gaoithe) wrote,
@ 2009-07-06 16:50:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Entry tags:c++ design patterns perl python, hexdump

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);
    }                  
    
}




Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…