I need to hook socket in one application, so I will be able to send packets to client/server and modify sent/received. I've managed to do it with madCodeHook by hooking recv/send calls, but there's one problem - via this method I'm not able to send packets to this socket. That's because recv doesn't take the packet as a parameter, but empty buffer which will store it. So I started to look for a workaround...
After playing a bit with OllyDbg and reading winsock documentantion I found out few things. First, the application is calling WSAAsyncSelect so winsock will post a message everytime it receives a packet. I also found the message ID. Later, after receiving it it's calling select function, to check whether socket is readable (so there's something in the queue). If it is, it's using recv function to get the packet.
The problem is, how can I emulate it... First, I've hooked the call to 'select' function and everytime it gets called I print a message on the screen so I see when it's used. Then, starting from the beginning, I need to send a faked message telling the application there's a packet waiting for receiving... and here's the problem. I have the message id, window handle and I (think I) know what parameters do I need to send. I tried the following:
PostMessage(WindowHandle, MessageID, 0, FD_READ);
Result value was true, so it sent the message however nothing happened - my hooked select function wasn't called.
So my question is - did I miss any other important function on the way? Or maybe I am sending message to the window incorrectly?
Thanks in advance