Skip to content

Instantly share code, notes, and snippets.

@AmyrAhmady
Created March 16, 2019 14:01
Show Gist options
  • Save AmyrAhmady/0d9c332105b684f95aac274079bfa7ab to your computer and use it in GitHub Desktop.
Save AmyrAhmady/0d9c332105b684f95aac274079bfa7ab to your computer and use it in GitHub Desktop.
smh
void Memory::HookInit()
{
// Init MinHook
if (MH_Initialize() != MH_OK)
{
printf("[Memory::Init] MH_Initialize failed!\n");
return;
}
}
void Memory::HookCleanUp()
{
MH_Uninitialize();
}
bool Memory::HookFunction(DWORD64 pAddress, void* pDetour, void** ppOriginal)
{
// Create Hook
int iResult = MH_CreateHook((void*)pAddress, pDetour, ppOriginal);
if (iResult != MH_OK)
{
printf("[Memory::HookFunction] MH_CreateHook failed: %I64x [Error %i]\n", pAddress, iResult);
MessageBoxA(0, "CreateHook fail", "Fail", 0);
return false;
}
// Enable Hook
iResult = MH_EnableHook((void*)pAddress);
if (iResult != MH_OK)
{
printf("[Memory::HookFunction] MH_EnableHook failed: %I64x [Error %i]\n", pAddress, iResult);
MessageBoxA(0, "EnableHook fail", "Fail", 0);
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment