Created
June 7, 2018 16:06
-
-
Save Supermilkycow/6fa20bc58d1c9ffc3b0c15cca7dd5d57 to your computer and use it in GitHub Desktop.
Format Outputdebugstring
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 DumpHex(const void* data, size_t size) | |
{ | |
char ascii[17]; | |
size_t i, j; | |
ascii[16] = '\0'; | |
char line_buffer[4096]; | |
memset(line_buffer, 0, 4096); | |
for (i = 0; i < size; ++i) | |
{ | |
char tmp[10]; | |
memset(tmp, 0, 10); | |
sprintf(tmp, "%02X ", ((unsigned char*)data)[i]); | |
strcat(line_buffer, tmp); | |
if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') | |
{ | |
ascii[i % 16] = ((unsigned char*)data)[i]; | |
} | |
else | |
{ | |
ascii[i % 16] = '.'; | |
} | |
if ((i + 1) % 8 == 0 || i + 1 == size) | |
{ | |
strcat(line_buffer," "); | |
if ((i + 1) % 16 == 0) { | |
strcat(line_buffer, "| "); | |
strcat(line_buffer, ascii); | |
OutputDebugStringA(line_buffer); | |
memset(line_buffer, 0, 4096); | |
} | |
else if (i + 1 == size) { | |
ascii[(i + 1) % 16] = '\0'; | |
if ((i + 1) % 16 <= 8) { | |
strcat(line_buffer," "); | |
} | |
for (j = (i + 1) % 16; j < 16; ++j) { | |
strcat(line_buffer, " "); | |
} | |
strcat(line_buffer, "| "); | |
strcat(line_buffer, ascii); | |
OutputDebugStringA(line_buffer); | |
memset(line_buffer, 0, 4096); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment