-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathMain.cs
439 lines (382 loc) · 14.7 KB
/
Main.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
434
435
436
437
438
439
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Linq;
using CSHexStringByteArrayConverter;
using CSProcessLayer;
using CSFileLayer;
using CSRegexStringLayer;
namespace RadioEye
{
public partial class Main : Form
{
private delegate void InvokeInsertItemDelegate(byte[] btBuf);
private ProcessLayer pl;
private string[] KeyList;
private string Uid;
public Main(string szDevice)
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
Device.Text = "Device Info: " + szDevice;
pl = new ProcessLayer(ProcStatus, txt_Log);
}
private void chk_Mode_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
{
txt_Id.ReadOnly = false;
btn_ReadId.Enabled = false;
btn_WriteId.Enabled = true;
}
else
{
txt_Id.ReadOnly = true;
btn_ReadId.Enabled = true;
btn_WriteId.Enabled = false;
}
}
private void btn_ReadId_Click(object sender, EventArgs e)
{
if (pl.AsyncStart("nfc/nfc-list.exe", "", GetUid) == false)
{
MessageBox.Show("已存在工作线程");
return;
}
}
private void GetUid(string sExecResultTmp, int ExitCode)
{
string[] RegexRet = RegexStringLayer.GetSubString(sExecResultTmp, "UID \\(\\S*\\): ((\\S\\S\\s\\s){4})");
txt_Id.Text = Uid = RegexRet[0].Replace(" ", "").ToString().ToUpper();
}
private void GetUidToCrack(string sExecResultTmp, int ExitCode)
{
GetUid(sExecResultTmp, ExitCode);
if (string.IsNullOrEmpty(Uid))
{
if (pl.m_RetErrorMsg != null && pl.m_RetErrorMsg.Length != 0)
{
MessageBox.Show(pl.m_RetErrorMsg);
}
else
{
MessageBox.Show("Can not get the UID of the card");
}
return;
}
if (FileLayer.Exists("key/" + Uid + ".dump"))
{
byte[] btBuf = FileLayer.Read("key/" + Uid + ".dump");
if (btBuf == null)
{
if (pl.m_RetErrorMsg != null && pl.m_RetErrorMsg.Length != 0)
{
MessageBox.Show(pl.m_RetErrorMsg);
}
else
{
if (pl.AsyncStart("nfc/mfoc.exe", "-P " + ud_Probe.Value.ToString() + " -T " + ud_distance.Value.ToString() + " -O key/" + Uid + ".dump", GetData) == false)
{
MessageBox.Show("已存在工作线程");
return;
}
}
return;
}
List<string> KeyListTmp = new List<string>();
for (int i = 0; i < 64; i++)
{
byte[] btBufTmp = new byte[6];
Buffer.BlockCopy(btBuf, 64 * i + 48, btBufTmp, 0, 6);
KeyListTmp.Add(HexStringByteArrayConverter.BytesToHexString(btBufTmp));
Buffer.BlockCopy(btBuf, 64 * i + 58, btBufTmp, 0, 6);
KeyListTmp.Add(HexStringByteArrayConverter.BytesToHexString(btBufTmp));
}
KeyListTmp = KeyListTmp.Distinct().ToList();
StringBuilder sbKeyArgv = new StringBuilder();
foreach (string item in KeyListTmp)
{
sbKeyArgv.Append(" -k ");
sbKeyArgv.Append(item);
}
if (pl.AsyncStart("nfc/mfoc.exe", sbKeyArgv.ToString() + " -P " + ud_Probe.Value.ToString() + " -T " + ud_distance.Value.ToString() + " -O key/tmp.dump", GetData) == false)
{
MessageBox.Show("已存在工作线程");
return;
}
}
else
{
if (pl.AsyncStart("nfc/mfoc.exe", "-P " + ud_Probe.Value.ToString() + " -T " + ud_distance.Value.ToString() + " -O key/" + Uid + ".dump", GetData) == false)
{
MessageBox.Show("已存在工作线程");
return;
}
}
}
private void GetData(string sExecResultTmp, int ExitCode)
{
if (ExitCode != 0)
{
if (pl.m_RetErrorMsg != null && pl.m_RetErrorMsg.Length != 0)
{
MessageBox.Show(pl.m_RetErrorMsg);
}
else
{
MessageBox.Show("Crack Failed");
}
return;
}
GetUid(sExecResultTmp, ExitCode);
byte[] btBuf = FileLayer.Read("key/" + Uid + ".dump");
if (btBuf == null)
{
if (pl.m_RetErrorMsg != null && pl.m_RetErrorMsg.Length != 0)
{
MessageBox.Show(pl.m_RetErrorMsg);
}
else
{
MessageBox.Show("Crack Failed");
}
return;
}
InvokeInsertItemDelegate iiid = new InvokeInsertItemDelegate(InvokeInsertItem);
this.BeginInvoke(iiid, new object[] {btBuf});
lb_source.Text = "Card Reader";
}
void InvokeInsertItem(byte[] btBuf)
{
dgv_DumpData.Rows.Clear();
string szBuf = HexStringByteArrayConverter.BytesToHexString(btBuf);
for (int i = 0; i < 64; i++)
{
dgv_DumpData.Rows.Add();
dgv_DumpData.Rows[i].Cells[0].Value = i.ToString();
dgv_DumpData.Rows[i].Cells[1].Value = szBuf.Substring(128 * i + 0, 32);
dgv_DumpData.Rows[i].Cells[2].Value = szBuf.Substring(128 * i + 32, 32);
dgv_DumpData.Rows[i].Cells[3].Value = szBuf.Substring(128 * i + 64, 32);
dgv_DumpData.Rows[i].Cells[4].Value = szBuf.Substring(128 * i + 96, 12);
dgv_DumpData.Rows[i].Cells[5].Value = szBuf.Substring(128 * i + 116, 12);
dgv_DumpData.Rows[i].Cells[6].Value = szBuf.Substring(128 * i + 108, 8);
}
}
private void GetDataFromFile(string sFilePath)
{
byte[] btBuf = FileLayer.ReadWhileFixDump(sFilePath);
if (btBuf == null)
{
MessageBox.Show("不是标准4K/1K.Dump文件");
return;
}
InvokeInsertItem(btBuf);
lb_source.Text = sFilePath;
}
private void btn_Crack_Click(object sender, EventArgs e)
{
if (chk_Key.Checked)
{
StringBuilder sbKeyArgv = new StringBuilder();
foreach (string item in KeyList)
{
sbKeyArgv.Append(" -k ");
sbKeyArgv.Append(item);
}
if (pl.AsyncStart("nfc/mfoc.exe", sbKeyArgv.ToString() + " -P " + ud_Probe.Value.ToString() + " -T " + ud_distance.Value.ToString() + " -O key/tmp.dump", GetData) == false)
{
MessageBox.Show("已存在工作线程");
return;
}
}
else
{
if (pl.AsyncStart("nfc/nfc-list.exe", "", GetUidToCrack, false) == false)
//if (pbl.Start("nfc/mfoc.exe", "-P " + ud_Probe.Value.ToString() + " -T " + ud_distance.Value.ToString() + " -O key/tmp.dump", GetData) == false)
{
MessageBox.Show("已存在工作线程");
return;
}
}
}
private void btn_WriteId_Click(object sender, EventArgs e)
{
if (!RegexStringLayer.CheckMatch(txt_Id.Text, @"^[0-9a-fA-F]{8}$"))
{
MessageBox.Show("请输入一个8位的16进制UID值!");
return;
}
if (pl.AsyncStart("nfc/nfc-mfsetuid.exe", "-f " + txt_Id.Text) == false)
{
MessageBox.Show("已存在工作线程");
}
}
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
if (pl.IdleCheck() == false)
{
if (MessageBox.Show("存在工作线程,是否强制结束?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
pl.Kill();
}
else
{
e.Cancel = true;
}
}
}
private void txt_Id_KeyPress(object sender, KeyPressEventArgs e)
{
if (((e.KeyChar < '0' || e.KeyChar > '9') && (e.KeyChar < 'a' || e.KeyChar > 'f') && (e.KeyChar < 'A' || e.KeyChar > 'F') && e.KeyChar != 8) || (e.KeyChar != 8 && ((TextBox)(sender)).Text.Length >= 8))
{
e.Handled = true;
}
}
private void btn_Open_Click(object sender, EventArgs e)
{
openFileDialog.Filter = "(*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string FileName = openFileDialog.FileName;
GetDataFromFile(FileName);
}
}
private byte[] GetGridViewData()
{
if (dgv_DumpData.Rows.Count != 64)
{
return null;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 64; i++)
{
sb.Append(dgv_DumpData.Rows[i].Cells[1].Value.ToString());
sb.Append(dgv_DumpData.Rows[i].Cells[2].Value.ToString());
sb.Append(dgv_DumpData.Rows[i].Cells[3].Value.ToString());
sb.Append(dgv_DumpData.Rows[i].Cells[4].Value.ToString());
sb.Append(dgv_DumpData.Rows[i].Cells[6].Value.ToString());
sb.Append(dgv_DumpData.Rows[i].Cells[5].Value.ToString());
}
return HexStringByteArrayConverter.HexStringToBytes(sb.ToString());
}
private void btn_Export2File_Click(object sender, EventArgs e)
{
if (dgv_DumpData.Rows.Count != 64)
{
return;
}
if (saveFileDialog.ShowDialog() != DialogResult.OK)
{
return;
}
FileLayer.Write(saveFileDialog.FileName, GetGridViewData());
MessageBox.Show("保存到文件 [" + saveFileDialog.FileName.Substring(saveFileDialog.FileName.LastIndexOf("\\") + 1) + "] 成功!");
}
private void btn_DownloadNet_Click(object sender, EventArgs e)
{
List DownloadDlg = new List();
if (DownloadDlg.ShowDialog() == DialogResult.OK)
{
InvokeInsertItem(DownloadDlg.RetBytes);
lb_source.Text = "Net Storage <" + DownloadDlg.szSource + ">";
}
}
private void dgv_DumpData_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0 || e.ColumnIndex < 1)
{
return;
}
Modify ModifyDlg = new Modify("Sector" + dgv_DumpData.Rows[e.RowIndex].Cells[0].Value.ToString(), dgv_DumpData.Columns[e.ColumnIndex].HeaderText, dgv_DumpData.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
if (ModifyDlg.ShowDialog() == DialogResult.OK)
{
if (ModifyDlg.szDumpData.Equals(dgv_DumpData.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) == false)
{
dgv_DumpData.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ModifyDlg.szDumpData;
dgv_DumpData.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Yellow;
}
}
}
private void btn_UploadNet_Click(object sender, EventArgs e)
{
if (dgv_DumpData.Rows.Count != 64)
{
return;
}
Upload UploadDlg = new Upload(dgv_DumpData.Rows[0].Cells[1].Value.ToString().Substring(0, 8), Convert.ToBase64String(GetGridViewData()));
UploadDlg.ShowDialog();
}
private void btn_WriteC_Click(object sender, EventArgs e)
{
if (dgv_DumpData.Rows.Count != 64)
{
return;
}
FileLayer.Write("key/tmp.dump", GetGridViewData());
StringBuilder szArgv = new StringBuilder();
szArgv.Append("w ");
if (rb_KeyA.Checked)
{
szArgv.Append("a ");
}
else
{
szArgv.Append("b ");
}
szArgv.Append(" key/tmp.dump key/tmp.dump");
if (pl.AsyncStart("nfc/nfc-mfclassic.exe", szArgv.ToString()) == false)
{
MessageBox.Show("已存在工作线程");
return;
}
}
private void btn_WriteU_Click(object sender, EventArgs e)
{
if (dgv_DumpData.Rows.Count != 64)
{
return;
}
FileLayer.Write("key/tmp.dump", GetGridViewData());
StringBuilder szArgv = new StringBuilder();
szArgv.Append("W ");
if (rb_KeyA.Checked)
{
szArgv.Append("a ");
}
else
{
szArgv.Append("b ");
}
szArgv.Append(" key/tmp.dump key/tmp.dump");
if (pl.AsyncStart("nfc/nfc-mfclassic.exe", szArgv.ToString()) == false)
{
MessageBox.Show("已存在工作线程");
return;
}
}
private void chk_Key_CheckedChanged(object sender, EventArgs e)
{
if (chk_Key.Checked)
{
btn_KeyList.Enabled = true;
}
else
{
btn_KeyList.Enabled = false;
}
}
private void btn_KeyList_Click(object sender, EventArgs e)
{
Key KeyDlg = new Key(KeyList, dgv_DumpData);
if (KeyDlg.ShowDialog() == DialogResult.OK)
{
KeyList = KeyDlg.m_KeyList;
return;
}
}
}
}