1
0
mirror of synced 2024-11-24 05:50:12 +01:00
bananatools/amcus/amcus.c

75 lines
1.6 KiB
C
Raw Normal View History

2023-01-03 05:35:53 +01:00
#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(
2023-02-11 07:55:56 +01:00
const IID *const rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
const IID *const riid,
2023-01-03 05:35:53 +01:00
LPVOID *ppv);
static HRESULT (STDAPICALLTYPE *next_CoCreateInstance)(
2023-02-11 07:55:56 +01:00
const IID *const rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
const IID *const riid,
2023-01-03 05:35:53 +01:00
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));
2023-02-11 07:55:56 +01:00
2023-01-03 05:35:53 +01:00
return S_OK;
}
static HRESULT STDAPICALLTYPE my_CoCreateInstance(
2023-02-11 07:55:56 +01:00
const IID *const rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
const IID *const riid,
2023-01-03 05:35:53 +01:00
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);
2023-02-11 07:55:56 +01:00
}