hook api writefile的问题
一个文件权限的项目,需要防止某些文件的保存操作,准备采用hook winapi Writefile的方法,利用detours
BOOL _stdcall Replace_WriteFile(//替换系统的Writefile
HANDLE hFile, // handle to file to write to
LPCVOID lpBuffer, // pointer to data to write to file
DWORD nNumberOfBytesToWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
LPOVERLAPPED lpOverlapped // pointer to structure for overlapped I/O
)
{
BOOL res = NULL; //操作成功完成返回非零值
__try
{
MessageBox( NULL, "您没有修改权限", "拦截成功!", MB_OK );
}
__finally
{
};
return res;
}
但是有几个问题
1. word下就算使用类似findwindow的方法得到某个文件的窗口线程,如果同时又多个word打开,钩子还是会钩住所有的文件保存信息
2. word中的保存信息不像txt文件,往往点击了保存以后虽然能够拦截该保存消息,但是却造成messagebox弹出多次,可能是word中多次调用writefile操作,对此不是太了解
有没有有经验的兄弟能指点小弟一下啊,或者有什么更好的方法?