1
0
mirror of synced 2024-11-27 23:10:49 +01:00

path: add delete and move file hooks

This commit is contained in:
Kevin Trocolli 2023-12-10 18:47:17 -05:00
parent 5a130705d3
commit 9474da083d

View File

@ -97,6 +97,11 @@ static BOOL WINAPI hook_RemoveDirectoryA(const char *lpFileName);
static BOOL WINAPI hook_RemoveDirectoryW(const wchar_t *lpFileName); static BOOL WINAPI hook_RemoveDirectoryW(const wchar_t *lpFileName);
BOOL WINAPI hook_DeleteFileA(LPCSTR lpFileName);
BOOL WINAPI hook_DeleteFileW(LPWSTR lpFileName);
BOOL WINAPI hook_MoveFileA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName);
BOOL WINAPI hook_MoveFileW(LPWSTR lpFileName, LPWSTR lpNewFileName);
/* Link pointers */ /* Link pointers */
static BOOL (WINAPI *next_CreateDirectoryA)( static BOOL (WINAPI *next_CreateDirectoryA)(
@ -177,6 +182,11 @@ static BOOL (WINAPI *next_RemoveDirectoryA)(const char *lpFileName);
static BOOL (WINAPI *next_RemoveDirectoryW)(const wchar_t *lpFileName); static BOOL (WINAPI *next_RemoveDirectoryW)(const wchar_t *lpFileName);
BOOL (WINAPI *next_DeleteFileA)(LPCSTR lpFileName);
BOOL (WINAPI *next_DeleteFileW)(LPWSTR lpFileName);
BOOL (WINAPI *next_MoveFileA)(LPCSTR lpExistingFileName, LPCSTR lpNewFileName);
BOOL (WINAPI *next_MoveFileW)(LPWSTR lpFileName, LPWSTR lpNewFileName);
/* Hook table */ /* Hook table */
static const struct hook_symbol path_hook_syms[] = { static const struct hook_symbol path_hook_syms[] = {
@ -244,6 +254,22 @@ static const struct hook_symbol path_hook_syms[] = {
.name = "RemoveDirectoryW", .name = "RemoveDirectoryW",
.patch = hook_RemoveDirectoryW, .patch = hook_RemoveDirectoryW,
.link = (void **) &next_RemoveDirectoryW, .link = (void **) &next_RemoveDirectoryW,
}, {
.name = "DeleteFileA",
.patch = hook_DeleteFileA,
.link = (void **) &next_DeleteFileA,
}, {
.name = "DeleteFileW",
.patch = hook_DeleteFileW,
.link = (void **) &next_DeleteFileW,
}, {
.name = "MoveFileA",
.patch = hook_MoveFileA,
.link = (void **) &next_MoveFileA,
}, {
.name = "MoveFileW",
.patch = hook_MoveFileW,
.link = (void **) &next_MoveFileW,
} }
}; };
@ -854,3 +880,81 @@ static BOOL WINAPI hook_RemoveDirectoryW(const wchar_t *lpFileName)
return ok; return ok;
} }
BOOL WINAPI hook_DeleteFileA(LPCSTR lpFileName)
{
char *trans;
BOOL ok;
ok = path_transform_a(&trans, lpFileName);
if (!ok) {
return FALSE;
}
ok = next_DeleteFileA(trans ? trans : lpFileName);
free(trans);
return ok;
}
BOOL WINAPI hook_DeleteFileW(LPWSTR lpFileName)
{
wchar_t *trans;
BOOL ok;
ok = path_transform_w(&trans, lpFileName);
if (!ok) {
return FALSE;
}
ok = next_DeleteFileW(trans ? trans : lpFileName);
free(trans);
return ok;
}
BOOL WINAPI hook_MoveFileA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName)
{
char *trans1;
char *trans2;
BOOL ok;
ok = path_transform_a(&trans1, lpExistingFileName);
ok = path_transform_a(&trans2, lpNewFileName);
if (!ok) {
return FALSE;
}
ok = next_MoveFileA(trans1 ? trans1 : lpExistingFileName, trans2 ? trans2 : lpNewFileName);
free(trans1);
free(trans2);
return ok;
}
BOOL WINAPI hook_MoveFileW(LPWSTR lpExistingFileName, LPWSTR lpNewFileName)
{
wchar_t *trans1;
wchar_t *trans2;
BOOL ok;
ok = path_transform_w(&trans1, lpExistingFileName);
ok = path_transform_w(&trans2, lpNewFileName);
if (!ok) {
return FALSE;
}
ok = next_MoveFileW(trans1 ? trans1 : lpExistingFileName, trans2 ? trans2 : lpNewFileName);
free(trans1);
free(trans2);
return ok;
}