From 56a32fd80ad452a2360eb2186131534dfd8e057c Mon Sep 17 00:00:00 2001 From: 6cb1008cabfc0d4485696f6df7431a5e27604e1b <6cb1008cabfc0d4485696f6df7431a5e27604e1b@redacted> Date: Wed, 16 Jun 2021 12:08:08 +0200 Subject: [PATCH] Add dvd hook to allow hiding connected dvd drives --- hooklib/config.c | 9 +++++ hooklib/config.h | 2 ++ hooklib/dvd.c | 85 +++++++++++++++++++++++++++++++++++++++++++++ hooklib/dvd.h | 11 ++++++ hooklib/meson.build | 2 ++ idzhook/config.c | 4 +++ idzhook/config.h | 3 ++ idzhook/dllmain.c | 3 +- mu3hook/config.c | 2 ++ mu3hook/config.h | 2 ++ mu3hook/dllmain.c | 2 ++ 11 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 hooklib/dvd.c create mode 100644 hooklib/dvd.h diff --git a/hooklib/config.c b/hooklib/config.c index 1c4c9c4..a7a5a57 100644 --- a/hooklib/config.c +++ b/hooklib/config.c @@ -6,6 +6,7 @@ #include "hooklib/config.h" #include "hooklib/gfx.h" +#include "hooklib/dvd.h" void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename) { @@ -17,3 +18,11 @@ void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename) cfg->framed = GetPrivateProfileIntW(L"gfx", L"framed", 1, filename); cfg->monitor = GetPrivateProfileIntW(L"gfx", L"monitor", 0, filename); } + +void dvd_config_load(struct dvd_config *cfg, const wchar_t *filename) +{ + assert(cfg != NULL); + assert(filename != NULL); + + cfg->enable = GetPrivateProfileIntW(L"dvd", L"enable", 1, filename); +} diff --git a/hooklib/config.h b/hooklib/config.h index 0d737aa..ed3d7d4 100644 --- a/hooklib/config.h +++ b/hooklib/config.h @@ -4,5 +4,7 @@ #include #include "hooklib/gfx.h" +#include "hooklib/dvd.h" void gfx_config_load(struct gfx_config *cfg, const wchar_t *filename); +void dvd_config_load(struct dvd_config *cfg, const wchar_t *filename); diff --git a/hooklib/dvd.c b/hooklib/dvd.c new file mode 100644 index 0000000..f8050f4 --- /dev/null +++ b/hooklib/dvd.c @@ -0,0 +1,85 @@ +#include + +#include +#include +#include + +#include "hook/com-proxy.h" +#include "hook/table.h" + +#include "hooklib/config.h" +#include "hooklib/dll.h" +#include "hooklib/dvd.h" + +#include "util/dprintf.h" + +/* API hooks */ + +static DWORD WINAPI hook_QueryDosDeviceW( + const wchar_t *lpDeviceName, + wchar_t *lpTargetPath, + DWORD ucchMax); + +/* Link pointers */ + +static DWORD (WINAPI *next_QueryDosDeviceW)( + const wchar_t *lpDeviceName, + wchar_t *lpTargetPath, + DWORD ucchMax); + +static bool dvd_hook_initted; +static struct dvd_config dvd_config; + +static const struct hook_symbol dvd_hooks[] = { + { + .name = "QueryDosDeviceW", + .patch = hook_QueryDosDeviceW, + .link = (void **) &next_QueryDosDeviceW + }, +}; + +void dvd_hook_init(const struct dvd_config *cfg, HINSTANCE self) +{ + assert(cfg != NULL); + + if (!cfg->enable) { + return; + } + + /* Init is not thread safe because API hook init is not thread safe blah + blah blah you know the drill by now. */ + + if (dvd_hook_initted) { + return; + } + + dvd_hook_initted = true; + + memcpy(&dvd_config, cfg, sizeof(*cfg)); + hook_table_apply(NULL, "kernel32.dll", dvd_hooks, _countof(dvd_hooks)); + dprintf("DVD: hook enabled.\n"); +} + +DWORD WINAPI hook_QueryDosDeviceW( + const wchar_t *lpDeviceName, + wchar_t *lpTargetPath, + DWORD ucchMax) +{ + DWORD ok; + wchar_t *p_dest; + wchar_t *dvd_string = L"CdRom"; + + ok = next_QueryDosDeviceW( + lpDeviceName, + lpTargetPath, + ucchMax); + + p_dest = wcsstr (lpTargetPath, dvd_string); + + if ( p_dest != NULL ) { + dprintf("DVD: Hiding DVD drive.\n"); + return 0; + } + + return ok; +} diff --git a/hooklib/dvd.h b/hooklib/dvd.h new file mode 100644 index 0000000..ce2f09b --- /dev/null +++ b/hooklib/dvd.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +#include + +struct dvd_config { + bool enable; +}; + +void dvd_hook_init(const struct dvd_config *cfg, HINSTANCE self); diff --git a/hooklib/meson.build b/hooklib/meson.build index 80abf6e..e75056a 100644 --- a/hooklib/meson.build +++ b/hooklib/meson.build @@ -13,6 +13,8 @@ hooklib_lib = static_library( 'dll.h', 'dns.c', 'dns.h', + 'dvd.c', + 'dvd.h', 'fdshark.c', 'fdshark.h', 'gfx.c', diff --git a/idzhook/config.c b/idzhook/config.c index c8d551d..a7d095d 100644 --- a/idzhook/config.c +++ b/idzhook/config.c @@ -7,6 +7,9 @@ #include "board/config.h" #include "board/sg-reader.h" +#include "hooklib/config.h" +#include "hooklib/dvd.h" + #include "idzhook/config.h" #include "idzhook/idz-dll.h" @@ -41,6 +44,7 @@ void idz_hook_config_load( aime_config_load(&cfg->aime, filename); idz_dll_config_load(&cfg->dll, filename); zinput_config_load(&cfg->zinput, filename); + dvd_config_load(&cfg->dvd, filename); } void zinput_config_load(struct zinput_config *cfg, const wchar_t *filename) diff --git a/idzhook/config.h b/idzhook/config.h index a7cf964..58e421e 100644 --- a/idzhook/config.h +++ b/idzhook/config.h @@ -7,6 +7,8 @@ #include "board/sg-reader.h" +#include "hooklib/dvd.h" + #include "idzhook/idz-dll.h" #include "idzhook/zinput.h" @@ -16,6 +18,7 @@ struct idz_hook_config { struct platform_config platform; struct amex_config amex; struct aime_config aime; + struct dvd_config dvd; struct idz_dll_config dll; struct zinput_config zinput; }; diff --git a/idzhook/dllmain.c b/idzhook/dllmain.c index fd15f09..8349800 100644 --- a/idzhook/dllmain.c +++ b/idzhook/dllmain.c @@ -8,7 +8,7 @@ #include "hook/process.h" -#include "hooklib/gfx.h" +#include "hooklib/dvd.h" #include "hooklib/serial.h" #include "hooklib/spike.h" @@ -39,6 +39,7 @@ static DWORD CALLBACK idz_pre_startup(void) serial_hook_init(); zinput_hook_init(&idz_hook_cfg.zinput); + dvd_hook_init(&idz_hook_cfg.dvd, idz_hook_mod); /* Initialize emulation hooks */ diff --git a/mu3hook/config.c b/mu3hook/config.c index 24086d8..0205a3f 100644 --- a/mu3hook/config.c +++ b/mu3hook/config.c @@ -4,6 +4,7 @@ #include "board/config.h" #include "hooklib/config.h" +#include "hooklib/dvd.h" #include "hooklib/gfx.h" #include "mu3hook/config.h" @@ -35,6 +36,7 @@ void mu3_hook_config_load( platform_config_load(&cfg->platform, filename); aime_config_load(&cfg->aime, filename); + dvd_config_load(&cfg->dvd, filename); gfx_config_load(&cfg->gfx, filename); mu3_dll_config_load(&cfg->dll, filename); } diff --git a/mu3hook/config.h b/mu3hook/config.h index 6b2afaa..1d31ec5 100644 --- a/mu3hook/config.h +++ b/mu3hook/config.h @@ -4,6 +4,7 @@ #include "board/config.h" +#include "hooklib/dvd.h" #include "hooklib/gfx.h" #include "mu3hook/mu3-dll.h" @@ -13,6 +14,7 @@ struct mu3_hook_config { struct platform_config platform; struct aime_config aime; + struct dvd_config dvd; struct gfx_config gfx; struct mu3_dll_config dll; }; diff --git a/mu3hook/dllmain.c b/mu3hook/dllmain.c index c7fe361..6d307de 100644 --- a/mu3hook/dllmain.c +++ b/mu3hook/dllmain.c @@ -8,6 +8,7 @@ #include "hook/process.h" +#include "hooklib/dvd.h" #include "hooklib/serial.h" #include "hooklib/spike.h" @@ -36,6 +37,7 @@ static DWORD CALLBACK mu3_pre_startup(void) /* Hook Win32 APIs */ + dvd_hook_init(&mu3_hook_cfg.dvd, mu3_hook_mod); gfx_hook_init(&mu3_hook_cfg.gfx, mu3_hook_mod); serial_hook_init();