1
0
mirror of synced 2024-11-27 23:10:49 +01:00
bananatools/amcus/amcus.c
2023-09-18 03:57:11 -04:00

85 lines
1.8 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 bool is_enable = false;
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;
}
is_enable = true;
dprintf("AMCUS: init\n");
amcus_insert_hooks(NULL);
return S_OK;
}
void amcus_insert_hooks(HMODULE target)
{
if (is_enable) {
hook_table_apply(
target,
"ole32.dll",
amcus_hook_syms,
_countof(amcus_hook_syms));
}
}
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);
}