gpt4 book ai didi

c++ - Hook ExtTextOut 返回意外结果

转载 作者:太空狗 更新时间:2023-10-29 20:26:08 25 4
gpt4 key购买 nike

我试图将一个 dll 注入(inject)到软件中以绕过它的 ExtTextOut 函数。注入(inject)和绕行非常有效(我使用的是 Microsoft Detours),但是当我尝试修改 ExtTextOut 函数时,一切都出错了。

这是我的代码:

#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 等)。

您可能需要弄清楚如何从字形倒退到文本。

关于c++ - Hook ExtTextOut 返回意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21167718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com