1
0
mirror of https://gitea.tendokyu.moe/Dniel97/segatools.git synced 2024-11-24 05:20:10 +01:00

added setupapi hook to elisabeth

This commit is contained in:
Kevin Trocolli 2021-12-29 21:58:00 -05:00 committed by Hay1tsme
parent 31d1ffe24f
commit 40ce4d1bb3
4 changed files with 27 additions and 28 deletions

View File

@ -284,6 +284,8 @@ static HMODULE WINAPI hook_LoadLibraryW(const wchar_t *name)
{ {
HMODULE result; HMODULE result;
dprintf("hook_LoadLibraryW: Loading %S\n", name);
if (name == NULL) { if (name == NULL) {
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);

View File

@ -134,22 +134,27 @@ end:
return hr; return hr;
} }
static void setupapi_hook_init(void) static void setupapi_hook_init()
{ {
if (setupapi_initted) { if (setupapi_initted) {
return; return;
} }
hook_table_apply( setupapi_hook_insert_hooks(NULL);
NULL,
"setupapi.dll",
setupapi_syms,
_countof(setupapi_syms));
InitializeCriticalSection(&setupapi_lock); InitializeCriticalSection(&setupapi_lock);
setupapi_initted = true; setupapi_initted = true;
} }
void setupapi_hook_insert_hooks(HMODULE target)
{
hook_table_apply(
target,
"setupapi.dll",
setupapi_syms,
_countof(setupapi_syms));
}
static HDEVINFO WINAPI my_SetupDiGetClassDevsW( static HDEVINFO WINAPI my_SetupDiGetClassDevsW(
const GUID *ClassGuid, const GUID *ClassGuid,
wchar_t *Enumerator, wchar_t *Enumerator,
@ -191,6 +196,7 @@ static BOOL WINAPI my_SetupDiEnumDeviceInterfaces(
DWORD MemberIndex, DWORD MemberIndex,
SP_DEVICE_INTERFACE_DATA *DeviceInterfaceData) SP_DEVICE_INTERFACE_DATA *DeviceInterfaceData)
{ {
dprintf("my_SetupDiEnumDeviceInterfaces hit!\n");
const struct setupapi_class *class_; const struct setupapi_class *class_;
size_t i; size_t i;

View File

@ -5,3 +5,4 @@
#include <stddef.h> #include <stddef.h>
HRESULT setupapi_add_phantom_dev(const GUID *iface_class, const wchar_t *path); HRESULT setupapi_add_phantom_dev(const GUID *iface_class, const wchar_t *path);
void setupapi_hook_insert_hooks(HMODULE target);

View File

@ -10,6 +10,7 @@
#include "hooklib/dll.h" #include "hooklib/dll.h"
#include "hooklib/path.h" #include "hooklib/path.h"
#include "hooklib/setupapi.h"
#include "util/dprintf.h" #include "util/dprintf.h"
@ -21,7 +22,7 @@ static HMODULE (WINAPI *next_LoadLibraryW)(const wchar_t *name);
static FARPROC WINAPI my_GetProcAddress(HMODULE hModule, const char *name); static FARPROC WINAPI my_GetProcAddress(HMODULE hModule, const char *name);
static FARPROC (WINAPI *next_GetProcAddress)(HMODULE hModule, const char *name); static FARPROC (WINAPI *next_GetProcAddress)(HMODULE hModule, const char *name);
static const struct hook_symbol elisabeth_hooks[] = { static const struct hook_symbol win32_hooks[] = {
{ {
.name = "LoadLibraryW", .name = "LoadLibraryW",
.patch = my_LoadLibraryW, .patch = my_LoadLibraryW,
@ -39,14 +40,7 @@ static const wchar_t *target_modules[] = {
L"ftd2XX.dll", L"ftd2XX.dll",
}; };
static const char *target_functions[] = {
"FT_Read",
"FT_Write",
"USBIntLED_Init",
};
static const size_t target_modules_len = _countof(target_modules); static const size_t target_modules_len = _countof(target_modules);
static const size_t target_functions_len = _countof(target_functions);
void elisabeth_hook_init() void elisabeth_hook_init()
{ {
@ -58,8 +52,8 @@ static void dll_hook_insert_hooks(HMODULE target)
hook_table_apply( hook_table_apply(
target, target,
"kernel32.dll", "kernel32.dll",
elisabeth_hooks, win32_hooks,
_countof(elisabeth_hooks)); _countof(win32_hooks));
} }
static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name) static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name)
@ -71,6 +65,8 @@ static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name)
size_t name_len; size_t name_len;
size_t target_module_len; size_t target_module_len;
dprintf("Elisabeth: Trying to load %S\n", name);
if (name == NULL) { if (name == NULL) {
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
@ -107,7 +103,7 @@ static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name)
dprintf("Elisabeth: Loaded %S\n", target_module); dprintf("Elisabeth: Loaded %S\n", target_module);
dll_hook_insert_hooks(result); dll_hook_insert_hooks(result);
path_hook_insert_hooks(result); setupapi_hook_insert_hooks(result);
} }
} }
@ -116,19 +112,13 @@ static HMODULE WINAPI my_LoadLibraryW(const wchar_t *name)
FARPROC WINAPI my_GetProcAddress(HMODULE hModule, const char *name) FARPROC WINAPI my_GetProcAddress(HMODULE hModule, const char *name)
{ {
uintptr_t ordinal; uintptr_t ordinal = (uintptr_t) name;
FARPROC result = next_GetProcAddress(hModule, name); FARPROC result = next_GetProcAddress(hModule, name);
if (ordinal > 0xFFFF) {
for (size_t i = 0; i < target_functions_len; i++) { /* Import by name */
ordinal = (uintptr_t) name; dprintf("Elisabeth: GetProcAddress %s is %p\n", name, result);
if (ordinal > 0xFFFF) {
/* Import by name */
if (strcmp(target_functions[i], name) == 0)
dprintf("Elisabeth: GetProcAddress %s is %p\n", name, result);
}
} }
return result; return result;