关于c ++:挂钩ExtTextOut返回意外的结果

Hooking ExtTextOut returns unexpected results

我试图将dll注入软件中,以绕过它的ExtTextOut函数。 注入和绕行效果很好(我正在使用Microsoft Detours),但是当我尝试修改ExtTextOut函数时,一切都会出错。

这是我的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma comment(lib,"detours.lib")

#include <Windows.h>
#include <detours.h>
#include <tchar.h>

BOOL (WINAPI * Real_ExtTextOutW)(HDC hdc, int x, int y, UINT fuOptions, const RECT *lprc, LPCWSTR lpString, UINT cbCount, const INT *lpDx) = ExtTextOutW;

BOOL WINAPI Mine_ExtTextOutW(HDC hdc, int x, int y, UINT fuOptions, const RECT *lprc, LPCWSTR lpString, UINT cbCount, const INT *lpDx)
{
    // The expected results would be that every characters displayed become"z"
    return Real_ExtTextOutW(hdc, x, y, fuOptions, lprc, L"z", 1, lpDx);
}

BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved  )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:

        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());

        DetourAttach(&(PVOID&)Real_ExtTextOutW, Mine_ExtTextOutW);
        DetourAttach(&(PVOID&)Real_DrawTextW, Mine_DrawTextW);

        DetourTransactionCommit();
        break;

    case DLL_PROCESS_DETACH:

        DetourTransactionBegin();
        DetourUpdateThread(GetCurrentThread());

        DetourDetach(&(PVOID&)Real_ExtTextOutW, Mine_ExtTextOutW);
        DetourDetach(&(PVOID&)Real_DrawTextW, Mine_DrawTextW);

        DetourTransactionCommit();
        break;
    }

    return TRUE;
}

因此,正如您在" Mine_ExtTextOut"中看到的那样,我正在尝试替换由" z"显示的每个字符或字符串。 但是,当我在各种软件上尝试时,结果如下所示:

http://imgur.com/DI9o3GM (I do not have enough reputation to post image...)

那么...为什么ExtTextOut会在各处绘制随机字符而不是字母" z"?

最终,我的目标是能够检索显示的文本并进行分析以了解其显示位置,但是我认为从能够修改其显示方式开始是一个不错的开始...


检查ExtTextOut调用上的选项。 如果它们包含ETO_GLYPH_INDEX,则该函数期望字形索引(进入字体)而不是实际的(Unicode)文本。 可能只是" z"(172)恰好是该字体中"ò"的索引。

大多数文本绘图功能最终都由Uniscribe处理并翻译("定型")为一系列字形,然后使用ExtTextOutETO_GLYPH_INDEX选项将其转换为设备上下文。

我怀疑如果绕道TextOutDrawText,您会看到更多希望看到的内容。 但这只是一个猜测。 有很多功能可以绘制文本(DrawTextExPolyTextOut,以及DirectWrite / Direct2D API等)。

您可能必须弄清楚如何从字形向后退到文本。