Skip to content

Commit

Permalink
support hex dump codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Artikash committed Jan 19, 2020
1 parent a820289 commit 0f7a648
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
3 changes: 2 additions & 1 deletion GUI/host/textthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ void TextThread::Push(BYTE* data, int length)
if (leadByte) std::tie(doubleByteChar[0], doubleByteChar[1], data, length, leadByte) = std::tuple(leadByte, data[0], doubleByteChar, 2, 0);
else if (IsDBCSLeadByteEx(hp.codepage ? hp.codepage : Host::defaultCodepage, data[0])) std::tie(leadByte, length) = std::tuple(data[0], 0);

if (hp.type & USING_UNICODE) buffer.append((wchar_t*)data, length / sizeof(wchar_t));
if (hp.type & HEX_DUMP) for (int i = 0; i < length; i += sizeof(short)) buffer.append(FormatString(L"%04hX ", *(short*)(data + i)));
else if (hp.type & USING_UNICODE) buffer.append((wchar_t*)data, length / sizeof(wchar_t));
else if (auto converted = Util::StringToWideString(std::string((char*)data, length), hp.codepage ? hp.codepage : Host::defaultCodepage)) buffer.append(converted.value());
else Host::AddConsoleOutput(INVALID_CODEPAGE);
if (hp.type & FULL_STRING) buffer.push_back(L'\n');
Expand Down
42 changes: 30 additions & 12 deletions GUI/host/util.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "util.h"
#include <sstream>
#include <Psapi.h>

namespace
Expand All @@ -10,7 +9,7 @@ namespace
HookParam hp = {};
hp.type |= DIRECT_READ;

// {S|Q|V}
// {S|Q|V|M}
switch (RCode[0])
{
case L'S':
Expand All @@ -21,6 +20,9 @@ namespace
case L'V':
hp.type |= USING_UTF8;
break;
case L'M':
hp.type |= USING_UNICODE | HEX_DUMP;
break;
default:
return {};
}
Expand Down Expand Up @@ -51,29 +53,36 @@ namespace
std::wsmatch match;
HookParam hp = {};

// {A|B|W|S|Q|V}
// {A|B|W|H|S|Q|V|M}
switch (HCode[0])
{
case L'S':
hp.type |= USING_STRING;
break;
case L'A':
hp.type |= BIG_ENDIAN;
hp.length_offset = 1;
break;
case L'B':
hp.length_offset = 1;
break;
case L'Q':
hp.type |= USING_STRING | USING_UNICODE;
break;
case L'W':
hp.type |= USING_UNICODE;
hp.length_offset = 1;
break;
case L'H':
hp.type |= USING_UNICODE | HEX_DUMP;
hp.length_offset = 1;
break;
case L'S':
hp.type |= USING_STRING;
break;
case L'Q':
hp.type |= USING_STRING | USING_UNICODE;
break;
case L'V':
hp.type |= USING_STRING | USING_UTF8;
break;
case L'M':
hp.type |= USING_STRING | USING_UNICODE | HEX_DUMP;
break;
default:
return {};
}
Expand Down Expand Up @@ -178,7 +187,8 @@ namespace

if (hp.type & USING_UNICODE)
{
RCode += L'Q';
if (hp.type & HEX_DUMP) RCode += L'M';
else RCode += L'Q';
if (hp.null_length != 0) RCode += std::to_wstring(hp.null_length) + L'<';
}
else
Expand All @@ -199,8 +209,16 @@ namespace

if (hp.type & USING_UNICODE)
{
if (hp.type & USING_STRING) HCode += L'Q';
else HCode += L'W';
if (hp.type & HEX_DUMP)
{
if (hp.type & USING_STRING) HCode += L'M';
else HCode += L'H';
}
else
{
if (hp.type & USING_STRING) HCode += L'Q';
else HCode += L'W';
}
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions include/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum HookParamType : unsigned
DIRECT_READ = 0x1000, // /R read code instead of classic /H hook code
FULL_STRING = 0x2000,
BLOCK_FLOOD = 0x4000, // remove this hook if flooding text causing perf issues
HOOK_ENGINE = 0x8000,
HOOK_ADDITIONAL = 0x10000,
HEX_DUMP = 0x8000,
HOOK_ENGINE = 0x10000,
HOOK_ADDITIONAL = 0x20000,
};
7 changes: 4 additions & 3 deletions text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ const char* SELECT_PROCESS_INFO = u8"If you manually type in the process file na
const char* FROM_COMPUTER = u8"Select from computer";
const char* PROCESSES = u8"Processes (*.exe)";
const char* CODE_INFODUMP = u8R"(Enter read code
R{S|Q|V}[null_length<][codepage#]@addr
R{S|Q|V|M}[null_length<][codepage#]@addr
OR
Enter hook code
H{A|B|W|S|Q|V}[F][null_length<][N][codepage#][padding+]data_offset[*deref_offset][:split_offset[*deref_offset]]@addr[:module[:func]]
H{A|B|W|H|S|Q|V|M}[F][null_length<][N][codepage#][padding+]data_offset[*deref_offset][:split_offset[*deref_offset]]@addr[:module[:func]]
All numbers except codepage/null_length in hexadecimal
Default codepage is 932 (Shift-JIS) but this can be changed in settings
A/B: codepage char little/big endian
W: UTF-16 char
S/Q/V: codepage/UTF-16/UTF-8 string
H: Two hex bytes
S/Q/V/M: codepage/UTF-16/UTF-8/hex string
F: treat strings as full lines of text
N: don't use context
null_length: length of null terminator used for string
Expand Down

0 comments on commit 0f7a648

Please sign in to comment.