Skip to content

Commit

Permalink
add default codepage option
Browse files Browse the repository at this point in the history
  • Loading branch information
Artikash committed Nov 2, 2018
1 parent 71f7e9b commit a99131f
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions GUI/host/host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace
case HOST_NOTIFICATION_TEXT:
{
auto info = *(ConsoleOutputNotif*)buffer;
Host::AddConsoleOutput(StringToWideString(info.message, CP_UTF8));
Host::AddConsoleOutput(StringToWideString(info.message));
}
break;
default:
Expand Down Expand Up @@ -273,7 +273,7 @@ namespace Host
std::wstring GetHookName(DWORD processId, uint64_t addr)
{
LOCK(hostMutex);
return StringToWideString(processRecordsByIds.at(processId)->GetHook(addr).hookName, CP_UTF8);
return StringToWideString(processRecordsByIds.at(processId)->GetHook(addr).hookName);
}

std::shared_ptr<TextThread> GetThread(ThreadParam tp)
Expand Down
3 changes: 2 additions & 1 deletion GUI/host/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace Host
void AddConsoleOutput(std::wstring text);
}

inline std::wstring StringToWideString(const std::string& text, UINT encoding)
inline UINT DEFAULT_CODEPAGE = SHIFT_JIS;
inline std::wstring StringToWideString(const std::string& text, UINT encoding = DEFAULT_CODEPAGE)
{
std::wstring ret(text.size() + 1, 0);
ret.resize(MultiByteToWideChar(encoding, 0, text.c_str(), -1, ret.data(), ret.capacity()) - 1);
Expand Down
2 changes: 1 addition & 1 deletion GUI/host/textthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void TextThread::AddText(const BYTE* data, int len)
LOCK(threadMutex);
buffer += hp.type & USING_UNICODE
? std::wstring((wchar_t*)data, len / 2)
: StringToWideString(std::string((char*)data, len), hp.codepage);
: StringToWideString(std::string((char*)data, len), hp.codepage != 0 ? hp.codepage : DEFAULT_CODEPAGE);
if (std::all_of(buffer.begin(), buffer.end(), [&](wchar_t c) { return repeatingChars.count(c) > 0; })) buffer.clear();
timestamp = GetTickCount();
}
Expand Down
2 changes: 2 additions & 0 deletions GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MainWindow::MainWindow(QWidget *parent) :

if (settings.contains("Window")) this->setGeometry(settings.value("Window").toRect());
// TODO: add GUI for changing these
if (settings.contains("Default_Codepage")) DEFAULT_CODEPAGE = settings.value("Default_Codepage").toInt();
if (settings.contains("Flush_Delay")) TextThread::flushDelay = settings.value("Flush_Delay").toInt();
if (settings.contains("Max_Buffer_Size")) TextThread::maxBufferSize = settings.value("Max_Buffer_Size").toInt();

Expand All @@ -42,6 +43,7 @@ MainWindow::MainWindow(QWidget *parent) :
MainWindow::~MainWindow()
{
settings.setValue("Window", this->geometry());
settings.setValue("Default_Codepage", DEFAULT_CODEPAGE);
settings.setValue("Flush_Delay", TextThread::flushDelay);
settings.setValue("Max_Buffer_Size", TextThread::maxBufferSize);
settings.sync();
Expand Down
4 changes: 2 additions & 2 deletions GUI/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace
else if (hp.type & USING_UTF8) codeBuilder << "V";
else codeBuilder << "S";

if (hp.codepage != SHIFT_JIS && hp.codepage != CP_UTF8) codeBuilder << hp.codepage << "#";
if (hp.codepage != 0 && hp.codepage != CP_UTF8) codeBuilder << hp.codepage << "#";

codeBuilder.setIntegerBase(16);
codeBuilder.setNumberFlags(QTextStream::UppercaseDigits);
Expand Down Expand Up @@ -220,7 +220,7 @@ namespace
}
if (hp.type & NO_CONTEXT) codeBuilder << "N";

if (hp.codepage != SHIFT_JIS && hp.codepage != CP_UTF8) codeBuilder << hp.codepage << "#";
if (hp.codepage != 0 && hp.codepage != CP_UTF8) codeBuilder << hp.codepage << "#";

codeBuilder.setIntegerBase(16);
codeBuilder.setNumberFlags(QTextStream::UppercaseDigits);
Expand Down
2 changes: 1 addition & 1 deletion GUI/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static QString CodeInfoDump =
/H{A|B|W|S|Q|V}[N][codepage#]data_offset[*deref_offset1][:split_offset[*deref_offset2]]@addr[:module[:func]]\r\n\
OR\r\n\
Enter read code\r\n\
/R{S|Q|V}[#codepage][*deref_offset|0]@addr\r\n\
/R{S|Q|V}[codepage#][*deref_offset|0]@addr\r\n\
All numbers except codepage in hexadecimal\r\n\
A/B: Shift-JIS char little/big endian\r\n\
W: UTF-16 char\r\n\
Expand Down
4 changes: 1 addition & 3 deletions vnrhook/hijack/texthook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ bool TextHook::InsertHook()
{
//ConsoleOutput("vnrcli:InsertHook: enter");
LOCK(*sectionMutex);
if (hp.type & USING_UTF8) hp.codepage = CP_UTF8;
if (hp.type & DIRECT_READ) return InsertReadCode();
#ifndef _WIN64
else return InsertHookCode();
Expand Down Expand Up @@ -229,9 +230,6 @@ bool TextHook::InsertHookCode()
else if (HMODULE moduleBase = GetModuleHandleW(hp.module)) hp.insertion_address += (uint64_t)moduleBase;
else return ConsoleOutput("Textractor: UnsafeInsertHookCode: FAILED: module not present"), false;

if (hp.type & USING_UTF8) hp.codepage = CP_UTF8;
if (hp.codepage == 0) hp.codepage = SHIFT_JIS; // Use Shift-JIS unless custom encoding was specified

BYTE* original;
insert:
if (MH_STATUS err = MH_CreateHook((void*)hp.insertion_address, (void*)trampoline, (void**)&original))
Expand Down

0 comments on commit a99131f

Please sign in to comment.