Advertisement
Dodovogel

MessageBox (A/W) Detour (Hook) C++ #2 (C++ Casts)

Jun 1st, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <Windows.h>
  2. #include "Detour.h"
  3.  
  4. /* PBYTE pbMessageBoxA = reinterpret_cast <PBYTE> (
  5.     GetProcAddress(GetModuleHandle("User32.dll"), "MessageBoxA"));
  6. PBYTE pbMessageBoxW = reinterpret_cast <PBYTE> (
  7.     GetProcAddress(GetModuleHandle("User32.dll"), "MessageBoxW")); */
  8.  
  9. typedef int (WINAPI* tpMessageBoxA)(HWND, LPCTSTR, LPCTSTR, UINT);
  10. typedef int (WINAPI* tpMessageBoxW)(HWND, LPCWSTR, LPCWSTR, UINT);
  11. tpMessageBoxA p_tpMessageBoxA = NULL;
  12. tpMessageBoxW p_tpMessageBoxW = NULL;
  13.  
  14. int WINAPI hkMessageBoxA(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType) {
  15.     return p_tpMessageBoxA(hWnd, "Detoured;)", lpCaption, uType);
  16. }
  17.  
  18. int WINAPI hkMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType) {
  19.     return p_tpMessageBoxW(hWnd, L"Detoured;)", lpCaption, uType);
  20. }
  21.  
  22. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
  23.     if (fdwReason == 1) {
  24.  
  25.         p_tpMessageBoxA =
  26.             reinterpret_cast <tpMessageBoxA> (DetourFunction(
  27.             reinterpret_cast <PBYTE> (MessageBoxA),
  28.             reinterpret_cast <PBYTE> (hkMessageBoxA)));
  29.  
  30.         /* p_tpMessageBoxA =
  31.             reinterpret_cast <tpMessageBoxA> (DetourFunction(pbMessageBoxA,
  32.             reinterpret_cast <PBYTE> (hkMessageBoxA))); */
  33.  
  34.         p_tpMessageBoxW =
  35.             reinterpret_cast <tpMessageBoxW> (DetourFunction(
  36.             reinterpret_cast <PBYTE> (MessageBoxW),
  37.             reinterpret_cast <PBYTE> (hkMessageBoxW)));
  38.  
  39.         /* p_tpMessageBoxW =
  40.             reinterpret_cast <tpMessageBoxW> (DetourFunction(pbMessageBoxW,
  41.             reinterpret_cast <PBYTE> (hkMessageBoxW))); */
  42.  
  43.     } return 1;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement