Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <Windows.h>
  2. DWORD WINAPI Hook_thread(LPVOID);
  3. DWORD hooked_messegebox = 0;
  4. DWORD APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  5. {
  6. switch (ul_reason_for_call)
  7. {
  8. case DLL_PROCESS_ATTACH:
  9. CreateThread(NULL, NULL, Hook_thread, NULL, NULL, NULL);
  10. case DLL_THREAD_ATTACH:
  11. case DLL_THREAD_DETACH:
  12. case DLL_PROCESS_DETACH:
  13. break;
  14. }
  15. return true;
  16. }
  17. int WINAPI HookedMessegeBox(
  18. _In_opt_ HWND hWnd,
  19. _In_opt_ LPCTSTR lpText,
  20. _In_opt_ LPCTSTR lpCaption,
  21. _In_ UINT uType
  22. )
  23. {
  24. return MessageBox (hWnd, "Hooked!", "Hooked!", MB_OK | MB_ICONERROR);
  25.  
  26. }
  27. void CallHook()
  28. {
  29. _asm call dword ptr hooked_messegebox
  30. }
  31. DWORD WINAPI Hook_thread(LPVOID)
  32. {
  33. DWORD hooked_messegebox = (DWORD)HookedMessegeBox;
  34. DWORD call_address = (DWORD)GetProcAddress(GetModuleHandleA("user32.dll"), "MessageBoxA");
  35. DWORD old_prot = 0;
  36.  
  37. VirtualProtect((void*)call_address, 6, PAGE_EXECUTE_READWRITE, &old_prot);
  38.  
  39. memcpy((void*)call_address, (PBYTE)CallHook, 6);
  40.  
  41. VirtualProtect((void*)call_address, 6, old_prot, &old_prot);
  42.  
  43. ::ExitThread(1337);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement