Skip to content

Commit

Permalink
Fix two problems, little cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
spender-sandbox committed Feb 13, 2017
1 parent 7a986a3 commit 352d895
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cuckoomon.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static hook_t g_hooks[] = {
// Covered by NtCreateFile() but still grab this information
HOOK(kernel32, CopyFileA),
HOOK(kernel32, CopyFileW),
HOOK(kernel32, CopyFileExW),
HOOK_NOTAIL_ALT(kernel32, CopyFileExW, 6),

// Covered by NtSetInformationFile() but still grab this information
HOOK(kernel32, DeleteFileA),
Expand Down
38 changes: 28 additions & 10 deletions hook_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,8 @@ HOOKDEF_NOTAIL(WINAPI, MoveFileWithProgressW,
BOOL ret = TRUE;

if (lpProgressRoutine) {
wchar_t *path = malloc(32768 * sizeof(wchar_t));
ensure_absolute_unicode_path(path, lpExistingFileName);
LOQ_bool("filesystem", "uFh", "ExistingFileName", path,
LOQ_bool("filesystem", "FFh", "ExistingFileName", lpExistingFileName,
"NewFileName", lpNewFileName, "Flags", dwFlags);
free(path);
return 0;
}
return 1;
Expand Down Expand Up @@ -795,11 +792,8 @@ HOOKDEF_NOTAIL(WINAPI, MoveFileWithProgressTransactedW,
BOOL ret = TRUE;

if (lpProgressRoutine) {
wchar_t *path = malloc(32768 * sizeof(wchar_t));
ensure_absolute_unicode_path(path, lpExistingFileName);
LOQ_bool("filesystem", "uFh", "ExistingFileName", path,
LOQ_bool("filesystem", "FFh", "ExistingFileName", lpExistingFileName,
"NewFileName", lpNewFileName, "Flags", dwFlags);
free(path);
return 0;
}
return 1;
Expand Down Expand Up @@ -1014,7 +1008,31 @@ HOOKDEF(BOOL, WINAPI, CopyFileW,
return ret;
}

HOOKDEF(BOOL, WINAPI, CopyFileExW,
HOOKDEF_NOTAIL(WINAPI, CopyFileExW,
_In_ LPWSTR lpExistingFileName,
_In_ LPWSTR lpNewFileName,
_In_opt_ LPPROGRESS_ROUTINE lpProgressRoutine,
_In_opt_ LPVOID lpData,
_In_opt_ LPBOOL pbCancel,
_In_ DWORD dwCopyFlags
) {
BOOL ret = TRUE;
BOOL file_existed = FALSE;

if (GetFileAttributesW(lpNewFileName) != INVALID_FILE_ATTRIBUTES)
file_existed = TRUE;

if (lpProgressRoutine) {
LOQ_bool("filesystem", "FFis", "ExistingFileName", lpExistingFileName,
"NewFileName", lpNewFileName, "CopyFlags", dwCopyFlags, "ExistedBefore", file_existed ? "yes" : "no");
return 0;
}

return 1;
}


HOOKDEF_ALT(BOOL, WINAPI, CopyFileExW,
_In_ LPWSTR lpExistingFileName,
_In_ LPWSTR lpNewFileName,
_In_opt_ LPPROGRESS_ROUTINE lpProgressRoutine,
Expand All @@ -1030,7 +1048,7 @@ HOOKDEF(BOOL, WINAPI, CopyFileExW,
ret = Old_CopyFileExW(lpExistingFileName, lpNewFileName,
lpProgressRoutine, lpData, pbCancel, dwCopyFlags);
LOQ_bool("filesystem", "FFis", "ExistingFileName", lpExistingFileName,
"NewFileName", lpNewFileName, "CopyFlags", dwCopyFlags, file_existed ? "yes" : "no");
"NewFileName", lpNewFileName, "CopyFlags", dwCopyFlags, "ExistedBefore", file_existed ? "yes" : "no");

if (ret)
new_file_path_unicode(lpNewFileName);
Expand Down
11 changes: 10 additions & 1 deletion hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ extern HOOKDEF(BOOL, WINAPI, CopyFileW,
__in BOOL bFailIfExists
);

extern HOOKDEF(BOOL, WINAPI, CopyFileExW,
extern HOOKDEF_NOTAIL(WINAPI, CopyFileExW,
_In_ LPWSTR lpExistingFileName,
_In_ LPWSTR lpNewFileName,
_In_opt_ LPPROGRESS_ROUTINE lpProgressRoutine,
Expand All @@ -249,6 +249,15 @@ extern HOOKDEF(BOOL, WINAPI, CopyFileExW,
_In_ DWORD dwCopyFlags
);

extern HOOKDEF_ALT(BOOL, WINAPI, CopyFileExW,
_In_ LPWSTR lpExistingFileName,
_In_ LPWSTR lpNewFileName,
_In_opt_ LPPROGRESS_ROUTINE lpProgressRoutine,
_In_opt_ LPVOID lpData,
_In_opt_ LPBOOL pbCancel,
_In_ DWORD dwCopyFlags
);

extern HOOKDEF(BOOL, WINAPI, DeleteFileA,
__in LPCSTR lpFileName
);
Expand Down

0 comments on commit 352d895

Please sign in to comment.