diff options
author | Jose Fonseca <jfonseca@vmware.com> | 2016-09-19 20:26:29 +0100 |
---|---|---|
committer | Jose Fonseca <jfonseca@vmware.com> | 2016-09-19 20:26:29 +0100 |
commit | 35fb465f5f7d92d1e449690166b5824fda039439 (patch) | |
tree | 95e0fae2a9ffa5147833223b4c945890af98a8f8 /inject | |
parent | 1706ffd827c03510f2ffd3a4f03e68483ec580bf (diff) |
inject: Compact Mhook_SetHook invocation.
Diffstat (limited to 'inject')
-rw-r--r-- | inject/injectee_mhook.cpp | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/inject/injectee_mhook.cpp b/inject/injectee_mhook.cpp index 398496fb..c96cbc29 100644 --- a/inject/injectee_mhook.cpp +++ b/inject/injectee_mhook.cpp @@ -972,33 +972,20 @@ setHooks(void) HMODULE hKernel32 = GetModuleHandleA("kernel32"); assert(hKernel32); - RealGetProcAddress = (PFNGETPROCADDRESS)RealGetProcAddress(hKernel32, "GetProcAddress"); - assert(RealGetProcAddress); - assert(RealGetProcAddress != MyGetProcAddress); - if (!Mhook_SetHook((PVOID*)&RealGetProcAddress, (PVOID)MyGetProcAddress)) { - debugPrintf("inject: error: failed to hook GetProcAddress\n"); - } - - RealCreateProcessA = (PFNCREATEPROCESSA)RealGetProcAddress(hKernel32, "CreateProcessA"); - assert(RealCreateProcessA); - assert(RealCreateProcessA != MyCreateProcessA); - if (!Mhook_SetHook((PVOID*)&RealCreateProcessA, (PVOID)MyCreateProcessA)) { - debugPrintf("inject: error: failed to hook CreateProcessA\n"); - } +# define SET_HOOK(_name) \ + Real##_name = reinterpret_cast<decltype(Real##_name)>(RealGetProcAddress(hKernel32, #_name)); \ + assert(Real##_name); \ + assert(Real##_name != My##_name); \ + if (!Mhook_SetHook((PVOID*)&Real##_name, (PVOID)My##_name)) { \ + debugPrintf("inject: error: failed to hook " #_name "\n"); \ + } - RealCreateProcessW = (PFNCREATEPROCESSW)RealGetProcAddress(hKernel32, "CreateProcessW"); - assert(RealCreateProcessW); - assert(RealCreateProcessW != MyCreateProcessW); - if (!Mhook_SetHook((PVOID*)&RealCreateProcessW, (PVOID)MyCreateProcessW)) { - debugPrintf("inject: error: failed to hook CreateProcessW\n"); - } + SET_HOOK(GetProcAddress) + SET_HOOK(CreateProcessA) + SET_HOOK(CreateProcessW) + SET_HOOK(CreateProcessAsUserW) - RealCreateProcessAsUserW = (PFNCREATEPROCESSASUSERW)RealGetProcAddress(hKernel32, "CreateProcessAsUserW"); - assert(RealCreateProcessAsUserW); - assert(RealCreateProcessAsUserW != MyCreateProcessAsUserW); - if (!Mhook_SetHook((PVOID*)&RealCreateProcessAsUserW, (PVOID)MyCreateProcessAsUserW)) { - debugPrintf("inject: error: failed to hook CreateProcessAsUserW\n"); - } +# undef SET_HOOK } |