dinput.dll proxy with CoCreateInstance hook

This commit is contained in:
FunkyFr3sh 2021-08-02 17:27:19 +02:00
parent d31ffbade5
commit a25e4d35f8
6 changed files with 38 additions and 1 deletions

View file

@ -236,7 +236,7 @@ HRESULT WINAPI fake_DirectInputCreateEx(
if (!real_DirectInputCreateEx)
{
real_DirectInputCreateEx =
(DIRECTINPUTCREATEEXPROC)GetProcAddress(GetModuleHandle("dinput.dll"), "DirectInputCreateEx");
(DIRECTINPUTCREATEEXPROC)GetProcAddress(LoadLibraryA("system32\\dinput.dll"), "DirectInputCreateEx");
}
if (!real_DirectInputCreateEx)

View file

@ -44,6 +44,7 @@ LOADLIBRARYAPROC real_LoadLibraryA = LoadLibraryA;
LOADLIBRARYWPROC real_LoadLibraryW = LoadLibraryW;
LOADLIBRARYEXAPROC real_LoadLibraryExA = LoadLibraryExA;
LOADLIBRARYEXWPROC real_LoadLibraryExW = LoadLibraryExW;
COCREATEINSTANCEPROC real_CoCreateInstance = CoCreateInstance;
static HOOKLIST g_hooks[] =
{
@ -440,6 +441,15 @@ void hook_init()
void hook_early_init()
{
/*
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_CoCreateInstance, (PVOID)fake_CoCreateInstance);
DetourTransactionCommit();
*/
hook_patch_iat(GetModuleHandle(NULL), FALSE, "ole32.dll", "CoCreateInstance", (PROC)fake_CoCreateInstance);
hook_patch_iat(GetModuleHandle(NULL), FALSE, "dinput.dll", "DirectInputCreateA", (PROC)fake_DirectInputCreateA);
hook_patch_iat(GetModuleHandle(NULL), FALSE, "dinput.dll", "DirectInputCreateW", (PROC)fake_DirectInputCreateW);
hook_patch_iat(GetModuleHandle(NULL), FALSE, "dinput.dll", "DirectInputCreateEx", (PROC)fake_DirectInputCreateEx);
@ -493,6 +503,8 @@ void hook_exit()
hook_revert((HOOKLIST*)&g_hooks);
}
hook_patch_iat(GetModuleHandle(NULL), TRUE, "ole32.dll", "CoCreateInstance", (PROC)fake_CoCreateInstance);
hook_patch_iat(GetModuleHandle(NULL), TRUE, "dinput.dll", "DirectInputCreateA", (PROC)fake_DirectInputCreateA);
hook_patch_iat(GetModuleHandle(NULL), TRUE, "dinput.dll", "DirectInputCreateW", (PROC)fake_DirectInputCreateW);
hook_patch_iat(GetModuleHandle(NULL), TRUE, "dinput.dll", "DirectInputCreateEx", (PROC)fake_DirectInputCreateEx);

View file

@ -3,6 +3,7 @@
#include <math.h>
#include "debug.h"
#include "dd.h"
#include "ddraw.h"
#include "hook.h"
#include "config.h"
#include "utils.h"
@ -630,3 +631,22 @@ HWND WINAPI fake_CreateWindowExA(
hInstance,
lpParam);
}
HRESULT WINAPI fake_CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID* ppv)
{
if (rclsid && riid && (IsEqualGUID(&CLSID_DirectDraw, rclsid) || IsEqualGUID(&CLSID_DirectDraw7, rclsid)))
{
if (IsEqualGUID(&IID_IDirectDraw2, riid) ||
IsEqualGUID(&IID_IDirectDraw4, riid) ||
IsEqualGUID(&IID_IDirectDraw7, riid))
{
return dd_CreateEx(NULL, ppv, NULL, NULL);
}
else
{
return dd_CreateEx(NULL, ppv, &IID_IDirectDraw, NULL);
}
}
return real_CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv);
}