diff --git a/board/bpreader.c b/board/bpreader.c index 27945e7..486c5fc 100644 --- a/board/bpreader.c +++ b/board/bpreader.c @@ -120,7 +120,7 @@ static HRESULT bp_handle_irp_locked(struct irp *irp) if (irp->op == IRP_OP_WRITE) { if (bp_uart.written.bytes[0] == 0x55) { - dprintf("Reader: Hello\n"); + dprintf("Reader: port opened\n"); bp_uart.written.pos = 0; // consume the written buffer } else if (bp_uart.written.bytes[3] == 0x00) { diff --git a/board/qr.c b/board/qr.c index 7af7c15..d4f5c18 100644 --- a/board/qr.c +++ b/board/qr.c @@ -195,4 +195,4 @@ static HRESULT qr_handle_irp_locked(struct irp* irp) qr_uart.written.pos = 0; return hr; -} \ No newline at end of file +} diff --git a/hooklib/path.c b/hooklib/path.c index 8bcb173..5b6b734 100644 --- a/hooklib/path.c +++ b/hooklib/path.c @@ -200,6 +200,23 @@ static UINT WINAPI hook_GetDriveTypeW( LPCWSTR lpRootPathName ); +static HFILE WINAPI hook_OpenFile( + LPCSTR lpFileName, + LPOFSTRUCT lpReOpenBuff, + UINT uStyle); + +static DWORD WINAPI hook_GetFullPathNameA( + LPCSTR lpFileName, + DWORD nBufferLength, + LPSTR lpBuffer, + LPSTR *lpFilePart); + +static DWORD WINAPI hook_GetFullPathNameW( + LPCWSTR lpFileName, + DWORD nBufferLength, + LPWSTR lpBuffer, + LPWSTR *lpFilePart); + /* Link pointers */ static BOOL (WINAPI *next_CreateDirectoryA)( @@ -395,6 +412,23 @@ static UINT (WINAPI *next_GetDriveTypeA)( LPCSTR lpRootPathName ); +static HFILE (WINAPI *next_OpenFile)( + LPCSTR lpFileName, + LPOFSTRUCT lpReOpenBuff, + UINT uStyle); + +static DWORD (WINAPI *next_GetFullPathNameA)( + LPCSTR lpFileName, + DWORD nBufferLength, + LPSTR lpBuffer, + LPSTR *lpFilePart); + +static DWORD (WINAPI *next_GetFullPathNameW)( + LPCWSTR lpFileName, + DWORD nBufferLength, + LPWSTR lpBuffer, + LPWSTR *lpFilePart); + /* Hook table */ static const struct hook_symbol path_hook_syms[] = { @@ -538,7 +572,19 @@ static const struct hook_symbol path_hook_syms[] = { .name = "GetDriveTypeW", .patch = hook_GetDriveTypeW, .link = (void **) &next_GetDriveTypeW, - } + }, { + .name = "OpenFile", + .patch = hook_OpenFile, + .link = (void **) &next_OpenFile, + }, { + .name = "GetFullPathNameA", + .patch = hook_GetFullPathNameA, + .link = (void **) &next_GetFullPathNameA, + }, { + .name = "GetFullPathNameW", + .patch = hook_GetFullPathNameW, + .link = (void **) &next_GetFullPathNameW, + }, }; static bool path_hook_initted; @@ -1886,4 +1932,83 @@ BOOL path_transform_args_w(const wchar_t* str, wchar_t delimiter, wchar_t* buf, free(copy); return !failed; -} \ No newline at end of file +} + +static HFILE WINAPI hook_OpenFile( + LPCSTR lpFileName, + LPOFSTRUCT lpReOpenBuff, + UINT uStyle) +{ + char *trans; + HFILE result; + BOOL ok; + + ok = path_transform_a(&trans, lpFileName); + + if (!ok) { + return HFILE_ERROR; + } + + result = next_OpenFile( + trans ? trans : lpFileName, + lpReOpenBuff, + uStyle); + + free(trans); + + return result; +} + +static DWORD WINAPI hook_GetFullPathNameA( + LPCSTR lpFileName, + DWORD nBufferLength, + LPSTR lpBuffer, + LPSTR *lpFilePart) +{ + char *trans; + DWORD result; + BOOL ok; + + ok = path_transform_a(&trans, lpFileName); + + if (!ok) { + return 0; + } + + result = next_GetFullPathNameA( + trans ? trans : lpFileName, + nBufferLength, + lpBuffer, + lpFilePart); + + free(trans); + + return result; +} + +static DWORD WINAPI hook_GetFullPathNameW( + LPCWSTR lpFileName, + DWORD nBufferLength, + LPWSTR lpBuffer, + LPWSTR *lpFilePart) +{ + wchar_t *trans; + DWORD result; + BOOL ok; + + ok = path_transform_w(&trans, lpFileName); + + if (!ok) { + return 0; + } + + result = next_GetFullPathNameW( + trans ? trans : lpFileName, + nBufferLength, + lpBuffer, + lpFilePart); + + free(trans); + + return result; +} diff --git a/platform/vfs.c b/platform/vfs.c index 83a7e19..34bad6d 100644 --- a/platform/vfs.c +++ b/platform/vfs.c @@ -299,8 +299,9 @@ HRESULT vfs_path_hook(const wchar_t *src, wchar_t *dest, size_t *count) assert(src != NULL); assert(count != NULL); - - if (src[0] == L'\0' || src[1] != L':' || !path_is_separator_w(src[2])) { + + // Allow null terminator, separators (\ or /), OR the wildcard (*) + if (src[0] == L'\0' || src[1] != L':' || (!path_is_separator_w(src[2]) && src[2] != L'*')) { return S_FALSE; } diff --git a/taikohook/amfw.c b/taikohook/amfw.c index 4a63f86..4ca4f88 100644 --- a/taikohook/amfw.c +++ b/taikohook/amfw.c @@ -7,6 +7,7 @@ #include "hook/iohook.h" #include "hooklib/dll.h" +#include "hooklib/reg.h" #include "hooklib/path.h" #include "hooklib/setupapi.h" #include "hooklib/serial.h" @@ -49,6 +50,14 @@ static const struct hook_symbol kernel32_syms[] = { } }; +static void dll_hook_insert_hooks(HMODULE target) { + hook_table_apply( + target, + "kernel32.dll", + kernel32_syms, + _countof(kernel32_syms)); +} + HRESULT amfw_hook_init() { HANDLE hMod; @@ -66,24 +75,17 @@ HRESULT amfw_hook_init() dprintf("AMFW: Found AMFrameWork Handle\n"); + dll_hook_insert_hooks(hMod); path_hook_insert_hooks(hMod); - setupapi_hook_insert_hooks(hMod); - proc_addr_insert_hooks(hMod); serial_hook_apply_hooks(hMod); iohook_apply_hooks(hMod); + reg_hook_apply_hooks(hMod); + proc_addr_insert_hooks(hMod); return S_OK; } -static void dll_hook_insert_hooks(HMODULE target) { - hook_table_apply( - target, - "kernel32.dll", - kernel32_syms, - _countof(kernel32_syms)); -} - static HMODULE WINAPI hook_LoadLibraryA(const char *name) { HMODULE result; diff --git a/taikohook/dllmain.c b/taikohook/dllmain.c index 05132c0..0dc4edb 100644 --- a/taikohook/dllmain.c +++ b/taikohook/dllmain.c @@ -33,10 +33,19 @@ static DWORD CALLBACK taiko_pre_startup(void) dprintf("--- Begin taiko_pre_startup ---\n"); + /* Load config */ + taiko_hook_config_load(&taiko_hook_cfg, L".\\bananatools.ini"); + /* Hook Win32 APIs */ + + gfx_hook_init(&taiko_hook_cfg.gfx); + gfx_d3d11_hook_init(&taiko_hook_cfg.gfx, taiko_hook_mod); + gfx_dxgi_hook_init(&taiko_hook_cfg.gfx, taiko_hook_mod); serial_hook_init(); + /* Initialize emulation hooks */ + struct dongle_info dinfo; dinfo.pid = 0x0C00; dinfo.vid = 0x0B9A; @@ -71,12 +80,6 @@ static DWORD CALLBACK taiko_pre_startup(void) ExitProcess(EXIT_FAILURE); } - hr = amfw_hook_init(); - - if (FAILED(hr)) { - ExitProcess(EXIT_FAILURE); - } - hr = amcus_hook_init(&taiko_hook_cfg.amcus); if (FAILED(hr)) { @@ -89,9 +92,16 @@ static DWORD CALLBACK taiko_pre_startup(void) ExitProcess(EXIT_FAILURE); } - gfx_hook_init(&taiko_hook_cfg.gfx); - gfx_d3d11_hook_init(&taiko_hook_cfg.gfx, taiko_hook_mod); - gfx_dxgi_hook_init(&taiko_hook_cfg.gfx, taiko_hook_mod); + /* Initialize native plugin DLL hooks + + There seems to be an issue with other DLL hooks if `LoadLibraryW` is + hooked earlier in the `taikohook` initialization. */ + + hr = amfw_hook_init(); + + if (FAILED(hr)) { + ExitProcess(EXIT_FAILURE); + } dprintf("--- End taiko_pre_startup ---\n");