Advertisement
Guest User

MinHook LoadLibraryExW

a guest
May 10th, 2013
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <windows.h>
  2. #include "MinHook.h"
  3.  
  4. #if defined _M_X64
  5. #pragma comment(lib, "libMinHook.x64.lib")
  6. #elif defined _M_IX86
  7. #pragma comment(lib, "libMinHook.x86.lib")
  8. #endif
  9.  
  10. // Foo detour function
  11. void WINAPI DetourFunc()
  12. {
  13.     MH_DisableHook(LoadLibraryExW);
  14.  
  15.     MessageBox(NULL, "HOOKED: Exiting" ,"HOOKED", MB_OK);
  16.     ExitProcess(0);
  17. }
  18.  
  19. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  20. {
  21.     void *pFoo;
  22.  
  23.     // Initialize MinHook
  24.     if (MH_Initialize() != MH_OK)
  25.     {
  26.         return 1;
  27.     }
  28.  
  29.     if (MH_CreateHook(LoadLibraryExW, &DetourFunc,
  30.         (void**)(&pFoo)) != MH_OK)
  31.     {
  32.         return 1;
  33.     }
  34.  
  35.     if (MH_EnableHook(LoadLibraryExW) != MH_OK)
  36.     {
  37.         return 1;
  38.     }
  39.  
  40.     LoadLibraryExW(L"blah", NULL, 0);
  41.  
  42.     __debugbreak(); // shouldn't reach here
  43.  
  44.     return 0; // suppress a warning
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement