I'm trying to inject a dll into a software in order to detour it's ExtTextOut function. The injection and detouring works great (I'm using Microsoft Detours), but when I try to modify the ExtTextOut function, everything goes wrong.
Here is my code:
#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;
}
So as you can see in "Mine_ExtTextOut", I'm trying to replace every characters or strings displayed by "z". The result, though, when I try it on various software, looks like this:
So... why does ExtTextOut draws random characters instead of the letter "z" everywhere?
Ultimately, my goal is to be able to retrieve the text displayed and analyse it in order to know where it's displayed, but I figured starting by being able to modify how it's displayed would be a good start...