使用钩住的GetQueuedCompletionStatus

时间:2016-12-21 22:25:41

标签: c++ winapi networking iocp kernel32

我正在使用下面的代码挂钩GetQueuedCompletionStatus函数:

// hook code
typedef BOOL (__stdcall * MyGetQueuedCompletionStatus)(
  _In_  HANDLE       CompletionPort,
  _Out_ LPDWORD      lpNumberOfBytes,
  _Out_ PULONG_PTR   lpCompletionKey,
  _Out_ LPOVERLAPPED *lpOverlapped,
  _In_  DWORD        dwMilliseconds
);

static BOOL __stdcall OwnGetQueuedCompletionStatus(
    __in  HANDLE CompletionPort,
    __out LPDWORD lpNumberOfBytesTransferred,
    __out PULONG_PTR lpCompletionKey,
    __out LPOVERLAPPED *lpOverlapped,
    __in  DWORD dwMilliseconds
    );    

int hook()
{
    LPVOID fnOrigGetQueuedCompletionStatus = ::GetProcAddress(LoadLibrary("kernel32.dll"),  "GetQueuedCompletionStatus");
    DWORD dwOsErr = cHookMgr.Hook(&nHookId, (LPVOID*)&(Information::Instance().pTrampolineGetQueuedCompletionStatus), fnOrigGetQueuedCompletionStatus, OwnGetQueuedCompletionStatus);
}

static BOOL __stdcall OwnGetQueuedCompletionStatus(
    __in  HANDLE CompletionPort,
    __out LPDWORD lpNumberOfBytesTransferred,
    __out PULONG_PTR lpCompletionKey,
    __out LPOVERLAPPED *lpOverlapped,
    __in  DWORD dwMilliseconds
    )
{
    return Information::Instance().pTrampolineGetQueuedCompletionStatus(CompletionPort, lpNumberOfBytesTransferred, lpCompletionKey, lpOverlapped, dwMilliseconds);
}

正如你所看到的,虚假功能什么也没做,但是当我挂钩应用程序使用它时我总是崩溃:

  

问题事件名称:BEX64
    应用程序名称:MainServer.exe
  申请时间戳:575f98b7
    故障模块名称:test64.dll_unloaded
    故障模块版本:0.0.0.0
    故障模块时间戳:585af544
    异常偏移:00000000000025a0
  异常代码:c0000005异常数据:0000000000000008

其他挂钩功能效果很好。 我该如何解决这个问题?

0 个答案:

没有答案