From 008d53dd458996e77630e483ae4c22ba0add4598 Mon Sep 17 00:00:00 2001 From: Matt Bilker Date: Mon, 18 May 2020 23:03:25 +0000 Subject: [PATCH] hooklib/path.c: hook Ex variants of CreateDirectory --- hooklib/path.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/hooklib/path.c b/hooklib/path.c index 0d86183c..6d27efc2 100644 --- a/hooklib/path.c +++ b/hooklib/path.c @@ -27,6 +27,16 @@ static BOOL WINAPI hook_CreateDirectoryW( const wchar_t *lpFileName, SECURITY_ATTRIBUTES *lpSecurityAttributes); +static BOOL WINAPI hook_CreateDirectoryExA( + const char *lpTemplateDirectory, + const char *lpNewDirectory, + SECURITY_ATTRIBUTES *lpSecurityAttributes); + +static BOOL WINAPI hook_CreateDirectoryExW( + const wchar_t *lpTemplateDirectory, + const wchar_t *lpNewDirectory, + SECURITY_ATTRIBUTES *lpSecurityAttributes); + static HANDLE WINAPI hook_CreateFileA( const char *lpFileName, uint32_t dwDesiredAccess, @@ -93,6 +103,16 @@ static BOOL (WINAPI *next_CreateDirectoryW)( const wchar_t *lpFileName, SECURITY_ATTRIBUTES *lpSecurityAttributes); +static BOOL (WINAPI *next_CreateDirectoryExA)( + const char *lpTemplateDirectory, + const char *lpNewDirectory, + SECURITY_ATTRIBUTES *lpSecurityAttributes); + +static BOOL (WINAPI *next_CreateDirectoryExW)( + const wchar_t *lpTemplateDirectory, + const wchar_t *lpNewDirectory, + SECURITY_ATTRIBUTES *lpSecurityAttributes); + static HANDLE (WINAPI *next_CreateFileA)( const char *lpFileName, uint32_t dwDesiredAccess, @@ -160,6 +180,14 @@ static const struct hook_symbol path_hook_syms[] = { .name = "CreateDirectoryW", .patch = hook_CreateDirectoryW, .link = (void **) &next_CreateDirectoryW, + }, { + .name = "CreateDirectoryExA", + .patch = hook_CreateDirectoryExA, + .link = (void **) &next_CreateDirectoryExA, + }, { + .name = "CreateDirectoryExW", + .patch = hook_CreateDirectoryExW, + .link = (void **) &next_CreateDirectoryExW, }, { .name = "CreateFileA", .patch = hook_CreateFileA, @@ -470,6 +498,54 @@ static BOOL WINAPI hook_CreateDirectoryW( return ok; } +static BOOL WINAPI hook_CreateDirectoryExA( + const char *lpTemplateDirectory, + const char *lpNewDirectory, + SECURITY_ATTRIBUTES *lpSecurityAttributes) +{ + char *trans; + BOOL ok; + + ok = path_transform_a(&trans, lpNewDirectory); + + if (!ok) { + return FALSE; + } + + ok = next_CreateDirectoryExA( + lpTemplateDirectory, + trans ? trans : lpNewDirectory, + lpSecurityAttributes); + + free(trans); + + return ok; +} + +static BOOL WINAPI hook_CreateDirectoryExW( + const wchar_t *lpTemplateDirectory, + const wchar_t *lpNewDirectory, + SECURITY_ATTRIBUTES *lpSecurityAttributes) +{ + wchar_t *trans; + BOOL ok; + + ok = path_transform_w(&trans, lpNewDirectory); + + if (!ok) { + return FALSE; + } + + ok = next_CreateDirectoryExW( + lpTemplateDirectory, + trans ? trans : lpNewDirectory, + lpSecurityAttributes); + + free(trans); + + return ok; +} + /* Don't pull in the entire iohook framework just for CreateFileA/CreateFileW */ static HANDLE WINAPI hook_CreateFileA(