Home > Software engineering >  Hook gdipdrawstring function is not successful
Hook gdipdrawstring function is not successful

Time:10-31

I use Microsoft detours to intercept gdipdrawstring function, but is not successful,
Check two days don't know what the reason, which ace to give directions,

Intercepted code:
Private: System: : Void Form1_Paint (System: : Object ^ sender, System: : Windows: : Forms: : PaintEventArgs ^ e) {
HDC HDC=(HDC) (e - & gt; Graphics - & gt; GetHdc (.) ToInt32 ());

Graphics Graphics (HDC);
//printf (" test messaged ");
//Create a string.
WCHAR string []=L "Sample Text".

//Initialize the arguments.
FontFamily FontFamily (L "Arial");
Gdiplus: : the Font myFont (& amp; FontFamily, 12, FontStyleBold UnitPoint);

RectF layoutRect (0.0 f, f, 0.0 200.0 f, 50.0 f);
StringFormat format;
Format. SetAlignment (StringAlignmentCenter);
SolidBrush blackBrush (Color (255, 0, 0, 0));

GdipDrawString (
(& amp; Graphics - & gt; NativeGraphics,
String,
11,
(& amp; MyFont) - & gt; NativeFont,
& LayoutRect,
(& amp; The format) - & gt; NativeFormat,
(& amp; BlackBrush) - & gt; NativeBrush
);
}
A function pointer statement:
The static GpStatus (WINGDIPAPI * InterDS) (GpGraphics * graphics, GDIPCONST WCHAR * string, INT length, GDIPCONST GpFont * the font, GDIPCONST RectF * layoutRect, GDIPCONST GpStringFormat * stringFormat, GDIPCONST GpBrush * brush)=GdipDrawString;

The method of intercepting executed after:
GpStatus WINGDIPAPI DrawStringEx (GpGraphics * graphics, GDIPCONST WCHAR * string, INT length, GDIPCONST GpFont * the font, GDIPCONST RectF * layoutRect, GDIPCONST GpStringFormat * stringFormat, GDIPCONST GpBrush * brush)
{
MessageBox (NULL, "DrawStringEx" L, L "debug info", MB_OK);
WCHAR changedstr []=L "changed";
Gdiplus: : GpStatus ret=InterDS (graphics, changedstr, length, the font, layoutRect stringFormat, brush);
Return ret.
}

Articulated target API:
If (dwReason==DLL_PROCESS_ATTACH) {
DetourRestoreAfterWith ();
DetourTransactionBegin ();
DetourUpdateThread (GetCurrentThread ());
DetourAttach (& amp; (PVOID&) InterDS DrawStringEx);
DetourTransactionCommit ();
}

CodePudding user response:

Don't know much, but, see code DetourAttach (& amp; (PVOID&) InterDS DrawStringEx);
You want to intercept is InterDS,
You should intercept GdipDrawString??

CodePudding user response:

reference
don't know much, but look at the code DetourAttach (& amp; (PVOID&) InterDS DrawStringEx);
You want to intercept is InterDS,
You should intercept GdipDrawString??

Thank you for your reply,
InterDS is GdipDrawString function Pointers, I intercept Sleep in the same way can be successful,
  • Related