forked from pipesocks/ssr868
-
Notifications
You must be signed in to change notification settings - Fork 23
/
b.cs
433 lines (394 loc) · 8.28 KB
/
b.cs
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
using socks5.Controller;
using socks5.Model;
using System;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Timers;
internal class b
{
private class a : IHandler
{
private Configuration a;
private byte[] b;
private int c;
private ProxySocketTunLocal d;
private ProxySocketTun e;
private bool f;
private bool g;
private string h;
private int i;
public const int j = 11680;
private byte[] k = new byte[11680];
private byte[] l = new byte[11680];
private int m;
protected int n = 600;
protected System.Timers.Timer o;
protected object p = new object();
protected DateTime q;
public void a(Configuration A_0, byte[] A_1, int A_2, Socket A_3, string A_4, bool A_5)
{
this.b = A_1;
this.c = A_2;
this.d = new ProxySocketTunLocal(A_3);
this.d.local_sendback_protocol = A_4;
this.a = A_0;
this.g = A_5;
this.d();
}
private void d()
{
try
{
IPAddress iPAddress = null;
int port = 0;
if (this.b[0] == 1)
{
byte[] array = new byte[4];
Array.Copy(this.b, 1, array, 0, array.Length);
iPAddress = new IPAddress(array);
port = ((int)this.b[5] << 8 | (int)this.b[6]);
this.h = iPAddress.ToString();
}
else if (this.b[0] == 4)
{
byte[] array2 = new byte[16];
Array.Copy(this.b, 1, array2, 0, array2.Length);
iPAddress = new IPAddress(array2);
port = ((int)this.b[17] << 8 | (int)this.b[18]);
this.h = iPAddress.ToString();
}
else if (this.b[0] == 3)
{
int num = (int)this.b[1];
byte[] array3 = new byte[num];
Array.Copy(this.b, 2, array3, 0, array3.Length);
this.h = Encoding.UTF8.GetString(this.b, 2, num);
port = ((int)this.b[num + 2] << 8 | (int)this.b[num + 3]);
if (!IPAddress.TryParse(this.h, out iPAddress) && iPAddress == null)
{
iPAddress = global::a.d().Get(this.h);
}
if (iPAddress == null)
{
iPAddress = global::a.a(this.h, null, false);
}
if (iPAddress != null)
{
global::a.d().Set(this.h, new IPAddress(iPAddress.GetAddressBytes()));
global::a.d().Sweep();
}
else if (!this.g)
{
throw new SocketException(11001);
}
}
this.i = port;
IPEndPoint ep = new IPEndPoint(iPAddress, port);
this.e = new ProxySocketTun(iPAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
this.e.GetSocket().NoDelay = true;
this.e.BeginConnect(ep, new AsyncCallback(this.c), null);
}
catch (Exception arg_1D1_0)
{
Logging.LogUsefulException(arg_1D1_0);
this.e();
}
}
private bool a(string A_0, int A_1)
{
return true;
}
private void c(IAsyncResult A_0)
{
if (this.f)
{
return;
}
try
{
this.e.EndConnect(A_0);
if (this.g && !this.a(this.h, this.i))
{
throw new SocketException(10054);
}
this.c();
}
catch (Exception arg_45_0)
{
Logging.LogUsefulException(arg_45_0);
this.e();
}
}
private void a(double A_0)
{
if (A_0 <= 0.0 && this.o == null)
{
return;
}
if (A_0 <= 0.0)
{
if (this.o == null)
{
return;
}
object obj = this.p;
lock (obj)
{
if (this.o != null)
{
this.o.Enabled = false;
this.o.Elapsed -= new ElapsedEventHandler(this.a);
this.o.Dispose();
this.o = null;
}
return;
}
}
DateTime arg_8F_0 = this.q;
if ((DateTime.Now - this.q).TotalMilliseconds > 500.0)
{
object obj = this.p;
lock (obj)
{
if (this.o == null)
{
this.o = new System.Timers.Timer(A_0 * 1000.0);
this.o.Elapsed += new ElapsedEventHandler(this.a);
}
else
{
this.o.Interval = A_0 * 1000.0;
this.o.Stop();
}
this.o.Start();
this.q = DateTime.Now;
}
}
}
private void a(object A_0, ElapsedEventArgs A_1)
{
if (this.f)
{
return;
}
this.e();
}
private void c()
{
if (this.f)
{
return;
}
try
{
this.e.BeginReceive(this.k, 11680, SocketFlags.None, new AsyncCallback(this.b), null);
this.d.BeginReceive(this.l, 11680, SocketFlags.None, new AsyncCallback(this.a), null);
this.d.Send(this.l, 0, SocketFlags.None);
this.a((double)this.n);
}
catch (Exception arg_77_0)
{
Logging.LogUsefulException(arg_77_0);
this.e();
}
}
private void b(IAsyncResult A_0)
{
if (this.f)
{
return;
}
try
{
int num = this.e.EndReceive(A_0);
if (num > 0)
{
this.a((double)this.n);
this.d.Send(this.k, num, SocketFlags.None);
if (Analyzer.instance().Add(this.h, this.i, this.e, this.k, num, true))
{
Analyzer.instance().Close(this.h, this.i, this.e);
}
this.m += num;
if (this.m <= 2097152)
{
this.e.BeginReceive(this.k, 11680, SocketFlags.None, new AsyncCallback(this.b), null);
}
else
{
this.b();
}
}
else
{
this.e();
}
}
catch (Exception arg_D3_0)
{
Logging.LogUsefulException(arg_D3_0);
this.e();
}
}
private void b()
{
bool flag = false;
byte[] buffer = new byte[11680];
DateTime d = DateTime.Now;
while (!this.f)
{
try
{
int num = this.e.Receive(buffer, 11680, SocketFlags.None);
DateTime now = DateTime.Now;
if (this.e != null && this.e.IsClose)
{
flag = true;
break;
}
if (this.f)
{
break;
}
this.a((double)this.n);
if (num > 0)
{
this.d.Send(buffer, num, SocketFlags.None);
if (Analyzer.instance().Add(this.h, this.i, this.e, buffer, num, true))
{
Analyzer.instance().Close(this.h, this.i, this.e);
}
if ((now - d).TotalSeconds > 5.0)
{
this.m = 0;
this.e.BeginReceive(this.k, 11680, SocketFlags.None, new AsyncCallback(this.b), null);
return;
}
d = now;
}
else
{
this.e();
}
}
catch (Exception arg_113_0)
{
Logging.LogUsefulException(arg_113_0);
flag = true;
break;
}
}
if (flag)
{
this.e();
return;
}
}
private void a(IAsyncResult A_0)
{
if (this.f)
{
return;
}
try
{
int num = this.d.EndReceive(A_0);
if (num > 0)
{
this.a((double)this.n);
this.e.Send(this.l, num, SocketFlags.None);
if (Analyzer.instance().Add(this.h, this.i, this.e, this.l, num, false))
{
Analyzer.instance().Close(this.h, this.i, this.e);
}
this.d.BeginReceive(this.l, 11680, SocketFlags.None, new AsyncCallback(this.a), null);
}
else
{
this.e();
}
}
catch (Exception arg_B0_0)
{
Logging.LogUsefulException(arg_B0_0);
this.e();
}
}
private void a(ProxySocketTun A_0)
{
lock (this)
{
if (A_0 != null)
{
try
{
A_0.Shutdown(SocketShutdown.Both);
}
catch
{
}
try
{
A_0.Close();
}
catch
{
}
}
}
}
public void e()
{
lock (this)
{
if (this.f)
{
return;
}
this.f = true;
}
this.a(0.0);
Thread.Sleep(100);
Analyzer.instance().Close(this.h, this.i, this.e);
this.a(this.e);
this.a(this.d);
}
public override void Shutdown()
{
new IHandler.InvokeHandler(this.a).BeginInvoke(null, null);
}
[CompilerGenerated]
private void a()
{
this.e();
}
}
private const int a = 1;
private const int b = 2;
private const int c = 0;
private Configuration d;
public b(Configuration A_0)
{
this.d = A_0;
}
public bool b(byte[] A_0, int A_1, Socket A_2)
{
return this.a(A_0, A_1, A_2, null);
}
public bool a(byte[] A_0, int A_1, Socket A_2, string A_3)
{
if (this.a(A_0, A_1, A_2) > 0)
{
new b.a().a(this.d, A_0, A_1, A_2, A_3, false);
return true;
}
return false;
}
public int a(byte[] A_0, int A_1, Socket A_2)
{
return 2;
}
}