首页
论坛
课程
招聘
[原创]枚举TCP并关闭指定连接,炉石传说拔线专用.
2022-3-21 01:00 9940

[原创]枚举TCP并关闭指定连接,炉石传说拔线专用.

2022-3-21 01:00
9940

炉石现在的版本,不拔线玩不了,所以刚弄了个拔线的...
过滤战网的连接,仅仅关闭炉石传说游戏中的连接.
稳定拔线不卡游戏.
直接复制粘贴,给你们心爱的主播编译一个吧.

 

图片描述
代码如下,新建控制台应用,覆盖粘贴进去编译就行了.
附件是成品.
图片描述

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <Psapi.h>
using namespace std;
// Need to link with Iphlpapi.lib and Ws2_32.lib
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "Psapi.lib")
#pragma comment(lib, "ntdll.lib")
 
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
/* Note: could also use malloc() and free() */
 
 
char* GetProcessName(DWORD dwPid,  char* szModuleName,DWORD buffsize)
{
 
    if (!szModuleName || !buffsize) return 0;
    HANDLE pro_handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, dwPid);
    if ((INT64)pro_handle > 0)
    {
        HMODULE hMods = 0;;
        DWORD cbNeeded = 0;
        if(EnumProcessModulesEx(pro_handle, &hMods, 8, &cbNeeded, LIST_MODULES_ALL)) //http://msdn.microsoft.com/en-us/library/ms682633(v=vs.85).aspx
        {
            GetModuleFileNameExA(pro_handle, hMods, szModuleName, buffsize);
            return strrchr(szModuleName, '\\');
        }
        CloseHandle(pro_handle);
 
    }
 
 
    return 0;
}
vector<MIB_TCPROW2> g_battlenet;//战网网络连接
vector<MIB_TCPROW2> g_Hearthstone;//炉石传说网络连接
 
const char *g_battlenetname="\\Battle.net.exe", * g_Hearthstonename="\\Hearthstone.exe";
int get_list(vector<MIB_TCPROW2>* battlenet_list, vector<MIB_TCPROW2>* Hearthstone_list)
{
    battlenet_list->resize(0);
    Hearthstone_list->resize(0);
 
 
    //代码来自 https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-gettcptable2
    // Declare and initialize variables
    PMIB_TCPTABLE2 pTcpTable;
    ULONG ulSize = 0;
    DWORD dwRetVal = 0;
 
    char szLocalAddr[128];
    char szRemoteAddr[128];
 
    struct in_addr IpAddr;
 
    pTcpTable = (MIB_TCPTABLE2*)MALLOC(sizeof(MIB_TCPTABLE2));
    if (pTcpTable == NULL)
    {
        printf("Error allocating memory\n");
        return 1;
    }
 
    ulSize = sizeof(MIB_TCPTABLE);
    // Make an initial call to GetTcpTable2 to
    // get the necessary size into the ulSize variable
    if ((dwRetVal = GetTcpTable2(pTcpTable, &ulSize, TRUE)) == ERROR_INSUFFICIENT_BUFFER)
    {
        FREE(pTcpTable);
        pTcpTable = (MIB_TCPTABLE2*)MALLOC(ulSize);
        if (pTcpTable == NULL)
        {
            printf("Error allocating memory\n");
            return 1;
        }
    }
    // Make a second call to GetTcpTable2 to get
    //
    // the actual data we require
    string socketstate;
 
    if ((dwRetVal = GetTcpTable2(pTcpTable, &ulSize, TRUE)) == NO_ERROR)
    {
        printf("PID     \t\tLocalAddr:Portt\t\tRemoteAddr:Port        \tstate\n");
        for (int i = 0; i < (int)pTcpTable->dwNumEntries; i++)
        {
            if (MIB_TCP_STATE_ESTAB!= pTcpTable->table[i].dwState)//过滤不是连接状态的连接
            {
                continue;
            }
 
            char processname[256];
            char *filename=GetProcessName(pTcpTable->table[i].dwOwningPid, processname, 256);
 
            if (!filename)
            {
                continue;
            }
            if (_stricmp(g_battlenetname, filename)!=0 && _stricmp(g_Hearthstonename, filename) != 0)//过滤进程
            {
                continue;
            }
            if (pTcpTable->table[i].dwLocalAddr == 0 || pTcpTable->table[i].dwLocalAddr == 0x100007F)//过滤本地连接
            {
                continue;
            }
            if (pTcpTable->table[i].dwRemoteAddr == 0 || pTcpTable->table[i].dwRemoteAddr == 0x100007F)//过滤本地连接
            {
                continue;
            }
            IpAddr.S_un.S_addr = (u_long)pTcpTable->table[i].dwLocalAddr;
            InetNtopA(AF_INET, &IpAddr, szLocalAddr, 128);
            DWORD dwLocalPort = ntohs(pTcpTable->table[i].dwLocalPort);
            IpAddr.S_un.S_addr = (u_long)pTcpTable->table[i].dwRemoteAddr;
            InetNtopA(AF_INET, &IpAddr, szRemoteAddr, 128);
            DWORD dwRemotePort = ntohs(pTcpTable->table[i].dwRemotePort);
            socketstate = "["+to_string(pTcpTable->table[i].dwOwningPid)+"]"+ string(filename+1) + "\t";
            socketstate = socketstate + string(szLocalAddr) + ":" + to_string(dwLocalPort) + "\t";
            socketstate = socketstate + string(szRemoteAddr) + ":" + to_string(dwRemotePort) + "\t";
            socketstate = socketstate + "[" + to_string(pTcpTable->table[i].dwState) + "]\n";
            if (dwRemotePort == 443 || dwRemotePort == 80)//过滤掉443端口
            {
                continue;
            }
 
            printf(socketstate.c_str());
 
            if (_stricmp(g_battlenetname, filename) ==0)
            {
                g_battlenet.push_back(pTcpTable->table[i]);
            }
            if (_stricmp(g_Hearthstonename, filename) == 0)
            {
                g_Hearthstone.push_back(pTcpTable->table[i]);
            }
 
 
        }
    }
    else {
        printf("\tGetTcpTable2 failed with %d\n", dwRetVal);
        FREE(pTcpTable);
        return 1;
    }
 
    if (pTcpTable != NULL) {
        FREE(pTcpTable);
        pTcpTable = NULL;
    }
    return 0;
}
DWORD thread_resocket(PVOID param)
{
 
    do
    {
 
        //SetTcpEntry((MIB_TCPROW*)&srtTcpRow);
       // pTcpTable->table[i].dwState = MIB_TCP_STATE_DELETE_TCB;
        //    dwRetVal = SetTcpEntry((MIB_TCPROW*)&pTcpTable->table[i]);
        if (GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_DELETE)&1)
        {
            printf("正在拔线....\n");
            get_list(&g_battlenet, &g_Hearthstone);
            bool samesocket = false;
 
            for (int i = 0; i < g_Hearthstone.size(); i++)
            {
                samesocket = false;
                for (size_t k = 0; k < g_battlenet.size(); k++)
                {
                    if (g_Hearthstone[i].dwRemoteAddr== g_battlenet[k].dwRemoteAddr && g_Hearthstone[i].dwRemotePort == g_battlenet[k].dwRemotePort)
                    {
                        samesocket = true;
                        break;
                    }
                }
                if (samesocket==false)
                {
                    g_Hearthstone[i].dwState = MIB_TCP_STATE_DELETE_TCB;//重置网络连接
 
                    char szLocalAddr[128];
                    char szRemoteAddr[128];
                    InetNtopA(AF_INET, &g_Hearthstone[i].dwLocalAddr, szLocalAddr, 128);
                    DWORD dwLocalPort = ntohs(g_Hearthstone[i].dwLocalPort);
 
                    InetNtopA(AF_INET, &g_Hearthstone[i].dwRemoteAddr, szRemoteAddr, 128);
                    DWORD dwRemotePort = ntohs(g_Hearthstone[i].dwRemotePort);
                    printf("已经断开连接--->%s:%d ---- %s:%d \n", szLocalAddr, dwLocalPort, szRemoteAddr, dwRemotePort);
                    SetTcpEntry((MIB_TCPROW*)&g_Hearthstone[i]);
                }
            }
            Sleep(500);
        }
 
 
 
        Sleep(10);
    } while (true);
 
 
    return 0;
}
int main()
{
 
    CreateThread(0, 0, thread_resocket, 0, 0, 0);
    printf("启动成功\n登录[暴雪战网]且[炉石传说]游戏中\n按下热键[Ctrl+Delete]拔线");
    getchar();
    return 0;
}

