简体   繁体   English

模拟数据包发送和接收

[英]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? 我如何模拟钩子函数的相同套接字的send和recv?

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. 调用send时,获取发送的数据,确定是否要将任何内容发送到服务器,然后根据需要调用send和receive来与服务器对话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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