Created
February 14, 2021 19:41
-
-
Save mykola2312/80e3035dd12762a046daf0bc28c361e7 to your computer and use it in GitHub Desktop.
This file contains 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_buffer(API::Buffer& buf, unsigned codepage = 0) | |
{ | |
const char ascii_lup = 201, ascii_rup = 187, | |
ascii_lsp = 199, ascii_rsp = 182, | |
ascii_lbt = 200, ascii_rbt = 188, | |
ascii_up_cross = 209, ascii_bt_cross = 207, | |
ascii_cross = 197, | |
ascii_v_sp = 179, ascii_h_sp = 196, | |
ascii_v_border = 186, ascii_h_border = 205; | |
const size_t line = 0x10; | |
//code page | |
if (!codepage) codepage = GetConsoleOutputCP(); | |
SetConsoleOutputCP(codepage); | |
//start | |
putc(ascii_lup, stdout); | |
for (uint64_t i = 0; i < 8; i++) putc(ascii_h_border, stdout); | |
putc(ascii_up_cross, stdout); | |
for (uint64_t i = 0; i < line * 3 - 1; i++) | |
putc(ascii_h_border, stdout); | |
putc(ascii_up_cross, stdout); | |
for (uint64_t i = 0; i < line; i++) | |
putc(ascii_h_border, stdout); | |
putc(ascii_rup, stdout); | |
putc('\n', stdout); | |
//header | |
putc(ascii_v_border, stdout); | |
printf(" offset "); | |
putc(ascii_v_sp, stdout); | |
for (uint64_t i = 0; i < line; i++) | |
printf(i < line - 1 ? "%02x " : "%02x", i & 0xFF); | |
putc(ascii_v_sp, stdout); | |
switch (codepage) | |
{ | |
case CP_UTF7: printf(" UTF-7 "); break; | |
case CP_UTF8: printf(" UTF-8 "); break; | |
default: printf(" ANSI CP #%05d ", codepage); | |
} | |
putc(ascii_v_border, stdout); | |
putc('\n', stdout); | |
//split | |
putc(ascii_lsp, stdout); | |
for (uint64_t i = 0; i < 8; i++) | |
putc(ascii_h_sp, stdout); | |
putc(ascii_cross, stdout); | |
for (uint64_t i = 0; i < line * 3 - 1; i++) | |
putc(ascii_h_sp, stdout); | |
putc(ascii_cross, stdout); | |
for (uint64_t i = 0; i < line; i++) | |
putc(ascii_h_sp, stdout); | |
putc(ascii_rsp, stdout); | |
putc('\n', stdout); | |
//hex dump | |
for (size_t off = 0; off < buf.GetSize(); off += line) | |
{ | |
size_t len = std::min(buf.GetSize() - off, line); | |
putc(ascii_v_border, stdout); | |
printf("%08" FCroOff, off); | |
if (len) putc(ascii_v_sp, stdout); | |
else break; | |
for (uint64_t i = 0; i < line; i++) | |
{ | |
if (i < len) | |
{ | |
printf(i < line - 1 ? "%02X " : "%02X", | |
buf.GetData()[off + i] & 0xFF); | |
} | |
else printf(i < line - 1 ? " " : " "); | |
} | |
putc(ascii_v_sp, stdout); | |
for (uint64_t i = 0; i < line; i++) | |
{ | |
if (i < len) | |
{ | |
uint8_t byte = buf.GetData()[off + i]; | |
putc(byte >= 0x20 ? (char)byte : '.', stdout); | |
} | |
else putc(' ', stdout); | |
} | |
putc(ascii_v_border, stdout); | |
putc('\n', stdout); | |
} | |
//end | |
putc(ascii_lbt, stdout); | |
for (uint64_t i = 0; i < 8; i++) | |
putc(ascii_h_border, stdout); | |
putc(ascii_bt_cross, stdout); | |
for (uint64_t i = 0; i < line * 3 - 1; i++) | |
putc(ascii_h_border, stdout); | |
putc(ascii_bt_cross, stdout); | |
for (uint64_t i = 0; i < line; i++) | |
putc(ascii_h_border, stdout); | |
putc(ascii_rbt, stdout); | |
putc('\n', stdout); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment