This repository has been archived by the owner on Jun 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
d.cs
317 lines (293 loc) · 5.87 KB
/
d.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
using socks5.Controller;
using socks5.Model;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Timers;
internal class d
{
public interface b
{
bool a(byte[] A_0, int A_1, Socket A_2);
}
[CompilerGenerated]
private sealed class a
{
public Socket a;
public d b;
internal void d(object A_0, ElapsedEventArgs A_1)
{
this.b.a(A_0, A_1, this.a);
}
internal void c(object A_0, ElapsedEventArgs A_1)
{
this.b.a(A_0, A_1, this.a);
}
}
private Configuration a;
private bool b;
private string c;
private Socket d;
private Socket e;
private bool f;
private IList<d.b> g;
protected Timer h;
protected object i = new object();
public d(IList<d.b> A_0)
{
this.g = A_0;
this.f = false;
}
public IList<d.b> b()
{
return this.g;
}
private bool a(int A_0)
{
try
{
IPEndPoint[] activeTcpListeners = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners();
for (int i = 0; i < activeTcpListeners.Length; i++)
{
if (activeTcpListeners[i].Port == A_0)
{
return true;
}
}
}
catch
{
}
return false;
}
public bool a(Configuration A_0)
{
try
{
if (this.b != A_0.shareOverLan || this.d == null || ((IPEndPoint)this.d.LocalEndPoint).Port != A_0.localPort)
{
return true;
}
}
catch (Exception)
{
}
return false;
}
public void a(Configuration A_0, int A_1)
{
this.a = A_0;
this.b = A_0.shareOverLan;
this.c = "";
this.f = false;
int num = (A_1 == 0) ? this.a.localPort : A_1;
if (this.a(num))
{
throw new Exception("Port already in use");
}
try
{
bool arg_6D_0 = true;
this.d = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
this.d.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
if (arg_6D_0)
{
try
{
this.e = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
this.e.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
}
catch
{
this.e = null;
}
}
IPEndPoint localEP = new IPEndPoint(IPAddress.Any, num);
IPEndPoint localEP2 = new IPEndPoint(IPAddress.IPv6Any, num);
if (this.e != null)
{
this.e.Bind(localEP2);
this.e.Listen(1024);
}
this.d.Bind(localEP);
this.d.Listen(1024);
Console.WriteLine("socks5 started on port " + num.ToString());
this.d.BeginAccept(new AsyncCallback(this.b), this.d);
if (this.e != null)
{
this.e.BeginAccept(new AsyncCallback(this.b), this.e);
}
}
catch (SocketException arg_154_0)
{
Logging.LogUsefulException(arg_154_0);
if (this.d != null)
{
this.d.Close();
this.d = null;
}
if (this.e != null)
{
this.e.Close();
this.e = null;
}
throw;
}
}
public void a()
{
this.a(0.0, null);
this.f = true;
if (this.d != null)
{
this.d.Close();
this.d = null;
}
if (this.e != null)
{
this.e.Close();
this.e = null;
}
}
private void a(double A_0, Socket A_1)
{
d.a a = new d.a();
a.b = this;
a.a = A_1;
if (A_0 <= 0.0 && this.h == null)
{
return;
}
object obj = this.i;
lock (obj)
{
if (A_0 <= 0.0)
{
if (this.h != null)
{
this.h.Enabled = false;
this.h.Elapsed -= new ElapsedEventHandler(a.d);
this.h.Dispose();
this.h = null;
}
}
else if (this.h == null)
{
this.h = new Timer(A_0 * 1000.0);
this.h.Elapsed += new ElapsedEventHandler(a.c);
this.h.Start();
}
else
{
this.h.Interval = A_0 * 1000.0;
this.h.Stop();
this.h.Start();
}
}
}
private void a(object A_0, ElapsedEventArgs A_1, Socket A_2)
{
if (this.h == null)
{
return;
}
try
{
A_2.BeginAccept(new AsyncCallback(this.b), A_2);
this.a(0.0, A_2);
}
catch (ObjectDisposedException)
{
}
catch (Exception arg_34_0)
{
Logging.LogUsefulException(arg_34_0);
this.a(5.0, A_2);
}
}
public void b(IAsyncResult A_0)
{
if (this.f)
{
return;
}
Socket socket = (Socket)A_0.AsyncState;
try
{
Socket socket2 = socket.EndAccept(A_0);
if (!this.b && !global::a.b(socket2))
{
socket2.Shutdown(SocketShutdown.Both);
socket2.Close();
}
if ((this.c ?? "").Length == 0 && !global::a.a(socket2))
{
socket2.Shutdown(SocketShutdown.Both);
socket2.Close();
}
else
{
byte[] array = new byte[4096];
object[] state = new object[]
{
socket2,
array
};
socket2.BeginReceive(array, 0, array.Length, SocketFlags.None, new AsyncCallback(this.a), state);
}
}
catch (ObjectDisposedException)
{
}
catch (Exception arg_A0_0)
{
Console.WriteLine(arg_A0_0);
}
finally
{
try
{
socket.BeginAccept(new AsyncCallback(this.b), socket);
}
catch (ObjectDisposedException)
{
}
catch (Exception arg_C1_0)
{
Logging.LogUsefulException(arg_C1_0);
this.a(5.0, socket);
}
}
}
private void a(IAsyncResult A_0)
{
object[] expr_0B = (object[])A_0.AsyncState;
Socket socket = (Socket)expr_0B[0];
byte[] a_ = (byte[])expr_0B[1];
try
{
int a_2 = socket.EndReceive(A_0);
using (IEnumerator<d.b> enumerator = this.g.GetEnumerator())
{
while (enumerator.MoveNext())
{
if (enumerator.Current.a(a_, a_2, socket))
{
return;
}
}
}
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
catch (Exception arg_67_0)
{
Console.WriteLine(arg_67_0);
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
}
}