From 1b28a2cfad839f9247231a56421fda1383851401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Sat, 16 Nov 2024 20:24:23 +0800 Subject: [PATCH] fix --- cpp/LunaHook/LunaHook/main.cc | 12 +++++------- cpp/LunaHook/LunaHook/main.h | 1 - 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cpp/LunaHook/LunaHook/main.cc b/cpp/LunaHook/LunaHook/main.cc index 872cc1a8..d6a1bc54 100644 --- a/cpp/LunaHook/LunaHook/main.cc +++ b/cpp/LunaHook/LunaHook/main.cc @@ -5,6 +5,7 @@ void detachall(); HMODULE hLUNAHOOKDLL; WinMutex viewMutex; CommonSharedMem *commonsharedmem; +Synchronized>> delayinserthook; // 谜之这个必须在这里定义(可以extern+cpp里定义,或者只在这里写),不能在main.h里inline定义,否则会在v141_xp上编译后会崩。 namespace { AutoHandle<> hookPipe = INVALID_HANDLE_VALUE, @@ -252,20 +253,17 @@ bool NewHook_1(HookParam &hp, LPCSTR lpname) return true; } } -static std::mutex delayinsertlock; void delayinsertadd(HookParam hp, std::string name) { - std::lock_guard _(maplock); - delayinserthook[hp.emu_addr] = {name, hp}; + delayinserthook->insert(std::make_pair(hp.emu_addr, std::make_pair(name, hp))); ConsoleOutput(INSERTING_HOOK, name.c_str(), hp.emu_addr); } void delayinsertNewHook(uint64_t em_address) { - if (delayinserthook.find(em_address) == delayinserthook.end()) + if (delayinserthook->find(em_address) == delayinserthook->end()) return; - std::lock_guard _(maplock); - auto h = delayinserthook[em_address]; - delayinserthook.erase(em_address); + auto h = delayinserthook->at(em_address); + delayinserthook->erase(em_address); NewHook(h.second, h.first.c_str()); } bool NewHook(HookParam hp, LPCSTR name) diff --git a/cpp/LunaHook/LunaHook/main.h b/cpp/LunaHook/LunaHook/main.h index dbfb21ea..47c6bfc8 100644 --- a/cpp/LunaHook/LunaHook/main.h +++ b/cpp/LunaHook/LunaHook/main.h @@ -25,7 +25,6 @@ void jitaddraddr(uint64_t em_addr, uintptr_t jitaddr, JITTYPE); void context_get(hook_stack *, PCONTEXT); void context_set(hook_stack *, PCONTEXT); -inline std::map> delayinserthook; void delayinsertadd(HookParam, std::string); void delayinsertNewHook(uint64_t); inline bool safeautoleaveveh = false;