hooklib/path.c: hook Ex variants of CreateDirectory

This commit is contained in:
Felix Anderson 2020-05-18 23:03:25 +00:00
parent bd1e893b7a
commit eef0f74ac0

View File

@ -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(