Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- DWORD WINAPI Hook_thread(LPVOID);
- DWORD hooked_messegebox = 0;
- DWORD APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- CreateThread(NULL, NULL, Hook_thread, NULL, NULL, NULL);
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return true;
- }
- int WINAPI HookedMessegeBox(
- _In_opt_ HWND hWnd,
- _In_opt_ LPCTSTR lpText,
- _In_opt_ LPCTSTR lpCaption,
- _In_ UINT uType
- )
- {
- return MessageBox (hWnd, "Hooked!", "Hooked!", MB_OK | MB_ICONERROR);
- }
- void CallHook()
- {
- _asm call dword ptr hooked_messegebox
- }
- DWORD WINAPI Hook_thread(LPVOID)
- {
- DWORD hooked_messegebox = (DWORD)HookedMessegeBox;
- DWORD call_address = (DWORD)GetProcAddress(GetModuleHandleA("user32.dll"), "MessageBoxA");
- DWORD old_prot = 0;
- VirtualProtect((void*)call_address, 6, PAGE_EXECUTE_READWRITE, &old_prot);
- memcpy((void*)call_address, (PBYTE)CallHook, 6);
- VirtualProtect((void*)call_address, 6, old_prot, &old_prot);
- ::ExitThread(1337);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement