From 02c163f9304eebffdc59b7258156dc94d621f2be Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Wed, 29 Aug 2018 17:15:59 -0400 Subject: [PATCH] bugfix hook modifying --- vnrhook/hijack/texthook.cc | 11 +++++++---- vnrhook/main.cc | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/vnrhook/hijack/texthook.cc b/vnrhook/hijack/texthook.cc index e37d3dc..3a28aa8 100644 --- a/vnrhook/hijack/texthook.cc +++ b/vnrhook/hijack/texthook.cc @@ -264,8 +264,13 @@ bool TextHook::UnsafeInsertHookCode() } BYTE* original; + insert: if (MH_STATUS err = MH_CreateHook((void*)hp.address, (void*)trampoline, (void**)&original)) - if (err == MH_ERROR_ALREADY_CREATED) RemoveHook(hp.address); + if (err == MH_ERROR_ALREADY_CREATED) + { + RemoveHook(hp.address); + goto insert; // FIXME: i'm too lazy to do this properly right now... + } else { ConsoleOutput(("NextHooker: UnsafeInsertHookCode: FAILED: error " + std::string(MH_StatusToString(err))).c_str()); @@ -362,6 +367,7 @@ void TextHook::InitHook(const HookParam &h, LPCSTR name, WORD set_flag) void TextHook::RemoveHookCode() { MH_DisableHook((void*)hp.address); + MH_RemoveHook((void*)hp.address); } void TextHook::RemoveReadCode() @@ -379,9 +385,6 @@ void TextHook::ClearHook() NotifyHookRemove(hp.address); if (hook_name) delete[] hook_name; memset(this, 0, sizeof(TextHook)); // jichi 11/30/2013: This is the original code of ITH - //if (current_available>this) - // current_available = this; - currentHook--; ConsoleOutput("NextHooker:RemoveHook: leave"); ReleaseMutex(hmMutex); } diff --git a/vnrhook/main.cc b/vnrhook/main.cc index b74e71c..852f8ca 100644 --- a/vnrhook/main.cc +++ b/vnrhook/main.cc @@ -84,7 +84,10 @@ void RemoveHook(unsigned __int64 addr) { for (int i = 0; i < MAX_HOOK; i++) if (abs((long long)(::hookman[i].hp.address - addr)) < 9) + { ::hookman[i].ClearHook(); + return; + } } void SwitchTrigger(DWORD t)