From 6e8bfdcad637a123604622ab87a74acaa4ac1edb Mon Sep 17 00:00:00 2001 From: Jason Coulls Date: Wed, 4 Oct 2023 20:30:08 -0400 Subject: [PATCH] Debugging Hex viewer. --- LogBazooka/HexDumper.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/LogBazooka/HexDumper.cpp b/LogBazooka/HexDumper.cpp index ee880f2..e3991a6 100644 --- a/LogBazooka/HexDumper.cpp +++ b/LogBazooka/HexDumper.cpp @@ -25,18 +25,32 @@ std::wstring HexView(std::wstring source, size_t size) for (size_t chunk_idx = 0; chunk_idx < chunks.size(); chunk_idx++) { - // For each character, get it's ascii value in Hex. + // For each character, get it's ascii value in Hex and its regular representation. std::wstring hex; + std::wstring characters; // New string for characters + for (size_t char_index = 0; char_index < chunks[chunk_idx].size(); char_index++) { wchar_t buffer[5]; swprintf_s(buffer, L"%02X ", chunks[chunk_idx][char_index]); hex += buffer; - // If we hit the breakPosition, add the break with a " - ". + // Add to the characters string + wchar_t ch = chunks[chunk_idx][char_index]; + if (ch >= L' ' && ch <= L'~') // Check if the character is a printable ASCII character + { + characters += ch; + } + else + { + characters += L'.'; // Add a period for non-printable characters + } + + // If we hit the breakPosition, add the break if (char_index == breakPosition - 1) { - hex += L" - "; + hex += L"- "; // Note, no space before the dash + characters += L" - "; // Add the same break to the characters string } } @@ -44,22 +58,23 @@ std::wstring HexView(std::wstring source, size_t size) int thisChunkSize = chunks[chunk_idx].size(); if (thisChunkSize < chunkSize) { - for (int i = 0; i < chunkSize - thisChunkSize; i++) + for (int i = thisChunkSize; i < chunkSize; i++) { hex += L"00 "; + characters += L"."; + // If we hit the breakPosition, add the break with a " - ". if (i == breakPosition - 1) { - hex += L" - "; + hex += L"- "; + characters += L" - "; } } } - // Add a \n - hex += L"\n"; - // Add the hex string to the output. - output += hex; + std::wstring this_line = hex + L" " + characters + L"\r\n";; + output += this_line; }