1
0
mirror of synced 2024-11-30 16:24:27 +01:00
bananatools/amcus/amcus.c

85 lines
1.8 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
2023-09-18 09:57:11 +02:00
static bool is_enable = false;
2023-01-03 05:35:53 +01:00
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;
}
2023-09-18 09:57:11 +02:00
is_enable = true;
2023-01-03 05:35:53 +01:00
dprintf("AMCUS: init\n");
2023-09-18 09:57:11 +02:00
amcus_insert_hooks(NULL);
2023-02-11 07:55:56 +01:00
2023-01-03 05:35:53 +01:00
return S_OK;
}
2023-09-18 09:57:11 +02:00
void amcus_insert_hooks(HMODULE target)
{
if (is_enable) {
hook_table_apply(
target,
"ole32.dll",
amcus_hook_syms,
_countof(amcus_hook_syms));
}
}
2023-01-03 05:35:53 +01:00
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
}