-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathForm1.cs
290 lines (264 loc) · 11 KB
/
Form1.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
using System;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace FireSocks
{
public class Form1 : Form
{
private IContainer components;
private ToolStripMenuItem startToolStripMenuItem;
private BPListView listView1;
private ColumnHeader columnHeader1;
private ColumnHeader columnHeader2;
private ToolStripMenuItem buildProxyToolStripMenuItem;
private MenuStrip menuStrip1;
private StatusStrip statusStrip1;
private ToolStripStatusLabel toolStripStatusLabel1;
private ToolStripStatusLabel toolStripStatusLabel2;
private ColumnHeader columnHeader3;
private ProxyNotifications _PN;
private int _TotalProxies;
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(Form1));
this.startToolStripMenuItem = new ToolStripMenuItem();
this.menuStrip1 = new MenuStrip();
this.buildProxyToolStripMenuItem = new ToolStripMenuItem();
this.statusStrip1 = new StatusStrip();
this.toolStripStatusLabel1 = new ToolStripStatusLabel();
this.toolStripStatusLabel2 = new ToolStripStatusLabel();
this.listView1 = new BPListView();
this.columnHeader1 = new ColumnHeader();
this.columnHeader2 = new ColumnHeader();
this.columnHeader3 = new ColumnHeader();
this.menuStrip1.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
// startToolStripMenuItem
this.startToolStripMenuItem.Name = "startToolStripMenuItem";
this.startToolStripMenuItem.Size = new Size(43, 20);
this.startToolStripMenuItem.Text = "Start";
this.startToolStripMenuItem.Click += new EventHandler(this.startToolStripMenuItem_Click);
// menuStrip1
this.menuStrip1.Items.AddRange(new ToolStripItem[]
{
this.startToolStripMenuItem,
this.buildProxyToolStripMenuItem
});
this.menuStrip1.Location = new Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new Size(276, 24);
this.menuStrip1.TabIndex = 3;
this.menuStrip1.Text = "menuStrip1";
// buildProxyToolStripMenuItem
this.buildProxyToolStripMenuItem.Name = "buildProxyToolStripMenuItem";
this.buildProxyToolStripMenuItem.Size = new Size(79, 20);
this.buildProxyToolStripMenuItem.Text = "Build Proxy";
this.buildProxyToolStripMenuItem.Click += new EventHandler(this.buildProxyToolStripMenuItem_Click);
// statusStrip1
this.statusStrip1.Items.AddRange(new ToolStripItem[]
{
this.toolStripStatusLabel1,
this.toolStripStatusLabel2
});
this.statusStrip1.Location = new Point(0, 284);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new Size(276, 22);
this.statusStrip1.TabIndex = 4;
this.statusStrip1.Text = "statusStrip1";
// toolStripStatusLabel1
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new Size(76, 17);
this.toolStripStatusLabel1.Text = "Total Proxies:";
// toolStripStatusLabel2
this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
this.toolStripStatusLabel2.Size = new Size(13, 17);
this.toolStripStatusLabel2.Text = "0";
// listView1
this.listView1.Columns.AddRange(new ColumnHeader[]
{
this.columnHeader1,
this.columnHeader2,
this.columnHeader3
});
this.listView1.Dock = DockStyle.Fill;
this.listView1.FullRowSelect = true;
this.listView1.HideSelection = false;
this.listView1.Location = new Point(0, 24);
this.listView1.Name = "listView1";
this.listView1.OwnerDraw = true;
this.listView1.Size = new Size(276, 282);
this.listView1.TabIndex = 2;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = View.Details;
// columnHeader1
this.columnHeader1.Text = "Local Port";
this.columnHeader1.Width = 65;
// columnHeader2
this.columnHeader2.Text = "Address";
this.columnHeader2.Width = 129;
// columnHeader3
this.columnHeader3.Text = "Usage";
this.columnHeader3.Width = 45;
// Form1
this.AutoScaleDimensions = new SizeF(6f, 13f);
this.AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new Size(276, 306);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.listView1);
this.Controls.Add(this.menuStrip1);
this.DoubleBuffered = true;
//this.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
this.Name = nameof(Form1);
this.Opacity = 0.9;
this.StartPosition = FormStartPosition.CenterParent;
this.Text = "FireSocks";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
[DllImport("proxlib.dll", EntryPoint = "proxy_listener_start", CallingConvention = CallingConvention.Cdecl)]
private static extern int ProxyListenerStart(
ref ProxyConfig pconfig,
ref ProxyNotifications pnotf);
[DllImport("proxlib.dll", EntryPoint = "proxy_listener_stop", CallingConvention = CallingConvention.Cdecl)]
private static extern void ProxyListenerStop();
public Form1()
{
this.InitializeComponent();
AssemblyName assemblyName = Assembly.GetExecutingAssembly().GetName();
this.Text = $"{assemblyName.Name} v{assemblyName.Version}";
this._PN.newproxy = new NTFCBNewProxy(this.NewProxy);
this._PN.deadproxy = new NTFCBDeadProxy(this.DeadProxy);
this._PN.inuse = new NTFCBInUse(this.InUseProxy);
}
private void NewProxy(string addr_ip, int addr_port, int local_port)
{
if (this.InvokeRequired)
{
this.Invoke(new NTFCBNewProxy(this.NewProxy), addr_ip, addr_port, local_port);
}
else
{
this.listView1.Items.Add(new ListViewItem(local_port.ToString())
{
SubItems =
{
$"{addr_ip}:{addr_port}",
""
}
});
this._TotalProxies++;
this.toolStripStatusLabel2.Text = this._TotalProxies.ToString();
}
}
private void DeadProxy(int local_port)
{
if (this.InvokeRequired)
{
this.Invoke(new NTFCBDeadProxy(this.DeadProxy), local_port);
}
else
{
foreach (ListViewItem item in this.listView1.Items)
{
if (int.Parse(item.Text) == local_port)
{
this.listView1.Items.Remove(item);
this._TotalProxies--;
this.toolStripStatusLabel2.Text = this._TotalProxies.ToString();
break;
}
}
}
}
private void InUseProxy(int local_port)
{
if (this.InvokeRequired)
{
this.Invoke(new NTFCBInUse(this.InUseProxy), local_port);
}
else
{
foreach (ListViewItem item in this.listView1.Items)
{
if (int.Parse(item.Text) == local_port)
{
this.listView1.MarkUsage(item);
break;
}
}
}
}
private void buildProxyToolStripMenuItem_Click(object sender, EventArgs e)
{
using (Form3 form3 = new Form3())
{
form3.ShowDialog();
}
}
private void startToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.startToolStripMenuItem.Text == "Start")
{
using (Form2 form2 = new Form2())
{
if (form2.ShowDialog() == DialogResult.OK)
{
var proxyConfig = new ProxyConfig
{
pclient_port = form2.ClientPort,
pp_start = form2.LocalStartPort,
pp_end = form2.LocalEndPort
};
int result = ProxyListenerStart(ref proxyConfig, ref this._PN);
if (result != 0)
{
MessageBox.Show($"Error {result}");
}
else
{
this.startToolStripMenuItem.Text = "Stop";
}
}
}
}
else
{
ProxyListenerStop();
this.startToolStripMenuItem.Text = "Start";
this.listView1.Items.Clear();
this.toolStripStatusLabel2.Text = "0";
}
}
private delegate void NTFCBNewProxy(string addr_ip, int addr_port, int local_port);
private delegate void NTFCBDeadProxy(int local_port);
private delegate void NTFCBInUse(int local_port);
private struct ProxyNotifications
{
public NTFCBNewProxy newproxy;
public NTFCBDeadProxy deadproxy;
public NTFCBInUse inuse;
}
private struct ProxyConfig
{
public int pclient_port;
public int pp_start;
public int pp_end;
}
}
}