22
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

メモリダンプ

Last updated at Posted at 2013-05-15

投稿練習に、メモリダンプ。
最近使うことが少なくなったけど。。。

hex_dump.c
void hex_dmp(const void *buf, int size)
{
    int i,j;
    unsigned char *p = (unsigned char *)buf, tmp[20];

    printf("+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F|  -- ASCII --\r\n");
    printf("--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+----------------\r\n");
    for (i=0; p-(unsigned char *)buf<size; i++) {
        for (j=0; j<16; j++) {
            tmp[j] = (unsigned char)((*p<0x20||*p>=0x7f)? '.': *p);
            printf("%02X ", (int)*p);
            if (++p-(unsigned char *)buf>=size) {
                tmp[++j] = '\0';
                for (;j<16;j++) {
                    printf("   ");
                }
                break;
            }
        }
        tmp[16] = '\0';
        printf("%s\r\n", tmp);
        if (p-(unsigned char *)buf>=size) {
            break;
        }
    }
}
22
20
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?