forked from GuckTubeYT/GTProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
204 lines (175 loc) · 7.02 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <pthread.h>
#endif // __WIN32
#include <time.h>
#include <stdint.h>
#include "enet/include/enet.h"
#include "httpService.h"
#include "utils/utils.h"
#include "packet/packet.h"
#include "proxyStruct.h"
#include "events/eventClient.h"
#include "events/eventServer.h"
#include "mainVar.h"
#include "proxyStruct.h"
void loadConfig() {
FILE* fp = fopen("config.conf", "rb");
if (!fp) {
printf("[GTProxy Configuration] config.conf not found! Creating...\n");
fp = fopen("config.conf", "wb");
userConfig.usingServerData = 1;
userConfig.serverDataIP = "2.17.198.162";
userConfig.manualIP = "127.0.0.1";
userConfig.manualPort = 17091;
asprintf(&userConfig.manualMeta, "localhost");
userConfig.usingNewPacket = 1;
userConfig.httpsPort = 443;
userConfig.skipGazette = 1;
userConfig.isSpoofed = 0;
fprintf(fp, "usingServerData=1\nserverDataIP=2.17.198.162\nmanualIP=127.0.0.1\nmanualPort=17091\nmanualMeta=localhost\nusingNewPacket=1\nhttpsPort=443\nskipGazette=1\nisSpoofed=0");
fclose(fp);
printf("[GTProxy Configuration] config.conf has been created!\n");
} else {
fseek(fp, 0, SEEK_END);
int fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
char* data = malloc(fsize + 1);
fread(data, fsize, 1, fp);
fclose(fp);
data[fsize] = '\0';
char** split = strsplit(data, "\n", 0);
free(data);
int a = 0;
while(split[a]) {
if (split[a][0] == '#') continue;
char** split2 = strsplit(split[a++], "=", 0);
if (isStr(split2[0], "usingServerData", 1)) {
if (split2[1][0] == '1') userConfig.usingServerData = 1;
else userConfig.usingServerData = 0;
}
if (isStr(split2[0], "serverDataIP", 1)) asprintf(&userConfig.serverDataIP, "%s", split2[1]);
if (isStr(split2[0], "manualIP", 1)) asprintf(&userConfig.manualIP, "%s", split2[1]);
if (isStr(split2[0], "manualPort", 1)) userConfig.manualPort = atoi(split2[1]);
if (isStr(split2[0], "manualMeta", 1)) asprintf(&userConfig.manualMeta, "%s", split2[1]);
if (isStr(split2[0], "usingNewPacket", 1)) {
if (split2[1][0] == '1') userConfig.usingNewPacket = 1;
else userConfig.usingNewPacket = 0;
}
if (isStr(split2[0], "httpsPort", 1)) userConfig.httpsPort = atoi(split2[1]);
if (isStr(split2[0], "skipGazette", 1)) {
if (split2[1][0] == '1') userConfig.skipGazette = 1;
else userConfig.skipGazette = 0;
}
if (isStr(split2[0], "isSpoofed", 1)) {
if (split2[1][0] == '1') userConfig.isSpoofed = 1;
else userConfig.isSpoofed = 0;
}
free(split2);
}
free(split);
}
printf("[GTProxy Configuration] Using Server data: %s\n", userConfig.usingServerData ? "true" : "false");
if (userConfig.usingServerData) printf("[GTProxy Configuration] Server Data IP: %s\n", userConfig.serverDataIP);
else printf("[GTProxy Configuration] Manual IP: %s\n[GTProxy Configuration] Manual Port: %d\n[GTProxy Configuration] Manual Meta: %s\n", userConfig.manualIP, userConfig.manualPort, userConfig.manualMeta);
printf("[GTProxy Configuration] Using new packet: %s\n", userConfig.usingNewPacket ? "true" : "false");
printf("[GTProxy Configuration] HTTPS Port: %d\n", userConfig.httpsPort);
printf("[GTProxy Configuration] Skip gazette: %s\n", userConfig.skipGazette ? "true" : "false");
printf("[GTProxy Configuration] Is Spoofed: %s\n[GTProxy Configuration] Configuration has been loaded!\n", userConfig.isSpoofed ? "true" : "false");
}
int main() {
if (!isLoop) {
loadConfig();
}
isLoop = 1;
doLoop = 0;
srand(time(NULL));
memset(¤tInfo, 0, sizeof(currentInfo));
currentInfo.wk = generateHex(16);
currentInfo.rid = generateHex(16);
currentInfo.deviceID = generateHex(16);
currentInfo.mac = generateHex(0);
memset(&OnPacket, 0, sizeof(OnPacket));
enet_initialize();
memset(&proxyAddress, 0, sizeof(ENetAddress));
proxyAddress.host = 0; // 0.0.0.0
proxyAddress.port = 17091;
proxyServer = enet_host_create(&proxyAddress, 1024, 10, 0, 0);
proxyServer->checksum = enet_crc32;
enet_host_compress_with_range_coder(proxyServer);
realServer = enet_host_create(NULL, 1, 2, 0, 0);
realServer->checksum = enet_crc32;
realServer->usingNewPacket = userConfig.usingNewPacket;
enet_host_compress_with_range_coder(realServer);
if (!HTTPAlreadyOn) {
#ifdef __WIN32
HTTPThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)HTTPSServer, NULL, 0, NULL);
#else
pthread_create(&HTTPThread, NULL, HTTPSServer, NULL);
#endif // __WIN32
HTTPAlreadyOn = 1;
}
while(isLoop) {
ENetEvent proxyEvent;
ENetEvent realEvent;
while(enet_host_service(proxyServer, &proxyEvent, 5) > 0) {
proxyPeer = proxyEvent.peer;
switch(proxyEvent.type) {
case ENET_EVENT_TYPE_CONNECT: {
clientConnect();
break;
}
case ENET_EVENT_TYPE_RECEIVE: {
clientReceive(proxyEvent, proxyPeer, realPeer);
break;
}
case ENET_EVENT_TYPE_DISCONNECT: {
clientDisconnect();
break;
}
case ENET_EVENT_TYPE_NONE: break;
}
}
while(enet_host_service(realServer, &realEvent, 5) > 0) {
switch(realEvent.type) {
case ENET_EVENT_TYPE_CONNECT: {
serverConnect();
break;
}
case ENET_EVENT_TYPE_RECEIVE: {
serverReceive(realEvent, proxyPeer, realPeer);
break;
}
case ENET_EVENT_TYPE_DISCONNECT: {
serverDisconnect();
break;
}
case ENET_EVENT_TYPE_NONE: break;
}
}
}
if (realPeer) enet_peer_disconnect_now(realPeer, 0);
enet_peer_disconnect_now(proxyPeer, 0);
enet_host_destroy(realServer);
enet_host_destroy(proxyServer);
enet_deinitialize();
if (currentInfo.isMetaMalloc) {
free(currentInfo.meta);
currentInfo.isMetaMalloc = 0;
}
free(currentInfo.wk);
free(currentInfo.rid);
free(currentInfo.deviceID);
free(currentInfo.mac);
if (doLoop) {
currentInfo.isLogin = 0;
isLoop = 1;
doLoop = 0;
main();
}
return 0;
}