Advertisement
EddyCZ

Untitled

Apr 14th, 2023
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <windows.h>
  2. #include <detours.h>
  3.  
  4. // define a typedef for the original function
  5. typedef int(WINAPI* PMessageBox)(HWND, LPCWSTR, LPCWSTR, UINT);
  6.  
  7. // define the function pointer for the original function
  8. PMessageBox pMessageBox = MessageBoxW;
  9.  
  10. // define the replacement function
  11. int WINAPI MyMessageBox(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
  12. {
  13.     return pMessageBox(hWnd, L"Hello from hooked function!", lpCaption, uType);
  14. }
  15.  
  16. int main()
  17. {
  18.     // detour the MessageBoxW function to our replacement function
  19.     DetourTransactionBegin();
  20.     DetourUpdateThread(GetCurrentThread());
  21.     DetourAttach(&(LPVOID&)pMessageBox, MyMessageBox);
  22.     DetourTransactionCommit();
  23.  
  24.     // call the hooked function
  25.     MessageBoxW(NULL, L"Hello world!", L"Greetings", MB_OK);
  26.  
  27.     // remove the hook and exit
  28.     DetourTransactionBegin();
  29.     DetourUpdateThread(GetCurrentThread());
  30.     DetourDetach(&(LPVOID&)pMessageBox, MyMessageBox);
  31.     DetourTransactionCommit();
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement