From 6b1f49455906d1bd7724f2ced3f6f241f64be56f Mon Sep 17 00:00:00 2001 From: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Date: Mon, 25 May 2026 11:32:35 +0200 Subject: [PATCH] path: hook GetDiskFreeSpaceW for amGfetcher --- common/hooklib/path.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/common/hooklib/path.c b/common/hooklib/path.c index f480c63..0480e77 100644 --- a/common/hooklib/path.c +++ b/common/hooklib/path.c @@ -200,6 +200,14 @@ static UINT WINAPI hook_GetDriveTypeW( LPCWSTR lpRootPathName ); +static BOOL WINAPI hook_GetDiskFreeSpaceW( + LPCWSTR lpRootPathName, + LPDWORD lpSectorsPerCluster, + LPDWORD lpBytesPerSector, + LPDWORD lpNumberOfFreeClusters, + LPDWORD lpTotalNumberOfClusters +); + /* Link pointers */ static BOOL (WINAPI *next_CreateDirectoryA)( @@ -395,6 +403,14 @@ static UINT (WINAPI *next_GetDriveTypeA)( LPCSTR lpRootPathName ); +static BOOL (WINAPI *next_GetDiskFreeSpaceW)( + LPCWSTR lpRootPathName, + LPDWORD lpSectorsPerCluster, + LPDWORD lpBytesPerSector, + LPDWORD lpNumberOfFreeClusters, + LPDWORD lpTotalNumberOfClusters +); + /* Hook table */ static const struct hook_symbol path_hook_syms[] = { @@ -538,6 +554,10 @@ static const struct hook_symbol path_hook_syms[] = { .name = "GetDriveTypeW", .patch = hook_GetDriveTypeW, .link = (void **) &next_GetDriveTypeW, + }, { + .name = "GetDiskFreeSpaceW", + .patch = hook_GetDiskFreeSpaceW, + .link = (void **) &next_GetDiskFreeSpaceW, } }; @@ -1720,6 +1740,30 @@ static UINT WINAPI hook_GetDriveTypeW( return result; } +static BOOL WINAPI hook_GetDiskFreeSpaceW( + LPCWSTR lpRootPathName, + LPDWORD lpSectorsPerCluster, + LPDWORD lpBytesPerSector, + LPDWORD lpNumberOfFreeClusters, + LPDWORD lpTotalNumberOfClusters +) { + wchar_t *trans; + UINT result; + BOOL ok; + + ok = path_transform_w(&trans, lpRootPathName); + + if (!ok) { + return FALSE; + } + + result = next_GetDiskFreeSpaceW(trans ? trans : lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters); + + free(trans); + + return result; +} + char** str_split_a(char* a_str, const char a_delim) { char** result = 0; size_t count = 0;