简体   繁体   中英

Simulate packet send and recv

I have hooked the send and recv functions for a game process. Now I can handle what is sent and what in received.

My functions are:

int __stdcall nSend(SOCKET s, char *buf, int len,int flags)
{
    UnHookFunction("ws2_32.dll", "send", KSendHook);   
    int result = send(s, buf, len, flags); // Send data 
    HookFunction("ws2_32.dll", "send", (LPVOID*) nSend, KSendHook);

    return result; 
}

int __stdcall nRecv(SOCKET s, char *buf, int len, int flags)
{
    UnHookFunction("ws2_32.dll", "recv", KRecvHook); 
    int result = recv(s, buf, len, flags); // Receive data
    HookFunction("ws2_32.dll", "recv", (LPVOID*) nRecv, KRecvHook);

    return result;
}

My question is:

I hooked the function so I can only interpret and modify what is sent and received. I need to send new packets structures as I if I was the game. Using the same socket.

How could I simulate the send and recv for the same socket of hooked functions?

When your hooked receive function is called, call the real send and receive functions as needed. When you have data to return to the caller, return it to the caller. When send is called, take the data sent, decide whether you want to send anything to the server or not, and call send and receive to talk to the server as you like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM