DLL 注入:DrawText 和 TextOut 不会返回所有文本
DLL Injection: DrawText and TextOut doesn't return all text
我成功地将DLL注入程序中。但是,我想从列表框中获取信息。WM_GETTEXT不工作,所以我不得不进行dll注入。我收到了大量的文本,但从所需的控件中我一无所获。
这是我的代码:
#include <Windows.h>
#include "detours.h"
#include <tchar.h>
#include <stdio.h>
// Function pointer to the original (un-detoured) DrawText API
int (WINAPI * Real_DrawText)(HDC a0, LPCWSTR a1, int a2, LPRECT a3, UINT a4) = DrawTextW;
int (WINAPI * Real_TextOut)(HDC hdc, int nXStart, int nYStart, LPCTSTR lpString, int cchString) = TextOutW;
void writeToFile(LPCWSTR text)
{
FILE *out;
if (!(out = fopen("C:\OUTPUT\out.txt", "a+"))) {
MessageBox (0, TEXT("ERROR FILE"), TEXT("ERROR FILE"), MB_ICONINFORMATION);
return;
}
fwprintf(out, text);
fclose(out);
}
// Our custom version of DrawText
int WINAPI Mine_DrawText(HDC hdc, LPCWSTR text, int nCount, LPRECT lpRect, UINT uOptions)
{
int rv = Real_DrawText(hdc, text, nCount, lpRect, uOptions);
WideCharToMultiByte(CP_ACP, WC_DEFAULTCHAR, text, -1, txt, 0, NULL, NULL);
writeToFile(text);
return rv;
}
int WINAPI Mine_TextOut(HDC hdc, int nXStart, int nYStart, LPCTSTR lpString, int cchString) {
int rv = Real_TextOut(hdc, nXStart, nYStart, lpString, cchString);
writeToFile(lpString);
return rv;
}
// Install the DrawText detour whenever this DLL is loaded into any process...
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBox (0, TEXT("From DLLn"), TEXT("Process Attach"), MB_ICONINFORMATION);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)Real_DrawText, Mine_DrawText); // <- magic
DetourAttach(&(PVOID&)Real_TextOut, Mine_TextOut);
DetourTransactionCommit();
break;
case DLL_PROCESS_DETACH:
MessageBox (0, TEXT("From DLLn"), TEXT("Process Detach"), MB_ICONINFORMATION);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)Real_DrawText, Mine_DrawText);
DetourTransactionCommit();
break;
}
return TRUE;
}
我的问题是:有什么是我遗漏的吗?我的意思是,还有其他方法可以从应用程序中获取文本吗?因为当我做研究时,这应该会给我程序中的所有文本。
非常感谢你的帮助!
你真正想做什么?你似乎想抓取另一个程序中运行的列表框的内容。您是否尝试过简单地将LB_GETTEXT消息发送到列表框?
相关文章:
- 如何在C++中以这种方式返回一行文本?
- 返回从字符串文本创建的静态string_view是否安全?
- fscanf 在尝试返回文本文件的第一行时返回 -1
- 基于模板字符串文本返回的 c++ 函数指针
- std::string::find 为取消引用的迭代器和等效字符串文本返回不同的值
- 我想读取文本文件中的所有内容(但文本文件中只有一个双精度值),转换为双精度值并返回值
- FindResource 调用返回 RCDATA 类型的文本文件的 NULL
- 我的代码一直返回0作为文本文件中的小数数
- 函数读取最大和min int值,并用文本字符串返回
- 问题 - 递归函数以返回文本文件排列
- C++程序不返回文件中文本和字符串数据的值
- 搜索文本文件并返回等号后的值
- 任何人都知道如何解决尝试将从MySQL数据库返回的行打印到文本文件(.txt)中的C++
- 有没有更好的方法可以从静态和非静态函数返回相同的字符串文本
- 使用关键字从文本文件返回数字
- 使用 sqlite3 和 C++ 绑定和返回文本数据
- 给定一个单词和一个文本,返回文本中单词字谜的出现次数
- PInvoke:从c++返回文本到c#时出错
- 通过引用和内联返回文本
- c++检查int或char并返回文本