我勾的是CreateFile,第一个进程载入钩子就能hook上,然后打开一个文件就能收到消息,第二个进程代码页差不多,咋就没东西了。。但是偶尔还是会有消息,奇怪了;比如我在桌面新建一个文件,第二个程序就能捕获到。但是如果打开,只有第一个可以了。我用冰刃看过了,两个应用程序都能勾上钩子。

解决方案 »

  1.   

    附:我直接在CreateFile中直接弹出MessageBox框,第二个程序就是不会弹出这个框,只能表示没有勾上了。但是第一个就行。而且我用的是同一个Dll
      

  2.   

    贴下代码:HANDLE WINAPI MyCreateFileW(LPCTSTR lpFileName,                         // file name
       DWORD dwDesiredAccess,                      // access mode
       DWORD dwShareMode,                          // share mode
       LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
       DWORD dwCreationDisposition,                // how to create
       DWORD dwFlagsAndAttributes,                 // file attributes
       HANDLE hTemplateFile  )                      // handle to template file
    {
    // if(_tcsstr(processName,_T("NetMonitor.exe")) == NULL)
    // {
    //  if(dwCreationDisposition == OPEN_ALWAYS || dwCreationDisposition == OPEN_EXISTING)
    //  {
    if(iReadedCount == 0)
    {

    TCHAR szFileType[5];
    GetFromFileNameToType(szFileType,lpFileName);
    PutDbgStr(_T("%s"),lpFileName);
    if(_tcsicmp(szFileType,_T("doc")) == 0 || _tcsicmp(szFileType,_T("xls")) == 0 || _tcsicmp(szFileType,_T("ppt")) == 0
    || _tcsicmp(szFileType,_T("pdf")) == 0 || _tcsicmp(szFileType,_T("txt")) == 0)
    {
    MessageBox(NULL,lpFileName,processName,MB_OK);
    int iActionId = FILEACTION_MSG_OPEN;
    SendFileMessageA(lpFileName,&iActionId);
    ++iReadedCount;
    }
    }
    //  }
    // }
    HANDLE hRet = Real_CreateFileW(lpFileName,dwDesiredAccess,dwShareMode,lpSecurityAttributes,dwCreationDisposition,
         dwFlagsAndAttributes,hTemplateFile);
    return hRet;
    }BOOL SetAPIHook(HWND hwnd)
    {
    g_hMain = hwnd;
    g_MessageHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC) MessageProc, (HINSTANCE)hInst, 0);

    if (g_MessageHook != NULL)
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    //在界面程序上调用dll,两个界面都是一样的写法
    if (hModule != NULL)
    {
    typedef BOOL (*pProc)(HWND);
    pProc SetAPIHook = (pProc) GetProcAddress(hModule, "SetAPIHook");
    if (SetAPIHook != NULL)
    {
    SetAPIHook(CWnd::m_hWnd);
    }
    }
    else
    MessageBox(_T("文件监控模块丢失!"));
    第二个进程运行的时候,那个Messagebox都不会弹出来。iReadedCount设为dll内的全局变量,对于每个进程来说第一次调用这个实例的时候应该是为0的
      

  3.   

    iReadedCount如何定义的?是否定义在 #pragma data_seg 这个之间?如果这样的话就不对了你可以试试不用iReadedCount控制试试
      

  4.   

    我已经找到问题所在了,是字符类型的问题,要定义为UNICODE