1
0
mirror of synced 2024-12-17 22:55:52 +01:00
bananatools/amcus/amcus.c
2023-02-11 01:55:56 -05:00

75 lines
1.6 KiB
C

#include <windows.h>
#include <unknwnbase.h>
#include <combaseapi.h>
#include <rpcproxy.h>
#include "hook/table.h"
#include "amcus/amcus.h"
#include "amcus/config.h"
#include "amcus/iauth.h"
#include "util/dprintf.h"
// https://dev.s-ul.net/djhackers/bemanitools/-/blob/master/src/main/dinput/device_dinput8.c
static HRESULT STDAPICALLTYPE my_CoCreateInstance(
const IID *const rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
const IID *const riid,
LPVOID *ppv);
static HRESULT (STDAPICALLTYPE *next_CoCreateInstance)(
const IID *const rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
const IID *const riid,
LPVOID *ppv);
static const struct hook_symbol amcus_hook_syms[] = {
{
.name = "CoCreateInstance",
.patch = my_CoCreateInstance,
.link = (void **) &next_CoCreateInstance,
}
};
HRESULT amcus_hook_init(struct amcus_config *cfg)
{
assert(cfg != NULL);
amcus_config_load(cfg, L".\\bananatools.ini");
iauth_set_config(cfg);
if (!cfg->enable) {
return S_OK;
}
dprintf("AMCUS: init\n");
hook_table_apply(
NULL,
"ole32.dll",
amcus_hook_syms,
_countof(amcus_hook_syms));
return S_OK;
}
static HRESULT STDAPICALLTYPE my_CoCreateInstance(
const IID *const rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
const IID *const riid,
LPVOID *ppv)
{
if (IsEqualGUID(rclsid, &amcus_rclsid)) {
dprintf("AMCUS: CoCreateInstance GUID match\n");
*ppv = iauth_stub;
return S_OK;
}
return next_CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv);
}