Skip to content

Commit

Permalink
Debugging Hex viewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasecoulls committed Oct 5, 2023
1 parent fb73623 commit 6e8bfdc
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions LogBazooka/HexDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,56 @@ 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
}
}

// Pad with 00's if the chunk is not full.
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;

}

Expand Down

0 comments on commit 6e8bfdc

Please sign in to comment.