TsudaKageyu / minhook

The Minimalistic x86/x64 API Hooking Library for Windows
http://www.codeproject.com/KB/winsdk/LibMinHook.aspx
Other
4.43k stars 897 forks source link

Question about disabling hook #90

Closed zonya1 closed 3 years ago

zonya1 commented 4 years ago

I need to disable a hook after a certain function has been called, inside the hooked code. So far I have just called MH_DisableHook inside the hook function and there does not seem to be any issues yet but I was wondering if this is a safe way to do it? Should you call it outside the hooked code to ensure there is no crash or other issues, or is this fine?

Nucleoprotein commented 4 years ago

I think MH_DisableHook only changes a pointer in trampoline to point to original function so it should be safe.

m417z commented 3 years ago

MH_DisableHook just restores the bytes at the beginning on the function, so as @Nucleoprotein said, it's completely safe to call it inside the hooked function.