I'm a student and just learned about hooking with MS Detours.
DESCRIPTION:
I wanted to replace some Windows functions for writing and changing text inside windows, titles etc. like a TextOutW()
function
The TextOut()
function writes a character string at the specified location, using the currently selected font, background color, and text color.
THE GOAL:
My goal is to hook new functions (like NewTextOutW()
) which are going to do the same thing, but they will translate the text in another language. The new functions have the same parameters like the original ones.
WHY MS DETOURS?
I have to use MS Detours because the traditional hooking with asm and overwriting the hot-patch header of an original function works just for the X86 version of the app but not for X64, so because the MS Detours is compatible with 32bit and 64bit apps, I want to use MS Detorus.
I want to do the hooking with function addresses, because I have the source code and I have addresses of the original and the new function saved in a BYTE*
type of variable.
CODE INFO:
This is my code which is going to attach a new function to the original one using the 2 adresses (BYTE* m_pOrigFunc
and BYTE* m_pDetourFunc
).
m_pOrigFunc
is an adress of the original function and the m_pDetourFunc
is the address of the function which is going to be attached to the original one. To detach the two functions I use the same code but except using the DetourAttach((PVOID*)&m_pOrigFunc, m_pDetourFunc)
i use the DetourDetach((PVOID*)&m_pOrigFunc, m_pDetourFunc)
statement.
CODE:
LONG err_cd = DetourTransactionBegin();
if (err_cd == NO_ERROR)
{
//err_cd = DetourUpdateThread(GetCurrentThread());
if (err_cd == NO_ERROR)
{
err_cd = DetourAttach((PVOID*)&m_pOrigFunc, m_pDetourFunc);
if (err_cd == NO_ERROR)
{
err_cd = DetourTransactionCommit();
if (err_cd == NO_ERROR)
::Trace(2, _T("MSDetours::DetourTransactionCommit: Detour erfolgreich."));
else
AbortAndTraceMSDetours("DetourTransactionCommit", err_cd);}
else
AbortAndTraceMSDetours("DetourAttach", err_cd);}
else
AbortAndTraceMSDetours("DetourUpdateThread", err_cd);}
else
AbortAndTraceMSDetours("DetourTransactionBegin", err_cd);
THE PROBLEM: After implementig this code I got an error in some other windows function (I thing for the creating a frame but I'm not sure) which you can see here. For the people who don't speak german, here is a text translation:
Unhandled exception at 0x6D0A00C8 in Konfig32.exe: 0xC000041D: unhandled exception was encountered during a user callback.
The error accures with or without commenting the line with err_cd = DetourUpdateThread(GetCurrentThread());
statement.
Can someone help me to find the soolution for this problem?
User contributions licensed under CC BY-SA 3.0