From 0be4b4744828d6435e79f2d9e2e8ac40052bf383 Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Wed, 24 Dec 2025 14:26:46 +0100 Subject: [PATCH] misc: add GetDriveType hook --- common/hooklib/path.c | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/common/hooklib/path.c b/common/hooklib/path.c index b47fe1f..a88d5f9 100644 --- a/common/hooklib/path.c +++ b/common/hooklib/path.c @@ -161,6 +161,14 @@ static DWORD WINAPI hook_GetPrivateProfileSectionW( LPCWSTR lpFileName ); +static UINT WINAPI hook_GetDriveTypeA( + LPCSTR lpRootPathName +); + +static UINT WINAPI hook_GetDriveTypeW( + LPCWSTR lpRootPathName +); + /* Link pointers */ static BOOL (WINAPI *next_CreateDirectoryA)( @@ -303,6 +311,14 @@ static DWORD (WINAPI *next_GetPrivateProfileSectionW)( LPCWSTR lpFileName ); +static UINT (WINAPI *next_GetDriveTypeW)( + LPCWSTR lpRootPathName +); + +static UINT (WINAPI *next_GetDriveTypeA)( + LPCSTR lpRootPathName +); + /* Hook table */ static const struct hook_symbol path_hook_syms[] = { @@ -418,6 +434,14 @@ static const struct hook_symbol path_hook_syms[] = { .name = "GetPrivateProfileSectionW", .patch = hook_GetPrivateProfileSectionW, .link = (void **) &next_GetPrivateProfileSectionW, + }, { + .name = "GetDriveTypeA", + .patch = hook_GetDriveTypeA, + .link = (void **) &next_GetDriveTypeA, + }, { + .name = "GetDriveTypeW", + .patch = hook_GetDriveTypeW, + .link = (void **) &next_GetDriveTypeW, } }; @@ -1338,3 +1362,35 @@ static DWORD WINAPI hook_GetPrivateProfileSectionW( return next_GetPrivateProfileSectionW(lpAppName, lpReturnedString, nSize, trans ? trans: lpFileName); } + + +static UINT WINAPI hook_GetDriveTypeA( + LPCSTR lpRootPathName +) { + char *trans; + BOOL ok; + + ok = path_transform_a(&trans, lpRootPathName); + + if (!ok) { + return FALSE; + } + + return next_GetDriveTypeA(trans ? trans : lpRootPathName); +} + + +static UINT WINAPI hook_GetDriveTypeW( + LPCWSTR lpRootPathName +) { + wchar_t *trans; + BOOL ok; + + ok = path_transform_w(&trans, lpRootPathName); + + if (!ok) { + return FALSE; + } + + return next_GetDriveTypeW(trans ? trans : lpRootPathName); +}