0

I am stuck. For some reason, I need to block Copy feature of the file system on Windows 8. Till Windows 7, ShFileOperation & CopyFile used to do trick. However, with Windows 8, as I could scan through API monitor, a new API: CopyFile2, has been used to do the job. So I need to detour CopyFile2.

I tried doing this using Detour 2.x & 3.x along windows SDK 6.x, 7.x and Win8 SDK. Following is the code snippet -

HRESULT (WINAPI *Trampoline_CopyFile2)(PCWSTR pwszExistingFileName, PCWSTR pwszNewFileName, COPYFILE2_EXTENDED_PARAMETERS *pExtendedParameters) = CopyFile2;
HRESULT WINAPI Detour_CopyFile2(PCWSTR pwszExistingFileName, PCWSTR pwszNewFileName, COPYFILE2_EXTENDED_PARAMETERS *pExtendedParameters)
{
    OutputDebugString(L"Inside TrozenCopyFile...");
    return Trampoline_CopyFile2(pwszExistingFileName, pwszNewFileName, pExtendedParameters);
}

//Attaching Detour 
DetourAttach( &(PVOID&)Trampoline_CopyFile2, (PVOID)Detour_CopyFile2);

DetourAttach returns 0(Successful), but I do not receive call to my Trampoline function. I know my dll is getting loaded in Explorer because other APIs are getting detoured - and I have checked it in ProcessExplorer too.

Does microsoft Detour Library support win8 APIs? If yes, am I doing anything wrong? If No, shall I report this as a bug?

-- Further more, I create a sample application calls CopyFile2. My Dll is getting loaded and DetourAttach is returning 0. However, I am still unable to get traces to Detour_CopyFile2

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
VarunPandey
  • 327
  • 1
  • 12
  • 1
    The Pro version lists requirements as "Windows 7, Vista or XP SP3 " so it possibly doesn't support Win8 - best to ask MS directly. – Roger Rowland Apr 08 '13 at 06:11
  • 1
    Um, the user can still copy files by loading them into (for example) Notepad, then doing a "Save as". – Raymond Chen Apr 08 '13 at 06:29
  • Thanks Roger, for a quick reply. I think that's a good suggestion. I suspected the same. However, DetourAttach returns success, that confused me. What are your comments on that... – VarunPandey Apr 08 '13 at 08:07
  • Hey Raymond, thanks for replying. I agree, that we can copy them using "Save as" menu options. This might go out of context but I use sub-classing to monitor and disable such menu items. – VarunPandey Apr 08 '13 at 09:19

0 Answers0