This commit is contained in:
恍兮惚兮 2024-05-23 18:41:39 +08:00
parent 16852394ff
commit a4256dd67a
3 changed files with 138 additions and 37 deletions

View File

@ -63,6 +63,49 @@ struct PPSSPPFunction
const char *pattern; // debug string used within the function const char *pattern; // debug string used within the function
}; };
namespace{
uintptr_t findleapushaddr(uintptr_t addr)
{
#ifndef _WIN64
addr=MemDbg::findPushAddress(addr, processStartAddress, processStopAddress);
if(!addr)return NULL;
addr=SafeFindEnclosingAlignedFunction(addr, 0x200);
#else
addr=MemDbg::findleaaddr(addr, processStartAddress, processStopAddress);
if(!addr)return NULL;
BYTE sig1[]={
0xCC,
0x48,0x89,XX,0x24,XX,
};
BYTE sig2[]={
0xC3,
0x48,0x89,XX,0x24,XX,
};
BYTE sig3[]={
0xCC,
0x89,XX,0x24,XX,
};
BYTE sig4[]={
0xC3,
0x89,XX,0x24,XX,
};
int idx=0;
uintptr_t maxaddr=0;
for(auto sig:{sig1,sig2,sig3,sig4})
{
idx+=1;
maxaddr=max(maxaddr,reverseFindBytes(sig,(idx>2)?5:6,addr-0x500,addr,1,true));
}
maxaddr=max(maxaddr,MemDbg::findEnclosingAlignedFunction_strict(addr,0x500));
addr=maxaddr;
#endif
return addr;
}
}
bool InsertPPSSPPHLEHooks() bool InsertPPSSPPHLEHooks()
{ {
@ -105,43 +148,7 @@ bool InsertPPSSPPHLEHooks()
for (auto&& function :functions) { for (auto&& function :functions) {
auto addr = MemDbg::findBytes(function.pattern, ::strlen(function.pattern), processStartAddress, processStopAddress); auto addr = MemDbg::findBytes(function.pattern, ::strlen(function.pattern), processStartAddress, processStopAddress);
if(!addr)continue; if(!addr)continue;
#ifndef _WIN64 addr=findleapushaddr(addr);
addr=MemDbg::findPushAddress(addr, processStartAddress, processStopAddress);
if(!addr)continue;
addr=SafeFindEnclosingAlignedFunction(addr, 0x200);
#else
addr=MemDbg::findleaaddr(addr, processStartAddress, processStopAddress);
if(!addr)continue;
BYTE sig1[]={
0xCC,
0x48,0x89,XX,0x24,XX,
};
BYTE sig2[]={
0xC3,
0x48,0x89,XX,0x24,XX,
};
BYTE sig3[]={
0xCC,
0x89,XX,0x24,XX,
};
BYTE sig4[]={
0xC3,
0x89,XX,0x24,XX,
};
int idx=0;
uintptr_t maxaddr=0;
for(auto sig:{sig1,sig2,sig3,sig4})
{
idx+=1;
maxaddr=max(maxaddr,reverseFindBytes(sig,(idx>2)?5:6,addr-0x500,addr,1,true));
}
maxaddr=max(maxaddr,MemDbg::findEnclosingAlignedFunction_strict(addr,0x500));
addr=maxaddr;
#endif
if(!addr)continue; if(!addr)continue;
HookParam hp; HookParam hp;
@ -456,10 +463,83 @@ bool hookPPSSPPDoJit(){
return NewHook(hp,"PPSSPPDoJit"); return NewHook(hp,"PPSSPPDoJit");
} }
} }
namespace{
//ULJS00035 ULJS00149 流行り神
void* findGetPointer(){
char GetPointer[]="Unknown GetPointer %08x PC %08x LR %08x";
auto addr=MemDbg::findBytes(GetPointer,sizeof(GetPointer),processStartAddress,processStopAddress);
if(!addr)return nullptr;
addr=findleapushaddr(addr);
return (void*)addr;
}
bool Replace_memcpy(){
// static int Replace_memcpy() {
// u32 destPtr = PARAM(0);
// u32 srcPtr = PARAM(1);
// u32 bytes = PARAM(2);
static auto GetPointer=(uintptr_t(*)(uintptr_t))findGetPointer();
if(!GetPointer)return false;
ConsoleOutput("GetPointer %p",GetPointer);
char ReplaceMemcpy_VideoDecodeRange[] ="ReplaceMemcpy/VideoDecodeRange";
auto addr=MemDbg::findBytes(ReplaceMemcpy_VideoDecodeRange,sizeof(ReplaceMemcpy_VideoDecodeRange),processStartAddress,processStopAddress);
if(!addr)return false;
ConsoleOutput("ReplaceMemcpy/VideoDecodeRange %p",addr);
#ifndef _WIN64
BYTE sig[]={0xb9,XX4};
*(uintptr_t*)(sig+1)=addr;
bool succ=false;
for(auto addr:Util::SearchMemory(sig,sizeof(sig),PAGE_EXECUTE,processStartAddress,processStopAddress)){
BYTE sig1[]={
0x55,0x8b,0xec,
0x81,0xec,XX4,
0x8b,0x0d,XX4,
};
addr=reverseFindBytes(sig1,sizeof(sig1),addr-0x200,addr);
if(!addr)continue;
DWORD off_106D180=*(DWORD*)(addr+sizeof(sig1)-4);
HookParam hp;
hp.user_value=*(DWORD*)off_106D180;
#else
bool succ=false;
for(auto addr:MemDbg::findleaaddr_all(addr,processStartAddress,processStopAddress)){
BYTE sig1[]={
0x48,0x89,XX,0x24,0x18,
0x48,0x89,XX,0x24,0x20,
0x57,
0x48,0x81,0xec,XX4,
0x48,0x8b,XX,XX4
};
addr=reverseFindBytes(sig1,sizeof(sig1),addr-0x200,addr);
if(!addr)continue;
DWORD off_140F4C810=*(DWORD*)(addr+sizeof(sig1)-4);
HookParam hp;
hp.user_value=*(uintptr_t*)(off_140F4C810+addr+sizeof(sig1));
#endif
hp.address=addr;
hp.text_fun=[](hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len){
auto bytes = *((DWORD *)hp->user_value + 6);
auto srcPtr = GetPointer(*((DWORD *)hp->user_value + 5));
if(!IsDBCSLeadByteEx(932,*(BYTE*)srcPtr))
return;
if(bytes!=2)
return;
if(bytes!=strnlen((char*)srcPtr,TEXT_BUFFER_SIZE))
return;
*data=(uintptr_t)srcPtr;
*len=bytes;
};
succ|=NewHook(hp,"Replace_memcpy");
}
return succ;
}
}
bool InsertPPSSPPcommonhooks() bool InsertPPSSPPcommonhooks()
{ {
auto succ=InsertPPSSPPHLEHooks(); auto succ=InsertPPSSPPHLEHooks();
succ|=ppsspp::hookPPSSPPDoJit(); succ|=ppsspp::hookPPSSPPDoJit();
succ|=Replace_memcpy();
return succ; return succ;
} }

View File

@ -484,6 +484,7 @@ uint64_t findleaaddr(uint64_t addr,uint64_t start,uint64_t end)
{ {
for(auto _addr=start;_addr<end;_addr+=1) for(auto _addr=start;_addr<end;_addr+=1)
{ {
if(IsBadReadPtr((void*)_addr,4))continue;
auto lea=(*(WORD*)_addr); auto lea=(*(WORD*)_addr);
if(lea!=0x8d4c&&lea!=0x8d48) if(lea!=0x8d4c&&lea!=0x8d48)
continue; continue;
@ -496,6 +497,25 @@ uint64_t findleaaddr(uint64_t addr,uint64_t start,uint64_t end)
return 0; return 0;
} }
std::vector<uint64_t> findleaaddr_all(uint64_t addr,uint64_t start,uint64_t end)
{
std::vector<uint64_t> addrs;
for(auto _addr=start;_addr<end;_addr+=1)
{
if(IsBadReadPtr((void*)_addr,4))continue;
auto lea=(*(WORD*)_addr);
if(lea!=0x8d4c&&lea!=0x8d48)
continue;
auto offset=*(DWORD*)(_addr+3);
auto refaddr=(offset)+_addr+7;
if(refaddr==addr)
addrs.push_back(_addr);
}
return addrs;
}
#endif #endif
uintptr_t findCallerAddress(uintptr_t funcAddr, DWORD sig, uintptr_t lowerBound, uintptr_t upperBound, uintptr_t reverseLength,uintptr_t offset) uintptr_t findCallerAddress(uintptr_t funcAddr, DWORD sig, uintptr_t lowerBound, uintptr_t upperBound, uintptr_t reverseLength,uintptr_t offset)

View File

@ -133,6 +133,7 @@ inline dword_t findPushAddress(dword_t value, dword_t lowerBound, dword_t upperB
{ return findPushDwordAddress(value, lowerBound, upperBound); } { return findPushDwordAddress(value, lowerBound, upperBound); }
uint64_t findleaaddr(uint64_t addr,uint64_t start,uint64_t end); uint64_t findleaaddr(uint64_t addr,uint64_t start,uint64_t end);
std::vector<uint64_t> findleaaddr_all(uint64_t addr,uint64_t start,uint64_t end);
/** /**
* Return the enclosing function address outside the given address. * Return the enclosing function address outside the given address.
* The same as ITH FindEntryAligned(). * The same as ITH FindEntryAligned().