阻止文件保存,writefile问题

lilingjing lilingjing 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我使用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使用,但是试了以后效果不是太好,貌似他在重复的保存,不结束,我应该怎么做?
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
lilingjing
VC/MFC 16,551 成员 421,605 内容