Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.cpp:
- #include "main.h"
- #include "MinHook.h"
- #include <madCHook - dynamic.h>
- PVOID GetInterfaceMethod(PVOID intf, DWORD methodIndex)
- {
- return *(PVOID*)(*(DWORD*)intf + methodIndex * 4);
- }
- HRESULT (WINAPI *SCLNext)(void *ptr, HWND hwnd, DWORD dwFlags) = NULL;
- HRESULT WINAPI SCLCallback(void *ptr, HWND hwnd, DWORD dwFlags)
- {
- printf("The co-operative. Good with Desktops.\n");
- return SCLNext(ptr, GetDesktopWindow(), dwFlags);
- }
- HRESULT (WINAPI *DDrawCreateNext)(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter);
- HRESULT WINAPI DDrawCreateHook(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter)
- {
- HRESULT reslt = DDrawCreateNext(lpGUID, lplpDD, pUnkOuter);
- if(SCLNext == NULL)
- {
- printf("Hooking SCL in 3... 2... 1...\n");
- printf("%i\n",MH_Initialize());
- *reinterpret_cast<void**>(&SCLNext) = GetInterfaceMethod(*lplpDD, 20);
- memcpy((void *)((DWORD*)*lplpDD + 20 * 4), (void *)&SCLCallback, 4);
- printf("hookcode %i %i %i %i\n",*lplpDD, &((*lplpDD)->SetCooperativeLevel), MH_CreateHook(GetInterfaceMethod(*lplpDD, 20), (void *)SCLCallback, (PVOID*)&SCLNext), MH_OK);
- //printf("enable %i\n", MH_EnableHook(GetInterfaceMethod(*lplpDD, 20)));
- }
- return reslt;
- }
- BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
- {
- printf("Hello!\n");
- switch (fdwReason)
- {
- case DLL_PROCESS_ATTACH:
- InitializeMadCHook();
- printf("You're going MAD!\n");
- HookAPI("DDRAW.dll", "DirectDrawCreate", (void *)DDrawCreateHook, (PVOID *) &DDrawCreateNext);
- // attach to process
- // return FALSE to fail DLL load
- break;
- case DLL_PROCESS_DETACH:
- // detach from process
- break;
- case DLL_THREAD_ATTACH:
- // attach to thread
- break;
- case DLL_THREAD_DETACH:
- // detach from thread
- break;
- }
- return TRUE; // succesful
- }
- main.h:
- #ifndef __MAIN_H__
- #define __MAIN_H__
- #include <iostream>
- #include <fstream>
- #include <windows.h>
- #include <Ddraw.h>
- /* To use this exported function of dll, include this header
- * in your project.
- */
- #ifdef BUILD_DLL
- #define DLL_EXPORT __declspec(dllexport)
- #else
- #define DLL_EXPORT __declspec(dllimport)
- #endif
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
- DLL_EXPORT HRESULT WINAPI DDrawCreateHook(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter);
- DLL_EXPORT HRESULT WINAPI SCLCallback(void *ptr, HWND hwnd, DWORD dwFlags);
- DLL_EXPORT PVOID GetInterfaceMethod(PVOID intf, DWORD methodIndex);
- #ifdef __cplusplus
- }
- #endif
- #endif // __MAIN_H__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement