Skip to content

Commit 0f7a648

Browse files
committed
support hex dump codes
1 parent a820289 commit 0f7a648

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

GUI/host/textthread.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ void TextThread::Push(BYTE* data, int length)
4646
if (leadByte) std::tie(doubleByteChar[0], doubleByteChar[1], data, length, leadByte) = std::tuple(leadByte, data[0], doubleByteChar, 2, 0);
4747
else if (IsDBCSLeadByteEx(hp.codepage ? hp.codepage : Host::defaultCodepage, data[0])) std::tie(leadByte, length) = std::tuple(data[0], 0);
4848

49-
if (hp.type & USING_UNICODE) buffer.append((wchar_t*)data, length / sizeof(wchar_t));
49+
if (hp.type & HEX_DUMP) for (int i = 0; i < length; i += sizeof(short)) buffer.append(FormatString(L"%04hX ", *(short*)(data + i)));
50+
else if (hp.type & USING_UNICODE) buffer.append((wchar_t*)data, length / sizeof(wchar_t));
5051
else if (auto converted = Util::StringToWideString(std::string((char*)data, length), hp.codepage ? hp.codepage : Host::defaultCodepage)) buffer.append(converted.value());
5152
else Host::AddConsoleOutput(INVALID_CODEPAGE);
5253
if (hp.type & FULL_STRING) buffer.push_back(L'\n');

GUI/host/util.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "util.h"
2-
#include <sstream>
32
#include <Psapi.h>
43

54
namespace
@@ -10,7 +9,7 @@ namespace
109
HookParam hp = {};
1110
hp.type |= DIRECT_READ;
1211

13-
// {S|Q|V}
12+
// {S|Q|V|M}
1413
switch (RCode[0])
1514
{
1615
case L'S':
@@ -21,6 +20,9 @@ namespace
2120
case L'V':
2221
hp.type |= USING_UTF8;
2322
break;
23+
case L'M':
24+
hp.type |= USING_UNICODE | HEX_DUMP;
25+
break;
2426
default:
2527
return {};
2628
}
@@ -51,29 +53,36 @@ namespace
5153
std::wsmatch match;
5254
HookParam hp = {};
5355

54-
// {A|B|W|S|Q|V}
56+
// {A|B|W|H|S|Q|V|M}
5557
switch (HCode[0])
5658
{
57-
case L'S':
58-
hp.type |= USING_STRING;
59-
break;
6059
case L'A':
6160
hp.type |= BIG_ENDIAN;
6261
hp.length_offset = 1;
6362
break;
6463
case L'B':
6564
hp.length_offset = 1;
6665
break;
67-
case L'Q':
68-
hp.type |= USING_STRING | USING_UNICODE;
69-
break;
7066
case L'W':
7167
hp.type |= USING_UNICODE;
7268
hp.length_offset = 1;
7369
break;
70+
case L'H':
71+
hp.type |= USING_UNICODE | HEX_DUMP;
72+
hp.length_offset = 1;
73+
break;
74+
case L'S':
75+
hp.type |= USING_STRING;
76+
break;
77+
case L'Q':
78+
hp.type |= USING_STRING | USING_UNICODE;
79+
break;
7480
case L'V':
7581
hp.type |= USING_STRING | USING_UTF8;
7682
break;
83+
case L'M':
84+
hp.type |= USING_STRING | USING_UNICODE | HEX_DUMP;
85+
break;
7786
default:
7887
return {};
7988
}
@@ -178,7 +187,8 @@ namespace
178187

179188
if (hp.type & USING_UNICODE)
180189
{
181-
RCode += L'Q';
190+
if (hp.type & HEX_DUMP) RCode += L'M';
191+
else RCode += L'Q';
182192
if (hp.null_length != 0) RCode += std::to_wstring(hp.null_length) + L'<';
183193
}
184194
else
@@ -199,8 +209,16 @@ namespace
199209

200210
if (hp.type & USING_UNICODE)
201211
{
202-
if (hp.type & USING_STRING) HCode += L'Q';
203-
else HCode += L'W';
212+
if (hp.type & HEX_DUMP)
213+
{
214+
if (hp.type & USING_STRING) HCode += L'M';
215+
else HCode += L'H';
216+
}
217+
else
218+
{
219+
if (hp.type & USING_STRING) HCode += L'Q';
220+
else HCode += L'W';
221+
}
204222
}
205223
else
206224
{

include/const.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum HookParamType : unsigned
2828
DIRECT_READ = 0x1000, // /R read code instead of classic /H hook code
2929
FULL_STRING = 0x2000,
3030
BLOCK_FLOOD = 0x4000, // remove this hook if flooding text causing perf issues
31-
HOOK_ENGINE = 0x8000,
32-
HOOK_ADDITIONAL = 0x10000,
31+
HEX_DUMP = 0x8000,
32+
HOOK_ENGINE = 0x10000,
33+
HOOK_ADDITIONAL = 0x20000,
3334
};

text.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ const char* SELECT_PROCESS_INFO = u8"If you manually type in the process file na
2121
const char* FROM_COMPUTER = u8"Select from computer";
2222
const char* PROCESSES = u8"Processes (*.exe)";
2323
const char* CODE_INFODUMP = u8R"(Enter read code
24-
R{S|Q|V}[null_length<][codepage#]@addr
24+
R{S|Q|V|M}[null_length<][codepage#]@addr
2525
OR
2626
Enter hook code
27-
H{A|B|W|S|Q|V}[F][null_length<][N][codepage#][padding+]data_offset[*deref_offset][:split_offset[*deref_offset]]@addr[:module[:func]]
27+
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]]
2828
All numbers except codepage/null_length in hexadecimal
2929
Default codepage is 932 (Shift-JIS) but this can be changed in settings
3030
A/B: codepage char little/big endian
3131
W: UTF-16 char
32-
S/Q/V: codepage/UTF-16/UTF-8 string
32+
H: Two hex bytes
33+
S/Q/V/M: codepage/UTF-16/UTF-8/hex string
3334
F: treat strings as full lines of text
3435
N: don't use context
3536
null_length: length of null terminator used for string

0 commit comments

Comments
 (0)