Hooking ReadFile WinAPI
Hooking ReadFile WinAPI
Im使用mhook C++lib来挂接WinAPI。我有个问题。。这是一个挂钩函数:
BOOL WINAPI HookedReadFile(
_In_ HANDLE hFile,
_Out_ LPVOID lpBuffer,
_In_ DWORD nNumberOfBytesToRead,
_Out_opt_ LPDWORD lpNumberOfBytesRead,
_Inout_opt_ LPOVERLAPPED lpOverlapped)
{
if (inWork && hFile == CryptedFileHandle)
{
DWORD readedCount = 0;
DWORD toReadCount = nNumberOfBytesToRead;
LPBYTE Buf = new BYTE[toReadCount];
BOOL result = OriginalReadFile(hFile, Buf, toReadCount, &readedCount, NULL);
if (result && readedCount > 0)
{
// decryption routine will be here
std::copy(Buf, Buf + readedCount, (LPBYTE)lpBuffer);
}
lpNumberOfBytesRead = &readedCount;
delete[] Buf;
return result;
} else
return OriginalReadFile(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped);
}
这一定很简单。如果它的加密文件应用程序将即时解密字节(简单的xor)。
但它不起作用。我认为问题出在std::copy(Buf, Buf + readedCount, (LPBYTE)lpBuffer);
中,因为程序无法正常读取此文件。
这里有一个主要问题:
pNumberOfBytesRead = &readedCount;
在这里,使pNumberOfBytesRead
指向局部变量readedCount
。除了试图"返回"指向局部变量的指针(在下一个大括号处超出范围)的问题外,您还忘记了参数,甚至指针,都是按值传递的,所以您只更改pNumberOfBytesRead
的本地副本。
相反,您应该使用解引用运算符*
并将其指定为值
*pNumberOfBytesRead = readedCount;
至于std::copy
调用,它看起来是合法的。也许你有什么问题是在某些代码中你没有向我们展示?您是否尝试过在调试器中逐步执行代码?
相关文章:
- WinAPI挂钩鼠标
- 将执行、作业和WinAPI相乘
- 如何在桌面C++上使用 WinApi 画线
- WINAPI 注册应用程序重新启动时不清除打开的套接字
- Winapi:屏幕截图未显示在窗口中
- WinAPI 在单击第一个对话框上的按钮控件并销毁第一个对话框后创建第二个对话框
- Qt with WinAPI MouseProc
- 如何在"SUBSYSTEM:WINDOWS"下显示并输出到Windows(C++ WinApi)上的
- WinAPI 无法创建按钮
- 将 Win32/WinAPI 应用程序移植到 wxWidgets
- WinAPI 检查窗口是否具有常规标题栏
- 如何使用带有矢量的 winapi 读取进程内存从另一个进程读取缓冲区?
- 将Qt集成到现有的VS项目中以取代WinAPI
- __stdcall - WINAPI vs STDMETHODCALLTYPE vs APIENTRY
- 如何将'this'指针传递给C++ WinAPI 线程?
- Winapi-WM_CLOSE的替代方案
- Winapi ReadFile返回损坏的数据
- 使用 ReadFile WinAPI 读取'Binary'文件
- ReadFile winapi在从虚拟盒共享文件夹读取时失败.GetLastError正在引发错误183
- Hooking ReadFile WinAPI