Advertisement
Muzer

wkUseDesktopWindow, failed attempt at writing to vtable

Mar 25th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 KB | None | 0 0
  1. main.cpp:
  2.  
  3. #include "main.h"
  4. #include "MinHook.h"
  5. #include <madCHook - dynamic.h>
  6.  
  7. PVOID GetInterfaceMethod(PVOID intf, DWORD methodIndex)
  8. {
  9.   return *(PVOID*)(*(DWORD*)intf + methodIndex * 4);
  10. }
  11.  
  12. HRESULT (WINAPI *SCLNext)(void *ptr, HWND hwnd, DWORD dwFlags) = NULL;
  13.  
  14. HRESULT WINAPI SCLCallback(void *ptr, HWND hwnd, DWORD dwFlags)
  15. {
  16.     printf("The co-operative. Good with Desktops.\n");
  17.     return SCLNext(ptr, GetDesktopWindow(), dwFlags);
  18. }
  19.  
  20. HRESULT (WINAPI *DDrawCreateNext)(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter);
  21.  
  22. HRESULT WINAPI DDrawCreateHook(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter)
  23. {
  24.     HRESULT reslt = DDrawCreateNext(lpGUID, lplpDD, pUnkOuter);
  25.     if(SCLNext == NULL)
  26.     {
  27.         printf("Hooking SCL in 3... 2... 1...\n");
  28.         printf("%i\n",MH_Initialize());
  29.         *reinterpret_cast<void**>(&SCLNext) = GetInterfaceMethod(*lplpDD, 20);
  30.         memcpy((void *)((DWORD*)*lplpDD + 20 * 4), (void *)&SCLCallback, 4);
  31.         printf("hookcode %i %i %i %i\n",*lplpDD, &((*lplpDD)->SetCooperativeLevel), MH_CreateHook(GetInterfaceMethod(*lplpDD, 20), (void *)SCLCallback, (PVOID*)&SCLNext), MH_OK);
  32.         //printf("enable %i\n", MH_EnableHook(GetInterfaceMethod(*lplpDD, 20)));
  33.     }
  34.     return reslt;
  35. }
  36.  
  37. BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  38. {
  39.     printf("Hello!\n");
  40.     switch (fdwReason)
  41.     {
  42.         case DLL_PROCESS_ATTACH:
  43.             InitializeMadCHook();
  44.             printf("You're going MAD!\n");
  45.             HookAPI("DDRAW.dll", "DirectDrawCreate", (void *)DDrawCreateHook, (PVOID *) &DDrawCreateNext);
  46.  
  47.             // attach to process
  48.             // return FALSE to fail DLL load
  49.             break;
  50.  
  51.         case DLL_PROCESS_DETACH:
  52.             // detach from process
  53.             break;
  54.  
  55.         case DLL_THREAD_ATTACH:
  56.             // attach to thread
  57.             break;
  58.  
  59.         case DLL_THREAD_DETACH:
  60.             // detach from thread
  61.             break;
  62.     }
  63.     return TRUE; // succesful
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. main.h:
  72.  
  73. #ifndef __MAIN_H__
  74. #define __MAIN_H__
  75.  
  76. #include <iostream>
  77. #include <fstream>
  78. #include <windows.h>
  79. #include <Ddraw.h>
  80.  
  81. /*  To use this exported function of dll, include this header
  82.  *  in your project.
  83.  */
  84.  
  85. #ifdef BUILD_DLL
  86.     #define DLL_EXPORT __declspec(dllexport)
  87. #else
  88.     #define DLL_EXPORT __declspec(dllimport)
  89. #endif
  90.  
  91.  
  92. #ifdef __cplusplus
  93. extern "C"
  94. {
  95. #endif
  96.  
  97. DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
  98. DLL_EXPORT HRESULT WINAPI DDrawCreateHook(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter);
  99. DLL_EXPORT HRESULT WINAPI SCLCallback(void *ptr, HWND hwnd, DWORD dwFlags);
  100. DLL_EXPORT PVOID GetInterfaceMethod(PVOID intf, DWORD methodIndex);
  101.  
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105.  
  106. #endif // __MAIN_H__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement