mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-11-24 22:35:36 +08:00
44 lines
1.6 KiB
C++
44 lines
1.6 KiB
C++
|
#include"PPSSPP.h"
|
||
|
|
||
|
/** Artikash 6/7/2019
|
||
|
* PPSSPP JIT code has pointers, but they are all added to an offset before being used.
|
||
|
Find that offset so that hook searching works 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 PPSSPP::attach_function()
|
||
|
{
|
||
|
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("PPSSPP memory found: searching for hooks should yield working hook codes");
|
||
|
// PPSSPP 1.8.0 compiles jal to sub dword ptr [r14+0x360],??
|
||
|
memcpy(spDefault.pattern, Array<BYTE>{ 0x41, 0x83, 0xae, 0x60, 0x03, 0x00, 0x00 }, spDefault.length = 7);
|
||
|
spDefault.offset = 0;
|
||
|
spDefault.minAddress = 0;
|
||
|
spDefault.maxAddress = -1ULL;
|
||
|
spDefault.padding = (uintptr_t)probe - 0x8000000;
|
||
|
spDefault.hookPostProcessor = [](HookParam& hp)
|
||
|
{
|
||
|
hp.type |= NO_CONTEXT | USING_SPLIT | SPLIT_INDIRECT;
|
||
|
hp.split = get_reg(regs::r14);
|
||
|
hp.split_index = -8; // this is where PPSSPP 1.8.0 stores its return address stack
|
||
|
};
|
||
|
}
|
||
|
probe += info.RegionSize;
|
||
|
}
|
||
|
}
|
||
|
return found;
|
||
|
}
|