diff --git a/LunaHook/engine64/yuzusuyu.cpp b/LunaHook/engine64/yuzusuyu.cpp index 735ab08..adbf3fb 100644 --- a/LunaHook/engine64/yuzusuyu.cpp +++ b/LunaHook/engine64/yuzusuyu.cpp @@ -171,23 +171,31 @@ bool yuzusuyu::attach_function() auto descriptor = *argidx(stack,idxDescriptor); // r8 auto entrypoint = *argidx(stack,idxEntrypoint); // r9 auto em_address = *(uintptr_t*)descriptor; + if(!entrypoint)return; jitaddraddr(em_address,entrypoint,JITTYPE::YUZU); - auto em_address_off=em_address- 0x80004000; - if(emfunctionhooks.find(em_address_off)==emfunctionhooks.end() || !entrypoint)return; - auto op=emfunctionhooks.at(em_address_off); - if(!(checkiscurrentgame(op)))return; - - HookParam hpinternal; - hpinternal.address=entrypoint; - hpinternal.emu_addr=em_address;//用于生成hcode - hpinternal.type=USING_STRING|NO_CONTEXT|BREAK_POINT|op.type; - hpinternal.text_fun=(decltype(hpinternal.text_fun))op.hookfunc; - hpinternal.filter_fun=(decltype(hpinternal.filter_fun))op.filterfun; - hpinternal.argidx=op.argidx; - hpinternal.padding=op.padding; - hpinternal.jittype=JITTYPE::YUZU; - NewHook(hpinternal,op.hookname); - + [&](){ + auto em_address_off=em_address- 0x80004000; + if(emfunctionhooks.find(em_address_off)==emfunctionhooks.end())return; + auto op=emfunctionhooks.at(em_address_off); + if(!(checkiscurrentgame(op)))return; + + HookParam hpinternal; + hpinternal.address=entrypoint; + hpinternal.emu_addr=em_address;//用于生成hcode + hpinternal.type=USING_STRING|NO_CONTEXT|BREAK_POINT|op.type; + hpinternal.text_fun=(decltype(hpinternal.text_fun))op.hookfunc; + hpinternal.filter_fun=(decltype(hpinternal.filter_fun))op.filterfun; + hpinternal.argidx=op.argidx; + hpinternal.padding=op.padding; + hpinternal.jittype=JITTYPE::YUZU; + NewHook(hpinternal,op.hookname); + }(); + [&](){ + if(delayinserthook.find(em_address)==delayinserthook.end())return; + auto h=delayinserthook[em_address]; + delayinserthook.erase(em_address); + NewHook(h.second,h.first.c_str()); + }(); }; return NewHook(hp,"YuzuDoJit"); } diff --git a/LunaHook/engines/ppsspp/ppsspp.cpp b/LunaHook/engines/ppsspp/ppsspp.cpp index ce911cf..18d164d 100644 --- a/LunaHook/engines/ppsspp/ppsspp.cpp +++ b/LunaHook/engines/ppsspp/ppsspp.cpp @@ -293,46 +293,52 @@ bool hookPPSSPPDoJit(){ hpinternal.user_value=hp->user_value; hpinternal.address=stack->retaddr; hpinternal.text_fun=[](hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len){ - - auto ret=stack->RETADDR; - if(breakpoints.find(ret)!=breakpoints.end())return; - breakpoints.insert(ret); - auto em_address=*(uintptr_t*)(hp->user_value); + [&](){ + auto ret=stack->RETADDR; + if(breakpoints.find(ret)!=breakpoints.end())return; + breakpoints.insert(ret); - jitaddraddr(em_address,ret,JITTYPE::PPSSPP); + jitaddraddr(em_address,ret,JITTYPE::PPSSPP); - if(emfunctionhooks.find(em_address)==emfunctionhooks.end())return; - if(!(checkiscurrentgame(emfunctionhooks.at(em_address))))return; - - auto op=emfunctionhooks.at(em_address); - ConsoleOutput("jit function addr %p",ret); - #ifndef _WIN64 - BYTE sig[]={ - 0x8b,XX2,//mov reg,[ebp-off] - 0x8b,0xc6,//mov eax,esi - 0x25,0xff,0xff,0xff,0x3f,//and eax,0x3fffffff - 0x89,XX,XX4,//mov [eax+base+off],reg + if(emfunctionhooks.find(em_address)==emfunctionhooks.end())return; + if(!(checkiscurrentgame(emfunctionhooks.at(em_address))))return; + + auto op=emfunctionhooks.at(em_address); + ConsoleOutput("jit function addr %p",ret); + #ifndef _WIN64 + BYTE sig[]={ + 0x8b,XX2,//mov reg,[ebp-off] + 0x8b,0xc6,//mov eax,esi + 0x25,0xff,0xff,0xff,0x3f,//and eax,0x3fffffff + 0x89,XX,XX4,//mov [eax+base+off],reg - }; - auto findbase=MemDbg::findBytes(sig,sizeof(sig),ret,ret+0x20); - if(!findbase) - findbase=MemDbg::findBytes(sig,sizeof(sig),ret-0x1000,ret+0x1000); - if(!findbase) - ConsoleOutput("can't find emu_baseaddr"); - PPSSPP::x86_baseaddr=(*(DWORD*)(findbase+12))&0xffff0000; - ConsoleOutput("x86 base addr %p",PPSSPP::x86_baseaddr); - #endif - HookParam hpinternal; - hpinternal.address=ret; - hpinternal.emu_addr=em_address;//用于生成hcode - hpinternal.type=USING_STRING|NO_CONTEXT|BREAK_POINT|op.type; - hpinternal.text_fun=(decltype(hpinternal.text_fun))op.hookfunc; - hpinternal.filter_fun=(decltype(hpinternal.filter_fun))op.filterfun; - hpinternal.argidx=op.argidx; - hpinternal.padding=op.padding; - hpinternal.jittype=JITTYPE::PPSSPP; - NewHook(hpinternal,op.hookname); + }; + auto findbase=MemDbg::findBytes(sig,sizeof(sig),ret,ret+0x20); + if(!findbase) + findbase=MemDbg::findBytes(sig,sizeof(sig),ret-0x1000,ret+0x1000); + if(!findbase) + ConsoleOutput("can't find emu_baseaddr"); + PPSSPP::x86_baseaddr=(*(DWORD*)(findbase+12))&0xffff0000; + ConsoleOutput("x86 base addr %p",PPSSPP::x86_baseaddr); + #endif + HookParam hpinternal; + hpinternal.address=ret; + hpinternal.emu_addr=em_address;//用于生成hcode + hpinternal.type=USING_STRING|NO_CONTEXT|BREAK_POINT|op.type; + hpinternal.text_fun=(decltype(hpinternal.text_fun))op.hookfunc; + hpinternal.filter_fun=(decltype(hpinternal.filter_fun))op.filterfun; + hpinternal.argidx=op.argidx; + hpinternal.padding=op.padding; + hpinternal.jittype=JITTYPE::PPSSPP; + NewHook(hpinternal,op.hookname); + }(); + [&](){ + if(delayinserthook.find(em_address)==delayinserthook.end())return; + auto h=delayinserthook[em_address]; + delayinserthook.erase(em_address); + NewHook(h.second,h.first.c_str()); + }(); }; static auto once=NewHook(hpinternal,"DoJitPtrRet"); }; diff --git a/LunaHook/main.cc b/LunaHook/main.cc index bd45682..91b9ea5 100644 --- a/LunaHook/main.cc +++ b/LunaHook/main.cc @@ -207,7 +207,11 @@ bool NewHook_1(HookParam& hp, LPCSTR lpname) bool NewHook(HookParam hp, LPCSTR name){ if(hp.address) return NewHook_1(hp,name); - if(emuaddr2jitaddr.find(hp.emu_addr)==emuaddr2jitaddr.end())return false; + //下面的是手动插入 + if(emuaddr2jitaddr.find(hp.emu_addr)==emuaddr2jitaddr.end()){ + delayinserthook[hp.emu_addr]={name,hp}; + return false; + } strcpy(hp.function,""); wcscpy(hp.module,L""); hp.type &= ~MODULE_OFFSET; diff --git a/LunaHook/main.h b/LunaHook/main.h index d3db9ad..1efd1e5 100644 --- a/LunaHook/main.h +++ b/LunaHook/main.h @@ -25,3 +25,5 @@ void jitaddraddr(uintptr_t em_addr,uintptr_t jitaddr,JITTYPE); void context_get(hook_stack*,PCONTEXT); void context_set(hook_stack*,PCONTEXT); + +inline std::map>delayinserthook; \ No newline at end of file diff --git a/LunaHook/veh_hook.cpp b/LunaHook/veh_hook.cpp index 6dd6a09..ea6172b 100644 --- a/LunaHook/veh_hook.cpp +++ b/LunaHook/veh_hook.cpp @@ -38,7 +38,8 @@ bool add_veh_hook(void* origFunc, newFuncType newFunc, DWORD hook_type) } void repair_origin(veh_node_t *node){ DWORD _p; - VirtualProtect(node->origFunc, sizeof(int), PAGE_EXECUTE_READWRITE, &_p); + if(!VirtualProtect(node->origFunc, sizeof(int), PAGE_EXECUTE_READWRITE, &_p)) + return; memcpy((void*)node->origFunc, (const void*)(&node->origBaseByte), sizeof(char)); VirtualProtect(node->origFunc, sizeof(int), node->OldProtect, &_p); }