为什么API在c++中挂钩extextout和DrawText只输出垃圾
Why does API hooking ExtTextOut and DrawText in C++ only output rubbish?
我正在尝试使用Detour从第三方程序提取文本输出的API钩子。然而,我只得到垃圾,大量的数字和没有文本输出。
这些函数到底在什么时候被调用?除了文字,他们还被要求画其他东西吗?如果第三方程序使用一些高级工具来避免拦截这些调用,是否有一些基本的示例,我可以尝试确保我的方法确实正确接收文本?换句话说,在窗口中是否有一些程序使用这些方法在屏幕上绘制文本?
我的代码如下:
BOOL (__stdcall *Real_ExtTextOut)(HDC hdc,int x, int y, UINT options, const RECT* lprc,LPCWSTR text,UINT cbCount, const INT* lpSpacingValues) = ExtTextOut;
BOOL (__stdcall *Real_DrawText)(HDC hdc, LPCWSTR text, int nCount, LPRECT lpRect, UINT uOptions) = DrawText;
int WINAPI Mine_DrawText(HDC hdc, LPCWSTR text, int nCount, LPRECT lpRect, UINT uOptions)
{
ofstream myFile;
myFile.open ("C:\temp\textHooking\textHook\example.txt", ios::app);
for(int i = 0; i < nCount; ++i)
myFile << text[i];
myFile << endl;
int rv = Real_DrawText(hdc, text, nCount, lpRect, uOptions);
return rv;
}
BOOL WINAPI Mine_ExtTextOut(HDC hdc, int X, int Y, UINT options, RECT* lprc, LPCWSTR text, UINT cbCount, INT* lpSpacingValues)
{
ofstream myFile;
myFile.open ("C:\temp\textHooking\textHook\example2.txt", ios::app);
for(int i = 0; i < cbCount; ++i)
myFile << text[i];
myFile << endl;
BOOL rv = Real_ExtTextOut(hdc, X, Y, options, lprc, text, cbCount, lpSpacingValues);
return rv;
}
// Install the DrawText detour whenever this DLL is loaded into any process
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved){
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)Real_ExtTextOut, Mine_ExtTextOut);
DetourAttach(&(PVOID&)Real_DrawText, Mine_DrawText);
DetourTransactionCommit();
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
您正在将UTF-16字符代码写成整数。因此,文件中充满了数字。直接将文本缓冲区移到文件中可能更简单:
ofstream myFile;
myFile.open("C:\temp\textHooking\textHook\example.txt", ios::app);
myFile.write(reinterpret_cast<const char*>text, nCount*sizeof(*text));
myFile << endl;
您可能希望将UTF-16LE BOM放在文件的前面,以帮助您的文本编辑器计算出正在使用的编码。
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- 将值从二维数组输出到文本文件
- 集合上的输出迭代器:assign和increment迭代器
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 为什么rk4.do_step不输出C++中的初始条件
- 输出没有重复元素的动态数组(收缩数组)C++
- 为什么API在c++中挂钩extextout和DrawText只输出垃圾