我用微軟的detours攔截gdipdrawstring函式,但是不成功。
查了兩天不知道什么原因,哪位高手指點一下。
被攔截的代碼:
private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
HDC hdc = (HDC)(e->Graphics->GetHdc().ToInt32());
Graphics graphics(hdc);
//printf("test messaged");
// Create a string.
WCHAR string[] = L"Sample Text";
// Initialize arguments.
FontFamily fontFamily(L"Arial");
Gdiplus::Font myFont(&fontFamily, 12, FontStyleBold, UnitPoint);
RectF layoutRect(0.0f, 0.0f, 200.0f, 50.0f);
StringFormat format;
format.SetAlignment(StringAlignmentCenter);
SolidBrush blackBrush(Color(255, 0, 0, 0));
GdipDrawString(
(&graphics) -> nativeGraphics,
string,
11,
(&myFont) -> nativeFont,
&layoutRect,
(&format) -> nativeFormat,
(&blackBrush) -> nativeBrush
);
}
函式指標的宣告:
static GpStatus (WINGDIPAPI* InterDS)(GpGraphics *graphics, GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font, GDIPCONST RectF *layoutRect, GDIPCONST GpStringFormat *stringFormat, GDIPCONST GpBrush *brush) = GdipDrawString;
攔截后執行的方法:
GpStatus WINGDIPAPI DrawStringEx(GpGraphics *graphics, GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font, GDIPCONST RectF *layoutRect, GDIPCONST GpStringFormat *stringFormat, GDIPCONST GpBrush *brush)
{
MessageBox( NULL, L"DrawStringEx", L"debug info", MB_OK);
WCHAR changedstr[] = L"changed";
Gdiplus::GpStatus ret = InterDS(graphics, changedstr, length, font, layoutRect, stringFormat, brush);
return ret;
}
掛接目標API:
if (dwReason == DLL_PROCESS_ATTACH) {
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)InterDS, DrawStringEx);
DetourTransactionCommit();
}
uj5u.com熱心網友回復:
了解不多,不過,看代碼DetourAttach(&(PVOID&)InterDS, DrawStringEx);你要攔截的是InterDS,
你是不是應該攔截GdipDrawString??
uj5u.com熱心網友回復:
謝謝回復。
InterDS是GdipDrawString的函式指標,我用同樣的方式攔截Sleep是可以成功的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/147940.html
標籤:基礎類
