void hexdump(const void * buf, size_t size) { const uchar * cbuf = (const uchar *) buf; const ulong BYTES_PER_LINE = 16; ulong offset, minioffset; for (offset = 0; offset < size; offset += BYTES_PER_LINE) { // OFFSETXX xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx abcdefghijklmnop printf("%08x ", cbuf + offset); for (minioffset = offset; minioffset < offset + BYTES_PER_LINE; minioffset++) { if (minioffset - offset == (BYTES_PER_LINE / 2)) { printf(" "); } if (minioffset < size) { printf("%02x ", cbuf[minioffset]); } else { printf(" "); } } printf(" "); for (minioffset = offset; minioffset < offset + BYTES_PER_LINE; minioffset++) { if (minioffset >= size) break; if (cbuf[minioffset] < 0x20 || cbuf[minioffset] > 0x7e) { printf("."); } else { printf("%c", cbuf[minioffset]); } } printf("\n"); } }