diff --git a/texthook/engine/engine.cc b/texthook/engine/engine.cc index 9d5e08d..1e1fc56 100644 --- a/texthook/engine/engine.cc +++ b/texthook/engine/engine.cc @@ -16806,6 +16806,37 @@ bool InsertVanillawareGCHook() return addr; } +/** Artikash 6/7/2019 +* PPSSPP JIT code has pointers, but they are all added to an offset before being used. + Find that offset and report it to user so they can search for hooks properly. + To find the offset, find a page of mapped memory with size 0x1f00000, read and write permissions, take its address and subtract 0x8000000. + The above is useful for emulating PSP hardware, so unlikely to change between versions. +*/ +bool FindPPSSPP() +{ + bool found = false; + SYSTEM_INFO systemInfo; + GetNativeSystemInfo(&systemInfo); + for (BYTE* probe = NULL; probe < systemInfo.lpMaximumApplicationAddress;) + { + MEMORY_BASIC_INFORMATION info; + if (!VirtualQuery(probe, &info, sizeof(info))) + { + probe += systemInfo.dwPageSize; + } + else + { + if (info.RegionSize == 0x1f00000 && info.Protect == PAGE_READWRITE && info.Type == MEM_MAPPED) + { + found = true; + ConsoleOutput("Textractor: PPSSPP memory found: use pattern 79 0F C7 85 and pattern offset 0 and string offset %p to search for hooks", probe - 0x8000000); + } + probe += info.RegionSize; + } + } + return found; +} + /** jichi 7/12/2014 PPSSPP * Tested with PPSSPP 0.9.8. */ diff --git a/texthook/engine/engine.h b/texthook/engine/engine.h index 99e8f9c..7394b07 100644 --- a/texthook/engine/engine.h +++ b/texthook/engine/engine.h @@ -43,6 +43,7 @@ bool InsertTypeMoonPS2Hook(); // http://typemoon.com void SpecialPSPHook(DWORD esp_base, HookParam *hp, DWORD *data, DWORD *split, DWORD *len); // General PSP extern hook +bool FindPPSSPP(); bool InsertPPSSPPHooks(); // PPSSPPWindows bool InsertPPSSPPHLEHooks(); diff --git a/texthook/engine/match.cc b/texthook/engine/match.cc index 4cf7b47..417e243 100644 --- a/texthook/engine/match.cc +++ b/texthook/engine/match.cc @@ -53,6 +53,6 @@ namespace Engine DetermineEngineType(); hijacked = true; - ConsoleOutput("Textractor: finished hijacking %S located from 0x%p to 0x%p", processName, processStartAddress, processStopAddress); + ConsoleOutput("Textractor: finished hijacking process located from 0x%p to 0x%p", processStartAddress, processStopAddress); } } diff --git a/texthook/engine/match32.cc b/texthook/engine/match32.cc index 0c5b465..a0bd47a 100644 --- a/texthook/engine/match32.cc +++ b/texthook/engine/match32.cc @@ -36,10 +36,13 @@ bool DeterminePCEngine() return true; } - if (Util::CheckFile(L"PPSSPP*.exe")) { // jichi 7/12/2014 PPSSPPWindows.exe, PPSSPPEX.exe PPSSPPSP.exe - //InsertPPSSPPHooks(); // Artikash 8/4/2018: removed for now as doesn't work for non ancient ppsspp versions - return true; - } + //if (Util::CheckFile(L"PPSSPP*.exe")) { // jichi 7/12/2014 PPSSPPWindows.exe, PPSSPPEX.exe PPSSPPSP.exe + // //InsertPPSSPPHooks(); // Artikash 8/4/2018: removed for now as doesn't work for non ancient ppsspp versions + // FindPPSSPP(); + // return true; + //} + + if (Util::CheckFile(L"PPSSPP*.exe") && FindPPSSPP()) return true; if (Util::CheckFile(L"pcsx2*.exe")) { // jichi 7/19/2014 PCSX2.exe or PCSX2WX.exe InsertPCSX2Hooks(); diff --git a/texthook/engine/match64.cc b/texthook/engine/match64.cc index 48a326c..bd0258b 100644 --- a/texthook/engine/match64.cc +++ b/texthook/engine/match64.cc @@ -1,9 +1,42 @@ #include "match.h" #include "main.h" #include "native/pchooks.h" +#include "engine.h" +#include "util.h" namespace Engine { + /** Artikash 6/7/2019 +* PPSSPP JIT code has pointers, but they are all added to an offset before being used. + Find that offset and report it to user so they can search for hooks properly. + To find the offset, find a page of mapped memory with size 0x1f00000, read and write permissions, take its address and subtract 0x8000000. + The above is useful for emulating PSP hardware, so unlikely to change between versions. +*/ + bool FindPPSSPP() + { + bool found = false; + SYSTEM_INFO systemInfo; + GetNativeSystemInfo(&systemInfo); + for (BYTE* probe = NULL; probe < systemInfo.lpMaximumApplicationAddress;) + { + MEMORY_BASIC_INFORMATION info; + if (!VirtualQuery(probe, &info, sizeof(info))) + { + probe += systemInfo.dwPageSize; + } + else + { + if (info.RegionSize == 0x1f00000 && info.Protect == PAGE_READWRITE && info.Type == MEM_MAPPED) + { + found = true; + ConsoleOutput("Textractor: PPSSPP memory found: use pattern 79 10 41 C7 and pattern offset 0 and string offset %p to search for hooks", probe - 0x8000000); + } + probe += info.RegionSize; + } + } + return found; + } + bool UnsafeDetermineEngineType() { for (std::wstring DXVersion : { L"d3dx9", L"d3dx10" }) @@ -11,6 +44,8 @@ namespace Engine else for (int i = 0; i < 50; ++i) if (HMODULE module = GetModuleHandleW((DXVersion + L"_" + std::to_wstring(i)).c_str())) PcHooks::hookD3DXFunctions(module); + if (Util::CheckFile(L"PPSSPP*.exe") && FindPPSSPP()) return true; + PcHooks::hookGDIFunctions(); PcHooks::hookGDIPlusFunctions(); return false;