c++ - DLL 注入(inject) : DrawText and TextOut doesn't return all text

标签 c++ dll-injection drawtext textout

我成功地将我的 DLL 注入(inject)到程序中。但是我想从 ListBox 中获取信息。 WM_GETTEXT 不工作所以我不得不做 dll 注入(inject)。我收到了大量文本,但从所需的控件中我什么也没有得到。

这是我的代码:

#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;
}

我的问题是:我是否遗漏了什么?我的意思是还有其他方法可以从应用程序中获取文本吗?因为在我进行研究时,这应该会为我提供程序中的所有文本。

非常感谢您的帮助!

最佳答案

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

关于c++ - DLL 注入(inject) : DrawText and TextOut doesn't return all text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12219061/

相关文章:

c++ - 窗口最大化

c++ - 在注入(inject)的 DLL 中调用函数

ffmpeg 移动文本 drawtext

FFmpeg 想将文本添加到 Xstack 马赛克

c++ - FindFirstFile 在根路径上失败

c++ - 在 CUDA 上需要有关 2D 纹理的帮助。没有得到我想要的索引的预期值

c++ - 远程进程的 WM_PAINT

c++ - std::shared_ptr 这个

c++ - 如何使用cub::DeviceReduce::ArgMin()

ios - UILabel 中的文本垂直放置在中间而不是从顶部 - 我如何在 Swift 中更改它?