Alright, so I'm hooking WSARecv and I can log packets just fine except for the case where lpOverlapped is not null, and lpCompletionRoutine is null.
There are two methods I have tried. One lets me log the packets and the game works as it normally would, except sometimes the logged packets are incorrect because the game changes the values in memory before I have a chance to look at them. The other method logs the packet correctly, but the game hangs waiting for some event to complete.
I want to get the second method working, since it should be more reliable. The problem is, I don't know exactly what I need to do to notify the client (game) that the packet is done being received. Right now my code looks like this.
Code:
int proxyWSARecv(int unused, SOCKET s, LPWSABUF recvBuffer, DWORD bufferCount, LPDWORD bytesRecvd, LPDWORD flags,
LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine){
WSAOVERLAPPED wsaoverlapped;
LPWSAOVERLAPPED ourOverlapped = &wsaoverlapped;
int retnVal;
__asm{
push lpCompletionRoutine
push ourOverlapped // our replacement lpoverlapped
push flags
push bytesRecvd
push bufferCount
push recvBuffer
push s
call p_WSARecv // real WSARecv
mov retnVal, EAX
}
// get overlapped results and log packets here. etc
}
That will log the packet properly, but the game will hang waiting for the WSARecv event to finish (because I'm not using the same lpOverlapped for the WSARecv call). I need to be able to let the game know that the action is complete.
I've been told that this can be done with PostQueuedCompletionStatus, but the problem is, the ioCompletionPort would be created before the game calls WSARecv, so I'm not quite sure how I could call PostQueuedCompletionStatus.
I'm aware that I could hook GetQueuedCompletionStatus or whatever it's called, but I'm trying to only intercept ws2_32 functions if possible.
Thanks!