bananatools/amcus/amcus.c
2023-01-02 23:39:03 -05:00

77 lines
1.7 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,
}
};
IAuth *test;
struct amcus_updater_state *a;
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);
}