int main() { hfoo = subhook_new((void *)foo, (void *)foo_hook); subhook_install(hfoo); foo(); subhook_remove(hfoo); foo(); subhook_install(hfoo); foo(); subhook_remove(hfoo); foo(); subhook_free(hfoo); }
void CHooks::InstallHooks() { // Reset public flag bGiveDamage = false; // Find the function pointers BYTE *pFindPublic = *(BYTE **)((DWORD)pAMXFunctions + PLUGIN_AMX_EXPORT_FindPublic * 4); BYTE *pPush = *(BYTE **)((DWORD)pAMXFunctions + PLUGIN_AMX_EXPORT_Push * 4); BYTE *pExec = *(BYTE **)((DWORD)pAMXFunctions + PLUGIN_AMX_EXPORT_Exec * 4); // Hook for amx_FindPublic hookFindPublic = subhook_new(pFindPublic, (BYTE *)&amx_FindPublic_Hook); subhook_install(hookFindPublic); // Hook for amx_Push hookPush = subhook_new(pPush, (BYTE *)&amx_Push_Hook); subhook_install(hookPush); // Hook for amx_Exec hookExec = subhook_new(pExec, (BYTE *)&amx_Exec_Hook); subhook_install(hookExec); }
BOOL Mhook_SetHook(PVOID * ppSystemFunctionP, PVOID pHookFunction) { Mhook_MyInit(); if(ppSystemFunctionP==NULL||pHookFunction==NULL) { return FALSE; } PVOID ppSystemFunction=(void*)(*ppSystemFunctionP); if(ppSystemFunction==NULL) return FALSE; if(mhooks_subhooks_count>=MHOOKS_MAX_SUPPORTED_HOOKS) { return FALSE; } else if(mhooks_subhooks_count<0) { mhooks_subhooks_count=0; } mhooks_subhooks[mhooks_subhooks_count]=subhook_new(ppSystemFunction, pHookFunction); if(mhooks_subhooks[mhooks_subhooks_count]==NULL) { return FALSE; } subhook_install(mhooks_subhooks[mhooks_subhooks_count]); if(subhook_is_installed(mhooks_subhooks[mhooks_subhooks_count])) { void * rr= subhook_get_trampoline(mhooks_subhooks[mhooks_subhooks_count]); if(rr==NULL) { subhook_remove(mhooks_subhooks[mhooks_subhooks_count]); subhook_free(mhooks_subhooks[mhooks_subhooks_count]); mhooks_subhooks[mhooks_subhooks_count]=NULL; return FALSE; } *ppSystemFunctionP=(void*)rr; } mhooks_subhooks_count++; return TRUE; }