实现detours下钩子遇到的奇怪问题 我勾的是CreateFile,第一个进程载入钩子就能hook上,然后打开一个文件就能收到消息,第二个进程代码页差不多,咋就没东西了。。但是偶尔还是会有消息,奇怪了;比如我在桌面新建一个文件,第二个程序就能捕获到。但是如果打开,只有第一个可以了。我用冰刃看过了,两个应用程序都能勾上钩子。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 附:我直接在CreateFile中直接弹出MessageBox框,第二个程序就是不会弹出这个框,只能表示没有勾上了。但是第一个就行。而且我用的是同一个Dll 贴下代码: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的 iReadedCount如何定义的?是否定义在 #pragma data_seg 这个之间?如果这样的话就不对了你可以试试不用iReadedCount控制试试 我已经找到问题所在了,是字符类型的问题,要定义为UNICODE 奇怪,程序主窗口一直显示在最前端,怎么办呀! 字符串问题,急!!! mfc的工程中,用到了c语言编写的文件,如何调用呢 在这里有没有高手想过一同开发专案,创业打天下 小问题 函数onSize()的问题 CString的问题 微软既然能写一个VC编译器,想必反编译器忘不了写一个吧?! m_wndStatusBar.SetPaneText(m_wndStatus.CommandToIndex(ID_INDICATOR_CLOCK),s); direct3D高手请进(愿给100分) MFC绘图问题 工具栏上的按钮删错了
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的