// 1. get memory address of the MessageBoxA function from user32.dll hinstLib= LoadLibraryA(TEXT("user32.dll")); function_address= GetProcAddress(hinstLib, "MessageBoxA");
// 1. get memory address of the MessageBoxA function from user32.dll hinstLib= LoadLibraryA(TEXT("user32.dll")); function_address= GetProcAddress(hinstLib, "MessageBoxA");
// 2. save the first 5 bytes into saved_buffer ReadProcessMemory(GetCurrentProcess(), function_address, saved_buffer, 5, NULL);
// 3. overwrite the first 5 bytes with a call to proxy_function proxy_address= &proxy_function; src= (DWORD)function_address + 5; dst= (DWORD)proxy_address; relative_offset= (DWORD *)(dst-src);
// The proxy function we will jump to after the hook has been installed int __stdcall proxy_function(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) { std::cout << "Hello from MessageBox!\n"; std::cout << "Text: " << (LPCSTR)lpText << "\nCaption: " << (LPCSTR)lpCaption << "\n";
// unhook the function (re-write the saved buffer) to prevent infinite recursion WriteProcessMemory(GetCurrentProcess(), (LPVOID)hooked_address, saved_buffer, 5, NULL);
// return to the original function and modify the intended parameters returnMessageBoxA(NULL, "yeet", "yeet", uType); }