bugfix hook modifying

This commit is contained in:
Akash Mozumdar 2018-08-29 17:15:59 -04:00
parent 166c9681e4
commit 02c163f930
2 changed files with 10 additions and 4 deletions

View File

@ -264,8 +264,13 @@ bool TextHook::UnsafeInsertHookCode()
} }
BYTE* original; BYTE* original;
insert:
if (MH_STATUS err = MH_CreateHook((void*)hp.address, (void*)trampoline, (void**)&original)) 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 else
{ {
ConsoleOutput(("NextHooker: UnsafeInsertHookCode: FAILED: error " + std::string(MH_StatusToString(err))).c_str()); 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() void TextHook::RemoveHookCode()
{ {
MH_DisableHook((void*)hp.address); MH_DisableHook((void*)hp.address);
MH_RemoveHook((void*)hp.address);
} }
void TextHook::RemoveReadCode() void TextHook::RemoveReadCode()
@ -379,9 +385,6 @@ void TextHook::ClearHook()
NotifyHookRemove(hp.address); NotifyHookRemove(hp.address);
if (hook_name) delete[] hook_name; if (hook_name) delete[] hook_name;
memset(this, 0, sizeof(TextHook)); // jichi 11/30/2013: This is the original code of ITH 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"); ConsoleOutput("NextHooker:RemoveHook: leave");
ReleaseMutex(hmMutex); ReleaseMutex(hmMutex);
} }

View File

@ -84,7 +84,10 @@ void RemoveHook(unsigned __int64 addr)
{ {
for (int i = 0; i < MAX_HOOK; i++) for (int i = 0; i < MAX_HOOK; i++)
if (abs((long long)(::hookman[i].hp.address - addr)) < 9) if (abs((long long)(::hookman[i].hp.address - addr)) < 9)
{
::hookman[i].ClearHook(); ::hookman[i].ClearHook();
return;
}
} }
void SwitchTrigger(DWORD t) void SwitchTrigger(DWORD t)