阻止文件保存,writefile问题
我使用detour,能够截获某特定文件的写入操作,代码如下:
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,"截获保存","成功",NULL);
res = Real_WriteFile( hFile,lpBuffer,nNumberOfBytesToWrite,lpNumberOfBytesWritten,lpOverlapped );
}
__finally
{};
return res;
}
假如我不想让该文件被写入,我可以将中间的res = Real_WriteFile( hFile,lpBuffer,nNumberOfBytesToWrite,lpNumberOfBytesWritten,lpOverlapped );这句注释了就可以,但是这样虽然达到了文件没有写入的目的,但是这样我的替换原有API的函数就没有去调用系统的原有API,是不是会造成堆栈不平衡?
我的想法是,能不能将writefilefile的相关参数我修改了以后,传给系统writefile api调用,比如lpBuffer,是需要被写入文件的数据的指针,我将他修改了再传给系统真实的writefile使用,但是试了以后效果不是太好,貌似他在重复的保存,不结束,我应该怎么做?