diff --git a/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp b/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp index 72c0180b..5c75f1fd 100644 --- a/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp +++ b/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp @@ -488,16 +488,6 @@ namespace ppsspp } return true; } - void LoadNativeHooks(const std::string &GameID) - { - for (auto &&[id, ptr] : nativehooks) - { - if (id == GameID) - { - ptr(); - } - } - } void Load_PSP_ISO_StringFromFormat() { /* @@ -538,7 +528,6 @@ namespace ppsspp game_info.TITLE = (char *)stack->ARG4; HostInfo(HOSTINFO::EmuGameName, "%s %s", stack->ARG3, stack->ARG4); jitaddrclear(); - LoadNativeHooks(game_info.DISC_ID); }; NewHook(hp, "PPSSPPGameInfo"); } @@ -553,7 +542,6 @@ namespace ppsspp game_info.DISC_ID = title.substr(0, title.find(':') - 1); game_info.TITLE = title.substr(title.find(':') + 2); HostInfo(HOSTINFO::EmuGameName, "%s %s", game_info.DISC_ID.c_str(), game_info.TITLE.c_str()); - LoadNativeHooks(game_info.DISC_ID); return; } } diff --git a/cpp/LunaHook/LunaHook/engines/ppsspp/specialgames.hpp b/cpp/LunaHook/LunaHook/engines/ppsspp/specialgames.hpp index 2bb1edef..67399c49 100644 --- a/cpp/LunaHook/LunaHook/engines/ppsspp/specialgames.hpp +++ b/cpp/LunaHook/LunaHook/engines/ppsspp/specialgames.hpp @@ -1,85 +1,6 @@ #include #include "emujitarg.hpp" -namespace PPSSPP -{ - uintptr_t findleapushalignfuncaddr(uintptr_t addr); - // 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 = findleapushalignfuncaddr(addr); - return (void *)addr; - } - void Replace_memcpy() - { - // static int Replace_memcpy() { - // u32 destPtr = PARAM(0); - // u32 srcPtr = PARAM(1); - // u32 bytes = PARAM(2); - static auto GetPointer = (void *(*)(uintptr_t))findGetPointer(); - if (!GetPointer) - return; - ConsoleOutput("GetPointer %p", GetPointer); - char ReplaceMemcpy_VideoDecodeRange[] = "ReplaceMemcpy/VideoDecodeRange"; - auto addr = MemDbg::findBytes(ReplaceMemcpy_VideoDecodeRange, sizeof(ReplaceMemcpy_VideoDecodeRange), processStartAddress, processStopAddress); - if (!addr) - return; - ConsoleOutput("ReplaceMemcpy/VideoDecodeRange %p", addr); -#ifndef _WIN64 - BYTE sig[] = {0xb9, XX4}; - *(uintptr_t *)(sig + 1) = addr; - 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 - - 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, auto *buff, auto *split) - { - auto bytes = *((DWORD *)hp->user_value + 6); - auto srcPtr = GetPointer(*((DWORD *)hp->user_value + 5)); - - if (!IsShiftjisLeadByte(*(BYTE *)srcPtr)) - return; - if (bytes != 2) - return; - if (bytes != strnlen((char *)srcPtr, TEXT_BUFFER_SIZE)) - return; - buff->from(srcPtr, bytes); - }; - NewHook(hp, "Replace_memcpy"); - } - } -} - namespace ppsspp { void ULJS00403_filter(TextBuffer *buffer, HookParam *hp) @@ -789,15 +710,13 @@ namespace ppsspp return buffer->clear(); } } - std::unordered_map> nativehooks = { - // 流行り神PORTABLE - {"ULJS00035", PPSSPP::Replace_memcpy}, - // 流行り神2PORTABLE - {"ULJS00149", PPSSPP::Replace_memcpy}, - // 流行り神3 - {"ULJS00204", PPSSPP::Replace_memcpy}, // 乱码太多 - }; std::unordered_map emfunctionhooks = { + // 流行り神PORTABLE + {0x88081cc, {0, 7, 0, 0, 0, "ULJS00035"}}, // 这三作都是单字符不断刷新,需要用比较复杂的处理 + // 流行り神2PORTABLE + {0x883EAD0, {0, 0, 0, 0, 0, "ULJS00149"}}, + // 流行り神3 + {0x885CB50, {0, 3, 0, 0, 0, "ULJS00204"}}, // 死神と少女 {0x883bf34, {0, 1, 0, 0, ULJS00403_filter, "ULJS00403"}}, // アマガミ diff --git a/cpp/LunaHook/LunaHook/hookfinder.cc b/cpp/LunaHook/LunaHook/hookfinder.cc index 7d598a67..ee0ac892 100644 --- a/cpp/LunaHook/LunaHook/hookfinder.cc +++ b/cpp/LunaHook/LunaHook/hookfinder.cc @@ -1,5 +1,6 @@ #include "MinHook.h" +#define SEARCH_SJIS_UNSAFE 0 namespace { SearchParam sp; @@ -95,7 +96,6 @@ namespace constexpr int addr_offset = 50, send_offset = 60, original_offset = 126, registers = 16; #endif } - bool IsBadReadPtr(void *data) { if (data > records.get() && data < records.get() + sp.maxRecords) @@ -134,13 +134,20 @@ void DoSend(int i, uintptr_t address, char *str, intptr_t padding, JITTYPE jitty int length = 0, sum = 0; for (; *(uint16_t *)(str + length) && length < MAX_STRING_SIZE; length += sizeof(uint16_t)) sum += *(uint16_t *)(str + length); +#if SEARCH_SJIS_UNSAFE + if (((length > STRING) || (IsDBCSLeadByteEx(932, *str))) && length < MAX_STRING_SIZE - 1) +#else if (length > STRING && length < MAX_STRING_SIZE - 1) +#endif { // many duplicate results with same address, offset, and third/fourth character will be found: filter them out uint64_t signature = ((uint64_t)i << 56) | ((uint64_t)(str[2] + str[3]) << 48) | address; +#if SEARCH_SJIS_UNSAFE +#else if (signatureCache[signature % CACHE_SIZE] == signature) return; signatureCache[signature % CACHE_SIZE] = signature; +#endif // if there are huge amount of strings that are the same, it's probably garbage: filter them out // can't store all the strings, so use sum as heuristic instead if (_InterlockedIncrement(sumCache + (sum % CACHE_SIZE)) > 25) @@ -472,13 +479,13 @@ void SearchForHooks(SearchParam spUser) } ConsoleOutput("%p %p",minemaddr,maxemaddr); ConsoleOutput("%p %p",sp.minAddress,sp.maxAddress); - #if 0 +#if SEARCH_SJIS_UNSAFE auto f=fopen("1.txt","a"); for(auto addr:jitaddr2emuaddr){ fprintf(f,"%llx => %llx\n", addr.second.second ,addr.first); } fclose(f); - #endif +#endif for(auto addr:jitaddr2emuaddr){ //ConsoleOutput("%llx => %p", addr.second.second ,addr.first); if(addr.second.second>sp.maxAddress||addr.second.secondsize() > STRING) +#if SEARCH_SJIS_UNSAFE + if (converted->size()) +#else + if (converted->size() > STRING) +#endif { wcscpy_s(info.hp.hookcode,HOOKCODE_LEN, HookCode::Generate(info.hp, processId).c_str()); OnHookFound(info.hp, std::move(converted.value()));