使用detours做了一个监控文件系统操作的程序.遇到些小问题."新建""打开"操作什么的都没问题.唯独"读""写"操作有问题.感觉函数构造应该差不多啊.怎么会有这么大差别.
先附上成功的api的代码
HANDLE WINAPI NEW_CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, 
DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition, DWORD dwFlagAndAttributes, HANDLE hTemplateFile)
{
if(lpFileName != "C:\\dlllog.log"){
switch(dwCreationDisposition){
case CREATE_ALWAYS:;
case CREATE_NEW:;
case OPEN_ALWAYS:AppendMessageToLog("创建新文件:","C:\\dlllog.log");
 AppendMessageToLog((char *)lpFileName,"C:\\dlllog.log");
 break;
case OPEN_EXISTING:;
case TRUNCATE_EXISTING:AppendMessageToLog("打开文件:","C:\\dlllog.log");
   AppendMessageToLog((char *)lpFileName,"C:\\dlllog.log");
   break;
}
}
HANDLE ret = OLD_CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagAndAttributes, hTemplateFile);
//MessageBoxW(NULL,lpFileName,L"[测试]",MB_OK);
return ret;
}
有问题的函数如下
BOOL WINAPI NEW_WriteFile(HANDLE hFile,LPCVOID lpBuffer,DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten,LPOVERLAPPED lpOverlapped)
{
AppendWMessageToLog(L"修改文件:",L"C:\\dlllog.log");
AppendWMessageToLog((wchar_t *)hFile,L"C:\\dlllog.log");
BOOL ret=OLD_WriteFile(hFile,lpBuffer,nNumberOfBytesToWrite,lpNumberOfBytesWritten,lpOverlapped);
return ret;
}
当把上面这个函数加入后,就不正常了..apiwindow文件系统

解决方案 »

  1.   

    你说的不正常指的是怎么意思?程序异常?HOOK不了?
      

  2.   

    就是得先生成个dll,然后注入到进程里么不是..编写好了自定义的函数,然后加上DetourAttach(&(PVOID&)OLD_WriteFile,NEW_WriteFile);
    DetourAttach(&(PVOID&)OLD_ReadFile,NEW_ReadFile);这两行之后,生成的dll再注入到进程里的时候,就不能记录结果了...不加这个的时候就是可以记录的...不知道是不是这个NEW_WriteFile写的有问题啊还是哪里出了问题...求大牛帮忙分析..
      

  3.   

    哥们儿,能不能帮我看下,detours的simple样例,为什么记录不了sleep的时间差呢?
    http://bbs.csdn.net/topics/390548195
      

  4.   

    AppendWMessageToLog((wchar_t *)hFile,L"C:\\dlllog.log"); ??