add default codepage option

This commit is contained in:
Akash Mozumdar 2018-11-01 21:59:13 -04:00
parent 71f7e9bf29
commit a99131fa23
7 changed files with 11 additions and 10 deletions

View File

@ -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:
@ -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)

View File

@ -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);

View File

@ -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();
}

View File

@ -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();
@ -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();

View File

@ -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);
@ -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);

View File

@ -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\

View File

@ -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();
@ -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))