From 995305427dec1970075ed52bc4c33fe55e0e26d4 Mon Sep 17 00:00:00 2001 From: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com> Date: Fri, 24 Oct 2025 13:43:39 +0200 Subject: [PATCH] ekt: hook CopyFileA/W for enbu server --- common/hooklib/path.c | 97 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/common/hooklib/path.c b/common/hooklib/path.c index b47fe1f..458292e 100644 --- a/common/hooklib/path.c +++ b/common/hooklib/path.c @@ -110,6 +110,16 @@ static BOOL WINAPI hook_MoveFileW( const wchar_t *lpExistingFileName, const wchar_t *lpNewFileName); +static BOOL WINAPI hook_CopyFileA( + const char *lpExistingFileName, + const char *lpNewFileName, + BOOL bFailIfExists); + +static BOOL WINAPI hook_CopyFileW( + const wchar_t *lpExistingFileName, + const wchar_t *lpNewFileName, + BOOL bFailIfExists); + static BOOL WINAPI hook_MoveFileExA( const char *lpExistingFileName, const char *lpNewFileName, @@ -253,6 +263,16 @@ static BOOL (WINAPI *next_MoveFileW)( const wchar_t *lpExistingFileName, const wchar_t *lpNewFileName); +static BOOL (WINAPI *next_CopyFileA)( + const char *lpExistingFileName, + const char *lpNewFileName, + BOOL bFailIfExists); + +static BOOL (WINAPI *next_CopyFileW)( + const wchar_t *lpExistingFileName, + const wchar_t *lpNewFileName, + BOOL bFailIfExists); + static BOOL (WINAPI *next_MoveFileExA)( const char *lpExistingFileName, const char *lpNewFileName, @@ -386,6 +406,14 @@ static const struct hook_symbol path_hook_syms[] = { .name = "MoveFileW", .patch = hook_MoveFileW, .link = (void **) &next_MoveFileW, + }, { + .name = "CopyFileA", + .patch = hook_CopyFileA, + .link = (void **) &next_CopyFileA, + }, { + .name = "CopyFileW", + .patch = hook_CopyFileW, + .link = (void **) &next_CopyFileW, }, { .name = "MoveFileExA", .patch = hook_MoveFileExA, @@ -1135,6 +1163,75 @@ static BOOL WINAPI hook_MoveFileW( return ok; } + +static BOOL WINAPI hook_CopyFileA( + const char *lpExistingFileName, + const char *lpNewFileName, + BOOL bFailIfExists) +{ + char *oldTrans; + char *newTrans; + BOOL ok; + + ok = path_transform_a(&oldTrans, lpExistingFileName); + + if (!ok) { + return FALSE; + } + + ok = path_transform_a(&newTrans, lpNewFileName); + + if (!ok) { + free(oldTrans); + + return FALSE; + } + + ok = next_CopyFileA( + oldTrans ? oldTrans : lpExistingFileName, + newTrans ? newTrans : lpNewFileName, + bFailIfExists); + + free(oldTrans); + free(newTrans); + + return ok; +} + +static BOOL WINAPI hook_CopyFileW( + const wchar_t *lpExistingFileName, + const wchar_t *lpNewFileName, + BOOL bFailIfExists) +{ + wchar_t *oldTrans; + wchar_t *newTrans; + BOOL ok; + + ok = path_transform_w(&oldTrans, lpExistingFileName); + + if (!ok) { + return FALSE; + } + + ok = path_transform_w(&newTrans, lpNewFileName); + + if (!ok) { + free(oldTrans); + + return FALSE; + } + + ok = next_CopyFileW( + oldTrans ? oldTrans : lpExistingFileName, + newTrans ? newTrans : lpNewFileName, + bFailIfExists); + + free(oldTrans); + free(newTrans); + + return ok; +} + static BOOL WINAPI hook_MoveFileExA( const char *lpExistingFileName, const char *lpNewFileName,