Advertisement
Guest User

MinHook LoadLibraryExW 2

a guest
May 31st, 2013
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 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. HMODULE (WINAPI *pFoo)(LPCWSTR, HANDLE, DWORD);
  11.  
  12. // Foo detour function
  13. void WINAPI DetourFunc()
  14. {
  15.     HMODULE h = pFoo(L"shell32.dll", NULL, 0);
  16.     WCHAR szMsg[1025];
  17.  
  18.     MH_DisableHook(LoadLibraryExW);
  19.  
  20.     wsprintfW(szMsg, L"shell32.dll loaded on %08p", h);
  21.  
  22.     MessageBoxW(NULL, szMsg, L"HOOKED", MB_OK);
  23.     ExitProcess(0);
  24. }
  25.  
  26. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  27. {
  28.     // Initialize MinHook
  29.     if (MH_Initialize() != MH_OK)
  30.     {
  31.         return 1;
  32.     }
  33.  
  34.     if (MH_CreateHook(LoadLibraryExW, &DetourFunc,
  35.         (void**)(&pFoo)) != MH_OK)
  36.     {
  37.         return 1;
  38.     }
  39.  
  40.     if (MH_EnableHook(LoadLibraryExW) != MH_OK)
  41.     {
  42.         return 1;
  43.     }
  44.  
  45.     LoadLibraryExW(L"blah", NULL, 0);
  46.  
  47.     __debugbreak(); // shouldn't reach here
  48.  
  49.     return 0; // suppress a warning
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement