Skip to content

Instantly share code, notes, and snippets.

@toshikazuhorii
Last active December 16, 2015 11:48
Show Gist options
  • Save toshikazuhorii/5429719 to your computer and use it in GitHub Desktop.
Save toshikazuhorii/5429719 to your computer and use it in GitHub Desktop.
バイナリダンプ用 Helper ref: http://qiita.com/items/af61f02772e8a06caca8
void dump_memory(const void* data, size_t length) {
const int LINE_BYTES = 16;
char buffer[LINE_BYTES + 1];
buffer[LINE_BYTES] = 0;
for (int i = 0; i < length; i++) {
if (i % LINE_BYTES == 0) {
printf("%06x: ", i);
}
unsigned char tc = ((const unsigned char*)data)[i];
printf(" %02x", tc);
if (tc <= 31 || 127 <= tc) {
buffer[i % LINE_BYTES] = '.';
} else {
buffer[i % LINE_BYTES] = tc;
}
if (i % LINE_BYTES == LINE_BYTES - 1) {
printf(" | %s\n", buffer);
}
}
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment