Last active
December 16, 2015 11:48
-
-
Save toshikazuhorii/5429719 to your computer and use it in GitHub Desktop.
バイナリダンプ用 Helper ref: http://qiita.com/items/af61f02772e8a06caca8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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