论坛大神们帮忙看下,这个HOOK哪里有问题
用的是微软的detours HOOK库,HOOK普通的Connect完全没问题。
LPFN_CONNECTEX lpfnConnectEx = NULL;
int (WINAPI *ConnectEx)(
SOCKET s,
const struct sockaddr* name,
int namelen,
PVOID lpSendBuffer,
DWORD dwSendDataLength,
LPDWORD lpdwBytesSent,
LPOVERLAPPED lpOverlapped
) = lpfnConnectEx;
int WINAPI HookConnectEx(
__in SOCKET s,
__in const struct sockaddr* name,
__in int namelen,
__in_opt PVOID lpSendBuffer,
__in DWORD dwSendDataLength,
__out LPDWORD lpdwBytesSent,
__in LPOVERLAPPED lpOverlapped
)
{
sockaddr_in saddr = *((SOCKADDR_IN*)name);
int nHostPort = ntohs(saddr.sin_port);
char* p = inet_ntoa(saddr.sin_addr);
char lpszHostAddress[80] = { 0 };
strcpy(lpszHostAddress, p);
//这里调用自身的API code......
OutputDebugString(lpszHostAddress);
}
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)ConnectEx, HookConnectEx);
DetourTransactionCommit();
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)