【问题标题】:DLL Injection: DrawText and TextOut doesn't return all textDLL 注入:DrawText 和 TextOut 不返回所有文本
【发布时间】:2012-08-31 16:12:43
【问题描述】:

我成功地将我的 DLL 注入到程序中。但是我想从 ListBox 中获取信息。 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 DLL\n"),  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 DLL\n"),  TEXT("Process Detach"), MB_ICONINFORMATION);
        DetourTransactionBegin(); 
        DetourUpdateThread(GetCurrentThread());
        DetourDetach(&(PVOID&)Real_DrawText, Mine_DrawText);
        DetourTransactionCommit();
        break;
    }

    return TRUE;
}

我的问题是:有什么我遗漏的吗?我的意思是还有其他方法可以从应用程序中获取文本吗?因为当我做研究时,这应该给我程序中的所有文本。

非常感谢您的帮助!

【问题讨论】:

  • 应用程序通过可访问性接口(MSAA、UI 自动化)以编程方式公开其内容。这些界面还将为您检索的文本提供更好的上下文。特定应用程序也可能具有自定义自动化模型。
  • 你能告诉我更多关于它的细节吗?我该如何实施来检索它们?
  • 这是一个很大的话题。我建议您阅读 MSDN 上 Active AccessibilityUI Automation 上的大量文档。

标签: c++ dll-injection drawtext textout


【解决方案1】:

你真正想做的是什么?您似乎想抓取在另一个程序中运行的列表框的内容。您是否尝试过简单地将LB_GETTEXT 消息发送到列表框?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-26
    • 2014-12-17
    • 2020-02-24
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 2018-05-19
    相关资源
    最近更新 更多