detours捕获了SleepEx、DrawText,却捕获不了TextOut

hhhcj 2013-08-16 03:01:02
我没辙了,不要怪我问得模糊,这问题实在太奇怪了,代码都一样,我认为没有半点问题。TextOutA和TextOutW都试过了,挂上没反应。
附DLL源代码如下:
//////////////////////////////////////////////////////////////////////////////
//
// Detours Test Program (simple.cpp of simple.dll)
//
// Microsoft Research Detours Package, Version 3.0.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This DLL will detour the Windows SleepEx API so that TimedSleep function
// gets called instead. TimedSleepEx records the before and after times, and
// calls the real SleepEx API through the TrueSleepEx function pointer.
//
#include <stdio.h>
#include <windows.h>
#include <atlstr.h>
#include "detours.h"

static LONG dwSlept = 0;
static CString flag="wrong";
static DWORD (WINAPI * TrueSleepEx)(DWORD dwMilliseconds, BOOL bAlertable) = SleepEx;
static BOOL (WINAPI* TrueTextOut)(HDC hdc,int nXStart,int nYStart,LPCWSTR lpString,int cchString)=TextOut;
static int (WINAPI* TrueDrawText)(HDC hdc,LPCTSTR lpchText,int nCount,LPRECT lpRect,UINT uFormat)=DrawText;

DWORD WINAPI TimedSleepEx(DWORD dwMilliseconds, BOOL bAlertable)
{
DWORD dwBeg = GetTickCount();
DWORD ret = TrueSleepEx(dwMilliseconds, bAlertable);
DWORD dwEnd = GetTickCount();

InterlockedExchangeAdd(&dwSlept, dwEnd - dwBeg);
flag="right";

return ret;
}

BOOL WINAPI SaveTextOut(HDC hdc,int nXStart,int nYStart,LPCWSTR lpString,int cchString){
BOOL b= TrueTextOut(hdc,nXStart,nYStart,lpString,cchString);
flag="right+wrong";

return b;
}

int WINAPI NewDrawText(HDC hdc,LPCTSTR lpchText,int nCount,LPRECT lpRect,UINT uFormat){
int b=TrueDrawText(hdc,lpchText,nCount,lpRect,uFormat);
flag="right 3";

return b;
}

BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
LONG error;
(void)hinst;
(void)reserved;

if (DetourIsHelperProcess()) {
return TRUE;
}

if (dwReason == DLL_PROCESS_ATTACH) {
DetourRestoreAfterWith();

printf("simple" DETOURS_STRINGIFY(DETOURS_BITS) ".dll:"
" Starting.\n");
fflush(stdout);

DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)TrueSleepEx, TimedSleepEx);
DetourAttach(&(PVOID&)TrueTextOut,SaveTextOut);
DetourAttach(&(PVOID&)TrueDrawText,NewDrawText);
error = DetourTransactionCommit();

if (error == NO_ERROR) {
printf("simple" DETOURS_STRINGIFY(DETOURS_BITS) ".dll:"
" Detoured SleepEx().\n");
}
else {
printf("simple" DETOURS_STRINGIFY(DETOURS_BITS) ".dll:"
" Error detouring SleepEx(): %d\n", error);
}
}
else if (dwReason == DLL_PROCESS_DETACH) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)TrueSleepEx, TimedSleepEx);
DetourDetach(&(PVOID&)TrueTextOut,SaveTextOut);
DetourDetach(&(PVOID&)TrueDrawText,NewDrawText);
error = DetourTransactionCommit();

printf("simple" DETOURS_STRINGIFY(DETOURS_BITS) ".dll:"
" Removed SleepEx() (result=%d), slept %d ticks.\n" , error, dwSlept);
printf("%S\n",flag);
fflush(stdout);
}
return TRUE;
}

__declspec(dllexport) void ExportFunc(void)
{
}


//
///////////////////////////////////////////////////////////////// End of File.
...全文
175 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhhcj 2013-08-19
  • 打赏
  • 举报
回复
TabbedTextOut和TextOut实质上都是调用ExtTextOut
引用 1 楼 wangk 的回复:
如果SleepEx能正常挂钩,那么同样方式的TextOut挂钩代码应该没什么问题, 剩下要确定TextOut是否会被调用到。 DrawText DrawTextEx ExtTextOut TabbedTextOut TextOut 这些都是绘制文本的函数。
wangk 2013-08-16
  • 打赏
  • 举报
回复
如果SleepEx能正常挂钩,那么同样方式的TextOut挂钩代码应该没什么问题, 剩下要确定TextOut是否会被调用到。 DrawText DrawTextEx ExtTextOut TabbedTextOut TextOut 这些都是绘制文本的函数。

15,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