improved Cotopha4 engine and used the same text filter for Cotopha2

This commit is contained in:
Blu3train 2024-03-11 17:50:35 +01:00
parent e18e3f6d4d
commit 954d4ed072

View File

@ -6355,6 +6355,41 @@ static bool InsertYuris2Hook()
bool InsertYurisHook() bool InsertYurisHook()
{ return InsertYuris1Hook() || InsertYuris2Hook(); } { return InsertYuris1Hook() || InsertYuris2Hook(); }
bool CotophaFilter(LPVOID data, DWORD *size, HookParam *, BYTE)
{
auto text = reinterpret_cast<LPWSTR>(data);
auto len = reinterpret_cast<size_t *>(size);
if (*len<=2 || text[0] != L'\\')
return false;
size_t lenPurged = 0;
for (size_t i = 0; i < *len/2; i++) {
if (text[i] != L'\\') {
text[lenPurged++] = text[i];
} else {
// start command
wchar_t cmd=text[++i];
if (cmd == 'r') { // ruby
i++; // skip ';' char
while (text[++i] != L':') {
if (text[i] == L';') // when we reach '; ' we have the kanji part
break;
text[lenPurged++] = text[i];
}
}
else if (cmd == L'n' && lenPurged) // newline
text[lenPurged++] = L' '; // for Western language compatibility
while (text[++i] != L':')
;
}
}
if (lenPurged)
text[lenPurged++] = L' '; // for Western language compatibility
*len = lenPurged * 2;
return true;
}
bool InsertCotophaHook1() bool InsertCotophaHook1()
{ {
enum : DWORD { ins = 0xec8b55 }; // mov ebp,esp, sub esp,* ; jichi 7/12/2014 enum : DWORD { ins = 0xec8b55 }; // mov ebp,esp, sub esp,* ; jichi 7/12/2014
@ -6382,10 +6417,7 @@ bool InsertCotophaHook2()
hp.address = (uintptr_t)addr; hp.address = (uintptr_t)addr;
hp.offset = 8; hp.offset = 8;
hp.type = USING_UNICODE | USING_STRING; hp.type = USING_UNICODE | USING_STRING;
hp.filter_fun = [](void* data, DWORD* len, HookParam*, BYTE) hp.filter_fun = CotophaFilter;
{
return std::wstring_view((wchar_t*)data, *len / sizeof(wchar_t)).find(L'\\') != std::wstring_view::npos;
};
ConsoleOutput("Textractor: INSERT Cotopha 2"); ConsoleOutput("Textractor: INSERT Cotopha 2");
NewHook(hp, "Cotopha2"); NewHook(hp, "Cotopha2");
return true; return true;
@ -6409,14 +6441,12 @@ bool InsertCotophaHook4()
0x56, // push esi 0x56, // push esi
0x57, // push edi 0x57, // push edi
0x8B, 0x7D, 0x08, // mov edi,[ebp+08] 0x8B, 0x7D, 0x08, // mov edi,[ebp+08]
0x33, 0xF6, // xor esi,esi 0x33, 0xF6 // xor esi,esi
0x8B, 0xD9, // mov ebx,ecx
0x85, 0xFF, // test edi,edi
0x74, 0x0D // je ststeady2.glsGetEnabledProcessorType+643F
}; };
ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR); if (ULONG procAddr = (ULONG)GetProcAddress(GetModuleHandleW(NULL), "glsGetEnabledProcessorType")) {
ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range); ULONG range = min(processStopAddress - procAddr, MAX_REL_ADDR);
ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), procAddr, procAddr + range);
if (!addr) { if (!addr) {
ConsoleOutput("vnreng:Cotopha4: pattern not found"); ConsoleOutput("vnreng:Cotopha4: pattern not found");
return false; return false;
@ -6427,39 +6457,12 @@ bool InsertCotophaHook4()
hp.offset = 4 * 1; // arg1 hp.offset = 4 * 1; // arg1
hp.index = 0; hp.index = 0;
hp.type = USING_UNICODE | USING_STRING | NO_CONTEXT; hp.type = USING_UNICODE | USING_STRING | NO_CONTEXT;
hp.filter_fun = [](LPVOID data, DWORD *size, HookParam *, BYTE) hp.filter_fun = CotophaFilter;
{
auto text = reinterpret_cast<LPWSTR>(data);
auto len = reinterpret_cast<size_t *>(size);
if (text[0] != L'\\')
return false;
size_t lenPurged = 0;
for (size_t i = 0; i < *len/2; i++) {
if (text[i] != L'\\')
text[lenPurged++] = text[i];
else {
// start command
wchar_t cmd=text[++i];
if (cmd == 'r') { // ruby
i++; // skip ';' char
while (text[++i] != L':') {
if (text[i] == L';') // when we reach '; ' we have the kanji part
break;
text[lenPurged++] = text[i];
}
}
while (text[++i] != L':')
;
}
}
*len = lenPurged * 2;
return true;
};
ConsoleOutput("vnreng: INSERT Cotopha4"); ConsoleOutput("vnreng: INSERT Cotopha4");
NewHook(hp, "Cotopha4"); NewHook(hp, "Cotopha4");
return true; return true;
}
return false;
} }
bool InsertCotophaHook() bool InsertCotophaHook()