1
0
mirror of https://gitea.tendokyu.moe/Dniel97/segatools.git synced 2024-11-15 01:27:36 +01:00
segatools-dniel97/mercuryhook/elisabeth.c

85 lines
1.9 KiB
C
Raw Normal View History

2021-12-30 06:51:44 +01:00
#include <initguid.h>
#include <windows.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include "mercuryhook/elisabeth.h"
2021-12-30 19:57:05 +01:00
#include "mercuryhook/mercury-dll.h"
#include "hook/table.h"
2021-12-30 19:57:05 +01:00
#include "hooklib/uart.h"
#include "hooklib/dll.h"
#include "hooklib/path.h"
2021-12-30 03:58:00 +01:00
#include "hooklib/setupapi.h"
#include "util/dprintf.h"
/* Hooks targeted DLLs dynamically loaded by elisabeth. */
static void dll_hook_insert_hooks(HMODULE target);
static FARPROC WINAPI my_GetProcAddress(HMODULE hModule, const char *name);
static FARPROC (WINAPI *next_GetProcAddress)(HMODULE hModule, const char *name);
2022-01-04 06:10:46 +01:00
static int my_USBIntLED_Init();
2022-07-31 20:11:24 +02:00
static int my_USBIntLED_set();
2021-12-30 03:58:00 +01:00
static const struct hook_symbol win32_hooks[] = {
{
.name = "GetProcAddress",
.patch = my_GetProcAddress,
.link = (void **) &next_GetProcAddress
}
};
2021-12-30 19:57:05 +01:00
HRESULT elisabeth_hook_init()
{
dll_hook_insert_hooks(NULL);
2022-05-29 06:23:24 +02:00
dprintf("Elisabeth: Init\n");
return S_OK;
}
static void dll_hook_insert_hooks(HMODULE target)
{
hook_table_apply(
target,
"kernel32.dll",
2021-12-30 03:58:00 +01:00
win32_hooks,
_countof(win32_hooks));
}
FARPROC WINAPI my_GetProcAddress(HMODULE hModule, const char *name)
{
2021-12-30 03:58:00 +01:00
uintptr_t ordinal = (uintptr_t) name;
2021-12-30 06:51:44 +01:00
FARPROC result = next_GetProcAddress(hModule, name);
2021-12-30 03:58:00 +01:00
if (ordinal > 0xFFFF) {
/* Import by name */
2022-01-04 06:10:46 +01:00
if (strcmp(name, "USBIntLED_Init") == 0) {
result = (FARPROC) my_USBIntLED_Init;
2022-01-04 06:10:46 +01:00
}
2022-07-31 20:11:24 +02:00
if (strcmp(name, "USBIntLED_set") == 0) {
result = (FARPROC) my_USBIntLED_set;
}
}
return result;
}
2022-01-04 06:10:46 +01:00
/* Intercept the call to initialize the LED board. */
static int my_USBIntLED_Init()
{
dprintf("Elisabeth: my_USBIntLED_Init hit!\n");
return 1;
}
2022-07-31 20:11:24 +02:00
static int my_USBIntLED_set(int data1, struct led_data data2)
{
assert(mercury_dll.set_leds != NULL);
mercury_dll.set_leds(data2);
return 1;
}