看雪招聘平台创建简历并且简历完整度达到90%及以上可获得500看雪币~

上传的附件:
收藏
点赞1
打赏
分享
最新回复 (7)
雪    币: 201
活跃值: 活跃值 (2116)
能力值: ( LV3,RANK:35 )
在线值:
发帖
回帖
粉丝
ookkaa 活跃值 2022-3-21 08:47
2
0
好东西
雪    币: 201
活跃值: 活跃值 (2116)
能力值: ( LV3,RANK:35 )
在线值:
发帖
回帖
粉丝
ookkaa 活跃值 2022-3-21 08:48
3
0
最好整出来直接能跳过动画,不用断网的
雪    币: 4684
活跃值: 活跃值 (2074)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
mudebug 活跃值 2022-3-21 12:13
4
0
当初被这种代码侦测外挂服务器验证IP折腾了1个多月才发现。
雪    币: 201
活跃值: 活跃值 (2116)
能力值: ( LV3,RANK:35 )
在线值:
发帖
回帖
粉丝
ookkaa 活跃值 2022-3-21 12:22
5
0
测了一下,不太行
雪    币: 201
活跃值: 活跃值 (2116)
能力值: ( LV3,RANK:35 )
在线值:
发帖
回帖
粉丝
ookkaa 活跃值 2022-3-21 12:23
6
0

 1

最后于 2022-3-21 12:24 被ookkaa编辑 ,原因:
雪    币: 201
活跃值: 活跃值 (2116)
能力值: ( LV3,RANK:35 )
在线值:
发帖
回帖
粉丝
ookkaa 活跃值 2022-3-21 12:35
7
0
多断几次游戏就闪退了
雪    币: 6274
活跃值: 活跃值 (1548)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
lononan 活跃值 2022-3-21 16:25
8
0
ookkaa 多断几次游戏就闪退了
卡死是因为你对局结束了,不是你挂了就是决赛圈结束了.
游客
登录 | 注册 方可回帖
返回