zyxm198272 2018-11-28 14:46 采纳率: 0%
浏览 772
已结题

现金红包,SOCKS5 TCP协议 代理游戏,协商成功后,发送数据包却收不到返回数据!

SOCKS5协议成功后,发送数据收不到返回信息是什么情况
图片说明

            我是HOOK的一个棋牌游戏的 ws2_32.connect,然后在里面调用下面的函数。
            协商成功后,游戏会自动发送1个数据包,也就是图片上最后一个包,发送到代理服务器上后,就没有返回信息了。望解疑惑。

            能搞定的,留下QQ号,我给你发个红包!

int ConnectBySock5(SOCKET socket, string ip, u_short port)
{
char buf[512];
int rc;

if (rc = WSAEventSelect(socket, 0, NULL))//这一个可以不用执行
{
    DebugPrint("Error %d : WSAEventSelect Failure!", WSAGetLastError());
}
else
{
    DebugPrint("Message : WSAEventSelect successfully!");
}
unsigned long nonBlock = 0;
if (rc = ioctlsocket(socket, FIONBIO, &nonBlock))// 这个真正修改为阻塞类型
{
    DebugPrint("Error %d : Set Blocking Failure!", WSAGetLastError());
}
else
{
    DebugPrint("Message : Set Blocking successfully!");
}

struct TSock5req1 *proxyreq1;
proxyreq1 = (struct TSock5req1 *)buf;
proxyreq1->Ver = 5;
proxyreq1->nMethods = 1;
proxyreq1->Methods = 2;// m_proxyUserName != "" ? 2 : 0;

DebugPrint("%d  %d  %d",buf[0], buf[1], buf[2]);

//g_SendBufLen = 3;
//memcpy_s(g_SendBuf, 1024, buf, g_SendBufLen);
Send(socket, buf, 3);

struct TSock5ans1 *proxyans1;
proxyans1 = (struct TSock5ans1 *)buf;

memset(buf, 0, sizeof(buf));
rc = Receive(socket, buf, sizeof(buf));


DebugPrint("proxyans1->Method = %d  proxyans1->Ver = %d", proxyans1->Method, proxyans1->Ver);

if (proxyans1->Method != 0 && proxyans1->Method != 2 || proxyans1->Ver != 5)
{
    DebugPrint("ConnectBySock5 CONNECT_SERVER_FAIL1");
    return CONNECT_SERVER_FAIL;
}

if (proxyans1->Method == 2)
{
    int nUserLen = m_proxyUserName.length();
    int nPassLen = m_proxyUserPwd.length();

    buf[0] = 1;
    buf[1] = nUserLen;
    memcpy(buf + 2, m_proxyUserName.c_str(), nUserLen);
    buf[2 + nUserLen] = nPassLen;
    memcpy(buf + 3 + nUserLen, m_proxyUserPwd.c_str(), nPassLen);


    //g_SendBufLen = 3 + nUserLen + nPassLen;
//  memcpy_s(g_SendBuf, 1024, buf, g_SendBufLen);

    Send(socket, buf, 3 + nUserLen + nPassLen);

    struct TAuthans *authans;
    authans = (struct TAuthans *)buf;
    memset(buf, 0, sizeof(buf));

    Receive(socket, buf, sizeof(buf));
    if (authans->Ver != 1 || authans->Status != 0)
    {
        DebugPrint("ConnectBySock5 CONNECT_SERVER_FAIL2");
        return CONNECT_SERVER_FAIL;
    }
}

struct TSock5req2 *proxyreq2;
proxyreq2 = (struct TSock5req2 *)buf;
proxyreq2->Ver = 5;
proxyreq2->Cmd = 1;
proxyreq2->Rsv = 0;
proxyreq2->Atyp = 1;

unsigned long tmpLong = inet_addr(ip.c_str());
unsigned short port1 = ntohs(port);
memcpy((char*)&proxyreq2->other, &tmpLong, 4);
memcpy((char*)(&proxyreq2->other) + 4, &port1, 2);

//Send(socket, buf, sizeof(struct TSock5req2) + 5); 

//g_SendBufLen = 10;
//memcpy_s(g_SendBuf, 1024, buf, g_SendBufLen);

Send(socket, buf, 10);

struct TSock5ans2 *proxyans2;
memset(buf, 0, sizeof(buf));
proxyans2 = (struct TSock5ans2 *)buf;

rc = Receive(socket, buf, sizeof(buf));

DebugPrint("len = %d  Data = %s", rc, bytesToHexString((byte*)buf,10));

if (proxyans2->Ver != 5 || proxyans2->Rep != 0)
{
    DebugPrint("ConnectBySock5 CONNECT_SERVER_FAIL3");
    return CONNECT_SERVER_FAIL;
}

//修改socket为非阻塞类型
nonBlock = 1;
if (rc = ioctlsocket(socket, FIONBIO, &nonBlock))
{
    DebugPrint("Error %d : Set Non-Blocking Failure!", WSAGetLastError());
    //return rc;
}
else
{
    DebugPrint("Message : Set Non-Blocking Successful!");
}

//rc = Receive(socket, buf, sizeof(buf));
//DebugPrint("len = %d  Data = %s", rc, bytesToHexString((byte*)buf, 10));

return SUCCESS;

}

  • 写回答

3条回答 默认 最新

  • zyxm198272 2018-11-28 19:07
    关注

    经检查,是协商成功返回后,tcp连接立即从代理服务器上断开了。不知道是什么情况引起!

    评论

报告相同问题?

悬赏问题

  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决