diff --git a/MifareOneTool.sln b/MifareOneTool.sln index c2d872a..80faf27 100644 --- a/MifareOneTool.sln +++ b/MifareOneTool.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MifareOneTool", "MifareOneTool\MifareOneTool.csproj", "{CDB26016-FC77-403F-B22A-A011F8622FCF}" EndProject -Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup1", "Setup1\Setup1.vdproj", "{989F68A9-CDD0-46FE-9A86-E36F581A3F7E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,22 +27,6 @@ Global {CDB26016-FC77-403F-B22A-A011F8622FCF}.Release|Win32.ActiveCfg = Release|x86 {CDB26016-FC77-403F-B22A-A011F8622FCF}.Release|x86.ActiveCfg = Release|x86 {CDB26016-FC77-403F-B22A-A011F8622FCF}.Release|x86.Build.0 = Release|x86 - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Debug|Any CPU.ActiveCfg = Debug - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Debug|Any CPU.Build.0 = Debug - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Debug|Mixed Platforms.ActiveCfg = Debug - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Debug|Mixed Platforms.Build.0 = Debug - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Debug|Win32.ActiveCfg = Debug - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Debug|Win32.Build.0 = Debug - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Debug|x86.ActiveCfg = Debug - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Debug|x86.Build.0 = Debug - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Release|Any CPU.ActiveCfg = Release - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Release|Any CPU.Build.0 = Release - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Release|Mixed Platforms.ActiveCfg = Release - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Release|Mixed Platforms.Build.0 = Release - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Release|Win32.ActiveCfg = Release - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Release|Win32.Build.0 = Release - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Release|x86.ActiveCfg = Release - {989F68A9-CDD0-46FE-9A86-E36F581A3F7E}.Release|x86.Build.0 = Release EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MifareOneTool/ClassMifareS50.cs b/MifareOneTool/ClassMifareS50.cs index f3e7c0d..e2a8ea2 100644 --- a/MifareOneTool/ClassMifareS50.cs +++ b/MifareOneTool/ClassMifareS50.cs @@ -2,50 +2,312 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Security.Cryptography; +using System.IO; namespace MifareOneTool { - class S50Sector + class Utils { - private byte[,] _sector = new byte[4, 16]; - public byte[,] Sector + public static byte[] ReadAC(byte[] ac) + { + byte[] acbits = new byte[4]; + acbits[0] = (byte)(((ac[2] & 0x10) >> 4) + + ((ac[2] & 0x01) << 1) + + ((ac[1] & 0x10) >> 2)); + acbits[1] = (byte)(((ac[2] & 0x20) >> 5) + + ((ac[2] & 0x02)) + + ((ac[1] & 0x20) >> 3)); + acbits[2] = (byte)(((ac[2] & 0x40) >> 6) + + ((ac[2] & 0x04) >> 1) + + ((ac[1] & 0x40) >> 4)); + acbits[3] = (byte)(((ac[2] & 0x80) >> 7) + + ((ac[2] & 0x08) >> 2) + + ((ac[1] & 0x80) >> 5)); + return acbits; + } + public static byte[] ReadRAC(byte[] ac) + { + byte[] acbits = new byte[4]; + for (int i = 0; i < ac.Length; i++) + { + ac[i] = (byte)~ac[i]; + } + acbits[0] = (byte)(((ac[0] & 0x01) <<2) + + ((ac[0] & 0x10) >>3) + + ((ac[1] & 0x01))); + acbits[1] = (byte)(((ac[0] & 0x02) <<1) + + ((ac[0] & 0x20)>>4) + + ((ac[1] & 0x02) >> 1)); + acbits[2] = (byte)(((ac[0] & 0x04)) + + ((ac[0] & 0x40) >> 5) + + ((ac[1] & 0x04) >> 2)); + acbits[3] = (byte)(((ac[0] & 0x08) >>1) + + ((ac[0] & 0x80) >> 6) + + ((ac[1] & 0x08) >> 3)); + return acbits; + } + public static byte[] GenAC(byte[] ac) + { + byte[] acbits = new byte[4]; + acbits[3] = 0x00; + acbits[1] = (byte)((ac[0]<< 2)& 0x10 + | (ac[1] << 3) & 0x20 + | (ac[2] << 4) & 0x40 + | (ac[3]<<5)&0x80); + acbits[2] = (byte)((ac[0]>>1)& 0x01 + | (ac[1]) & 0x02 + | (ac[2] << 1) & 0x04 + | (ac[3]<<2)&0x08); + acbits[2] = (byte)((ac[0] << 4) & 0x10 + | (ac[1] << 5) & 0x20 + | (ac[2] << 6) & 0x40 + | (ac[3] << 7) & 0x80); + for (int i = 0; i < ac.Length; i++) + { + ac[i] = (byte)(ac[i] ^ 0xff); + } + acbits[1] = (byte)((ac[0]) & 0x01 + | (ac[1] << 1) & 0x02 + | (ac[2] << 2) & 0x04 + | (ac[3] << 3) & 0x08); + acbits[0] = (byte)((ac[0]>>2) & 0x01 + | (ac[1] >>1) & 0x02 + | (ac[2]) & 0x04 + | (ac[3] << 1) & 0x08); + acbits[0] = (byte)((ac[0] << 3) & 0x10 + | (ac[1] << 4) & 0x20 + | (ac[2] << 5) & 0x40 + | (ac[3] << 6) & 0x80); + return acbits; + } + } + enum AccessBitsT + { + KeyAW_KeyAR_KeyARW, + keyAW_KeyARW_KeyARW, + Never_KeyAR_KeyAR, + KeyBW_KeyABRKeyBW_KeyBW, + KeyBW_KeyABR_KeyBW, + Never_KeyABRKeyBW_Never, + Never_KeyABR_Never, + Never_KeyABR_Never2 + } + enum AccessBitsD + { + AB_AB_AB_AB, + AB_N_N_AB, + AB_N_N_N, + B_B_N_N, + AB_B_N_N, + B_N_N_N, + AB_B_B_AB, + N_N_N_N + } + class Sector + { + private byte[][] _sector = new byte[4][] { new byte[16], new byte[16], new byte[16], new byte[16], }; + public byte[][] Block { get { return _sector; } set { _sector = value; } } private bool _isSector0 = false; + public bool IsSector0 + { + get { return _isSector0; } + set { _isSector0 = value; } + } public void Wipe() { - if (_isSector0) - { - this._sector = new byte[4, 16]{ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + byte[] zeroBlock = this._sector[0]; + this._sector = new byte[4][]{ + new byte[16]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, + new byte[16]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, + new byte[16]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, + new byte[16]{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0x07,0x80,0x69, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, }; + if (this._isSector0) + { + this._sector[0] = zeroBlock; + } + } + public Sector(bool sector0 = false) + { + this._isSector0 = sector0; + this.Wipe(); + if (sector0) + { + RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); + byte[] uid = new byte[4]; + rng.GetNonZeroBytes(uid); + byte bcc = (byte)(uid[0] ^ uid[1] ^ uid[2] ^ uid[3]); + this._sector[0] = new byte[16] { uid[0], uid[1], uid[2], uid[3], bcc, 0x08, 0x04, 0x00, + 0x62, 0x63, 0x64, 0x65, 0x66,0x67,0x68,0x69 }; + } + } + public Sector(byte[] uid) + { + if(uid.Length!=4){throw new Exception("不恰当的4字节UID长度");} + this._isSector0 = true; + this.Wipe(); + byte bcc = (byte)(uid[0] ^ uid[1] ^ uid[2] ^ uid[3]); + this._sector[0] = new byte[16] { uid[0], uid[1], uid[2], uid[3], bcc, 0x08, 0x04, 0x00, + 0x62, 0x63, 0x64, 0x65, 0x66,0x67,0x68,0x69 }; + } + public int Verify() + { + /* 检验该块内容是否合法 + * 0块:检查BCC + * 非0块:检查访问控制 + * ******** + * 0000:正常 + * 0001:BCC错 + * 0010:访问控制无效 + * 0100:访问控制损坏 + * + */ + int retCode = 0; + if (this._isSector0) + { + byte bc0 = (byte)(_sector[0][0]^_sector[0][1]^_sector[0][2]^_sector[0][3]^_sector[0][4]); + if (bc0 != 0x00) { retCode = retCode | 0x01; } + } + byte[] ac=new byte[4]{_sector[3][6],_sector[3][7],_sector[3][8],_sector[3][9]}; + byte[] acP = Utils.ReadAC(ac); + byte[] acN = Utils.ReadRAC(ac); + if (!Enumerable.SequenceEqual(acP,acN)) + { + retCode = retCode | 0x04; + } + foreach (byte acc in acP) + { + if (acc > 0x08) + { + retCode = retCode | 0x02; + break; + } + } + return retCode; + } + public string Info(int sec) + { + string info = "扇区" + sec.ToString(); + if (Enumerable.SequenceEqual( + new byte[16] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + this._sector[0]) && + Enumerable.SequenceEqual( + new byte[16] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + this._sector[1]) && + Enumerable.SequenceEqual( + new byte[16] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + this._sector[2])) + { + info += " 空扇区"; } else { - this._sector = new byte[4, 16]{ - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, - {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, - 0xFF,0x07,0x80,0x69, - 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, - }; + info += " 有数据"; } - } - public S50Sector(bool sector0 = false) - { - this._isSector0 = sector0; + return info; } } class S50 { + private List _sectors = new List(16); + internal byte[] SectorsRaw + { + get { + byte[] buffer = new byte[1024]; + for (int i = 0; i < 16; i++) + { + for (int j = 0; j < 4; j++) + { + for (int k = 0; k < 16; k++) + { + buffer[i * 64 + j * 16 + k] = this._sectors[i].Block[j][k]; + } + } + } + return buffer; + } + set + { + for (int i = 0; i < 16; i++) + { + for (int j = 0; j < 4; j++) + { + for (int k = 0; k < 16; k++) + { + this._sectors[i].Block[j][k] = value[i * 64 + j * 16 + k]; + } + } + } + } + } + + public List Sectors + { + get { return _sectors; } + set { _sectors = value; } + } + + public S50() + { + _sectors.Capacity = 16; + for (int i = 0; i < 16; i++) + { + if (i == 0) { _sectors.Add(new Sector(true)); } + else { _sectors.Add(new Sector()); } + } + } + public S50(byte[] uid) + { + _sectors.Capacity = 16; + if (uid.Length != 4) { throw new Exception("不恰当的4字节UID长度"); } + for (int i = 0; i < 16; i++) + { + if (i == 0) { _sectors.Add(new Sector(uid)); } + else { _sectors.Add(new Sector()); } + } + } + public void Wipe() + { + for (int i = 0; i < 16; i++) + { + _sectors[i].Wipe(); + } + } + public int[] Verify() + { + int[] ret = new int[17]; + int t = 0; + for (int i = 0; i < 16; i++) + { + ret[i] = _sectors[i].Verify(); + t += ret[i]; + } + ret[16] = t; + return ret; + } + public int Verify(int sector) + { + return _sectors[sector].Verify(); + } + public void LoadFromMfd(string file) + { + if (!File.Exists(file)) { throw new IOException("加载的文件不存在。"); } + if (new FileInfo(file).Length != 1024) { throw new IOException("加载的S50卡文件大小异常。"); } + byte[] loadByte = File.ReadAllBytes(file); + this.Wipe(); + this.SectorsRaw = (byte[])loadByte; + } + public void ExportToMfd(string file) + { + byte[] fileBuffer = this.SectorsRaw; + } } } diff --git a/MifareOneTool/Form1.Designer.cs b/MifareOneTool/Form1.Designer.cs index 0699fc9..f3ca0de 100644 --- a/MifareOneTool/Form1.Designer.cs +++ b/MifareOneTool/Form1.Designer.cs @@ -54,38 +54,47 @@ this.buttonTool1 = new System.Windows.Forms.Button(); this.toolTipHelp = new System.Windows.Forms.ToolTip(this.components); this.groupBox4 = new System.Windows.Forms.GroupBox(); - this.buttonCmfWrite = new System.Windows.Forms.Button(); - this.buttonLockUfuid = new System.Windows.Forms.Button(); + this.buttonEnAcr122u = new System.Windows.Forms.Button(); this.buttonMfFormat = new System.Windows.Forms.Button(); + this.buttonLockUfuid = new System.Windows.Forms.Button(); + this.buttonCmfWrite = new System.Windows.Forms.Button(); this.tabControl1 = new System.Windows.Forms.TabControl(); - this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage2 = new System.Windows.Forms.TabPage(); - this.groupBox5 = new System.Windows.Forms.GroupBox(); - this.buttonEMfoc = new System.Windows.Forms.Button(); - this.buttonEMfRead = new System.Windows.Forms.Button(); - this.buttonECmfoc = new System.Windows.Forms.Button(); - this.groupBox6 = new System.Windows.Forms.GroupBox(); - this.buttonEscan = new System.Windows.Forms.Button(); - this.buttoEScanCard = new System.Windows.Forms.Button(); - this.buttonESelectKey = new System.Windows.Forms.Button(); - this.buttonEUpdate = new System.Windows.Forms.Button(); + this.buttonEAdv = new System.Windows.Forms.Button(); this.groupBox7 = new System.Windows.Forms.GroupBox(); this.buttonECuidWrite = new System.Windows.Forms.Button(); this.buttonEUIDWrite = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.buttonEMfWrite = new System.Windows.Forms.Button(); - this.buttonEAdv = new System.Windows.Forms.Button(); - this.buttonEnAcr122u = new System.Windows.Forms.Button(); + this.groupBox6 = new System.Windows.Forms.GroupBox(); + this.buttonEUpdate = new System.Windows.Forms.Button(); + this.buttoEScanCard = new System.Windows.Forms.Button(); + this.buttonEscan = new System.Windows.Forms.Button(); + this.groupBox5 = new System.Windows.Forms.GroupBox(); + this.buttonESelectKey = new System.Windows.Forms.Button(); + this.buttonECmfoc = new System.Windows.Forms.Button(); + this.buttonEMfRead = new System.Windows.Forms.Button(); + this.buttonEMfoc = new System.Windows.Forms.Button(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.statusLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.runTimeLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.localVersionLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.remoteVersionLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.buttonCheckEncrypt = new System.Windows.Forms.Button(); + this.buttonECheckEncrypt = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.tabControl1.SuspendLayout(); - this.tabPage1.SuspendLayout(); this.tabPage2.SuspendLayout(); - this.groupBox5.SuspendLayout(); - this.groupBox6.SuspendLayout(); this.groupBox7.SuspendLayout(); + this.groupBox6.SuspendLayout(); + this.groupBox5.SuspendLayout(); + this.tabPage1.SuspendLayout(); + this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // // groupBox1 @@ -152,7 +161,7 @@ this.richTextBox1.Location = new System.Drawing.Point(12, 219); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.ReadOnly = true; - this.richTextBox1.Size = new System.Drawing.Size(623, 290); + this.richTextBox1.Size = new System.Drawing.Size(623, 300); this.richTextBox1.TabIndex = 1; this.richTextBox1.Text = "Hello,cardman!\n建议点击\"检测\"以加快后续运行速度\n"; // @@ -332,7 +341,6 @@ // // buttonHexTool // - this.buttonHexTool.Enabled = false; this.buttonHexTool.Font = new System.Drawing.Font("宋体", 8.5F); this.buttonHexTool.Location = new System.Drawing.Point(6, 53); this.buttonHexTool.Name = "buttonHexTool"; @@ -340,6 +348,7 @@ this.buttonHexTool.TabIndex = 1; this.buttonHexTool.Text = "Hex工具"; this.buttonHexTool.UseVisualStyleBackColor = true; + this.buttonHexTool.Click += new System.EventHandler(this.buttonHexTool_Click); // // buttonTool1 // @@ -362,6 +371,7 @@ // // groupBox4 // + this.groupBox4.Controls.Add(this.buttonCheckEncrypt); this.groupBox4.Controls.Add(this.buttonEnAcr122u); this.groupBox4.Controls.Add(this.buttonMfFormat); this.groupBox4.Controls.Add(this.buttonLockUfuid); @@ -376,25 +386,15 @@ this.groupBox4.TabStop = false; this.groupBox4.Text = "工具"; // - // buttonCmfWrite + // buttonEnAcr122u // - this.buttonCmfWrite.Location = new System.Drawing.Point(198, 23); - this.buttonCmfWrite.Name = "buttonCmfWrite"; - this.buttonCmfWrite.Size = new System.Drawing.Size(75, 23); - this.buttonCmfWrite.TabIndex = 4; - this.buttonCmfWrite.Text = "CUID写"; - this.buttonCmfWrite.UseVisualStyleBackColor = true; - this.buttonCmfWrite.Click += new System.EventHandler(this.buttonCmfWrite_Click); - // - // buttonLockUfuid - // - this.buttonLockUfuid.Location = new System.Drawing.Point(198, 52); - this.buttonLockUfuid.Name = "buttonLockUfuid"; - this.buttonLockUfuid.Size = new System.Drawing.Size(75, 23); - this.buttonLockUfuid.TabIndex = 5; - this.buttonLockUfuid.Text = "锁Ufuid"; - this.buttonLockUfuid.UseVisualStyleBackColor = true; - this.buttonLockUfuid.Click += new System.EventHandler(this.buttonLockUfuid_Click); + this.buttonEnAcr122u.Location = new System.Drawing.Point(279, 52); + this.buttonEnAcr122u.Name = "buttonEnAcr122u"; + this.buttonEnAcr122u.Size = new System.Drawing.Size(156, 23); + this.buttonEnAcr122u.TabIndex = 7; + this.buttonEnAcr122u.Text = "启用ACR122U支持"; + this.buttonEnAcr122u.UseVisualStyleBackColor = true; + this.buttonEnAcr122u.Click += new System.EventHandler(this.buttonEnAcr122u_Click); // // buttonMfFormat // @@ -406,6 +406,26 @@ this.buttonMfFormat.UseVisualStyleBackColor = true; this.buttonMfFormat.Click += new System.EventHandler(this.buttonMfFormat_Click); // + // buttonLockUfuid + // + this.buttonLockUfuid.Location = new System.Drawing.Point(198, 52); + this.buttonLockUfuid.Name = "buttonLockUfuid"; + this.buttonLockUfuid.Size = new System.Drawing.Size(75, 23); + this.buttonLockUfuid.TabIndex = 5; + this.buttonLockUfuid.Text = "锁Ufuid"; + this.buttonLockUfuid.UseVisualStyleBackColor = true; + this.buttonLockUfuid.Click += new System.EventHandler(this.buttonLockUfuid_Click); + // + // buttonCmfWrite + // + this.buttonCmfWrite.Location = new System.Drawing.Point(198, 23); + this.buttonCmfWrite.Name = "buttonCmfWrite"; + this.buttonCmfWrite.Size = new System.Drawing.Size(75, 23); + this.buttonCmfWrite.TabIndex = 4; + this.buttonCmfWrite.Text = "CUID写"; + this.buttonCmfWrite.UseVisualStyleBackColor = true; + this.buttonCmfWrite.Click += new System.EventHandler(this.buttonCmfWrite_Click); + // // tabControl1 // this.tabControl1.Controls.Add(this.tabPage2); @@ -416,20 +436,6 @@ this.tabControl1.Size = new System.Drawing.Size(640, 212); this.tabControl1.TabIndex = 11; // - // tabPage1 - // - this.tabPage1.Controls.Add(this.groupBox1); - this.tabPage1.Controls.Add(this.groupBox4); - this.tabPage1.Controls.Add(this.groupBox2); - this.tabPage1.Controls.Add(this.groupBox3); - this.tabPage1.Location = new System.Drawing.Point(4, 25); - this.tabPage1.Name = "tabPage1"; - this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(632, 183); - this.tabPage1.TabIndex = 0; - this.tabPage1.Text = "高级操作模式"; - this.tabPage1.UseVisualStyleBackColor = true; - // // tabPage2 // this.tabPage2.Controls.Add(this.buttonEAdv); @@ -444,100 +450,15 @@ this.tabPage2.Text = "复制卡模式"; this.tabPage2.UseVisualStyleBackColor = true; // - // groupBox5 + // buttonEAdv // - this.groupBox5.Controls.Add(this.buttonESelectKey); - this.groupBox5.Controls.Add(this.buttonECmfoc); - this.groupBox5.Controls.Add(this.buttonEMfRead); - this.groupBox5.Controls.Add(this.buttonEMfoc); - this.groupBox5.Location = new System.Drawing.Point(140, 6); - this.groupBox5.Name = "groupBox5"; - this.groupBox5.Size = new System.Drawing.Size(128, 171); - this.groupBox5.TabIndex = 0; - this.groupBox5.TabStop = false; - this.groupBox5.Text = "[2]读取原卡"; - // - // buttonEMfoc - // - this.buttonEMfoc.Location = new System.Drawing.Point(6, 25); - this.buttonEMfoc.Name = "buttonEMfoc"; - this.buttonEMfoc.Size = new System.Drawing.Size(116, 25); - this.buttonEMfoc.TabIndex = 0; - this.buttonEMfoc.Text = "[1]半加密破解"; - this.buttonEMfoc.UseVisualStyleBackColor = true; - this.buttonEMfoc.Click += new System.EventHandler(this.buttonEMfoc_Click); - // - // buttonEMfRead - // - this.buttonEMfRead.Location = new System.Drawing.Point(6, 140); - this.buttonEMfRead.Name = "buttonEMfRead"; - this.buttonEMfRead.Size = new System.Drawing.Size(116, 25); - this.buttonEMfRead.TabIndex = 1; - this.buttonEMfRead.Text = "已知密钥读"; - this.buttonEMfRead.UseVisualStyleBackColor = true; - this.buttonEMfRead.Click += new System.EventHandler(this.button2_Click); - // - // buttonECmfoc - // - this.buttonECmfoc.Location = new System.Drawing.Point(6, 80); - this.buttonECmfoc.Name = "buttonECmfoc"; - this.buttonECmfoc.Size = new System.Drawing.Size(116, 25); - this.buttonECmfoc.TabIndex = 2; - this.buttonECmfoc.Text = "知一密破解"; - this.buttonECmfoc.UseVisualStyleBackColor = true; - this.buttonECmfoc.Click += new System.EventHandler(this.buttonECmfoc_Click); - // - // groupBox6 - // - this.groupBox6.Controls.Add(this.buttonEUpdate); - this.groupBox6.Controls.Add(this.buttoEScanCard); - this.groupBox6.Controls.Add(this.buttonEscan); - this.groupBox6.Location = new System.Drawing.Point(6, 6); - this.groupBox6.Name = "groupBox6"; - this.groupBox6.Size = new System.Drawing.Size(128, 171); - this.groupBox6.TabIndex = 3; - this.groupBox6.TabStop = false; - this.groupBox6.Text = "[1]检测"; - // - // buttonEscan - // - this.buttonEscan.Location = new System.Drawing.Point(6, 25); - this.buttonEscan.Name = "buttonEscan"; - this.buttonEscan.Size = new System.Drawing.Size(116, 25); - this.buttonEscan.TabIndex = 0; - this.buttonEscan.Text = "[1]检测连接"; - this.buttonEscan.UseVisualStyleBackColor = true; - this.buttonEscan.Click += new System.EventHandler(this.buttonEscan_Click); - // - // buttoEScanCard - // - this.buttoEScanCard.Location = new System.Drawing.Point(6, 56); - this.buttoEScanCard.Name = "buttoEScanCard"; - this.buttoEScanCard.Size = new System.Drawing.Size(116, 25); - this.buttoEScanCard.TabIndex = 1; - this.buttoEScanCard.Text = "[2]扫描卡片"; - this.buttoEScanCard.UseVisualStyleBackColor = true; - this.buttoEScanCard.Click += new System.EventHandler(this.buttoEScanCard_Click); - // - // buttonESelectKey - // - this.buttonESelectKey.Location = new System.Drawing.Point(6, 109); - this.buttonESelectKey.Name = "buttonESelectKey"; - this.buttonESelectKey.Size = new System.Drawing.Size(116, 25); - this.buttonESelectKey.TabIndex = 2; - this.buttonESelectKey.Text = "加载密钥…"; - this.buttonESelectKey.UseVisualStyleBackColor = true; - this.buttonESelectKey.Click += new System.EventHandler(this.buttonESelectKey_Click); - // - // buttonEUpdate - // - this.buttonEUpdate.Location = new System.Drawing.Point(6, 140); - this.buttonEUpdate.Name = "buttonEUpdate"; - this.buttonEUpdate.Size = new System.Drawing.Size(116, 25); - this.buttonEUpdate.TabIndex = 4; - this.buttonEUpdate.Text = "检查M1T更新"; - this.buttonEUpdate.UseVisualStyleBackColor = true; - this.buttonEUpdate.Click += new System.EventHandler(this.buttonEUpdate_Click); + this.buttonEAdv.Location = new System.Drawing.Point(408, 16); + this.buttonEAdv.Name = "buttonEAdv"; + this.buttonEAdv.Size = new System.Drawing.Size(218, 40); + this.buttonEAdv.TabIndex = 4; + this.buttonEAdv.Text = "点此进入高级模式>>>"; + this.buttonEAdv.UseVisualStyleBackColor = true; + this.buttonEAdv.Click += new System.EventHandler(this.buttonEAdv_Click); // // groupBox7 // @@ -591,31 +512,187 @@ this.buttonEMfWrite.UseVisualStyleBackColor = true; this.buttonEMfWrite.Click += new System.EventHandler(this.buttonEMfWrite_Click); // - // buttonEAdv + // groupBox6 // - this.buttonEAdv.Location = new System.Drawing.Point(408, 16); - this.buttonEAdv.Name = "buttonEAdv"; - this.buttonEAdv.Size = new System.Drawing.Size(218, 40); - this.buttonEAdv.TabIndex = 4; - this.buttonEAdv.Text = "点此进入高级模式>>>"; - this.buttonEAdv.UseVisualStyleBackColor = true; - this.buttonEAdv.Click += new System.EventHandler(this.buttonEAdv_Click); + this.groupBox6.Controls.Add(this.buttonECheckEncrypt); + this.groupBox6.Controls.Add(this.buttonEUpdate); + this.groupBox6.Controls.Add(this.buttoEScanCard); + this.groupBox6.Controls.Add(this.buttonEscan); + this.groupBox6.Location = new System.Drawing.Point(6, 6); + this.groupBox6.Name = "groupBox6"; + this.groupBox6.Size = new System.Drawing.Size(128, 171); + this.groupBox6.TabIndex = 3; + this.groupBox6.TabStop = false; + this.groupBox6.Text = "[1]检测"; // - // buttonEnAcr122u + // buttonEUpdate // - this.buttonEnAcr122u.Location = new System.Drawing.Point(279, 52); - this.buttonEnAcr122u.Name = "buttonEnAcr122u"; - this.buttonEnAcr122u.Size = new System.Drawing.Size(164, 23); - this.buttonEnAcr122u.TabIndex = 7; - this.buttonEnAcr122u.Text = "启用ACR122U支持"; - this.buttonEnAcr122u.UseVisualStyleBackColor = true; - this.buttonEnAcr122u.Click += new System.EventHandler(this.buttonEnAcr122u_Click); + this.buttonEUpdate.Location = new System.Drawing.Point(6, 140); + this.buttonEUpdate.Name = "buttonEUpdate"; + this.buttonEUpdate.Size = new System.Drawing.Size(116, 25); + this.buttonEUpdate.TabIndex = 4; + this.buttonEUpdate.Text = "检查M1T更新"; + this.buttonEUpdate.UseVisualStyleBackColor = true; + this.buttonEUpdate.Click += new System.EventHandler(this.buttonEUpdate_Click); + // + // buttoEScanCard + // + this.buttoEScanCard.Location = new System.Drawing.Point(6, 56); + this.buttoEScanCard.Name = "buttoEScanCard"; + this.buttoEScanCard.Size = new System.Drawing.Size(116, 25); + this.buttoEScanCard.TabIndex = 1; + this.buttoEScanCard.Text = "[2]扫描卡片"; + this.buttoEScanCard.UseVisualStyleBackColor = true; + this.buttoEScanCard.Click += new System.EventHandler(this.buttoEScanCard_Click); + // + // buttonEscan + // + this.buttonEscan.Location = new System.Drawing.Point(6, 25); + this.buttonEscan.Name = "buttonEscan"; + this.buttonEscan.Size = new System.Drawing.Size(116, 25); + this.buttonEscan.TabIndex = 0; + this.buttonEscan.Text = "[1]检测连接"; + this.buttonEscan.UseVisualStyleBackColor = true; + this.buttonEscan.Click += new System.EventHandler(this.buttonEscan_Click); + // + // groupBox5 + // + this.groupBox5.Controls.Add(this.buttonESelectKey); + this.groupBox5.Controls.Add(this.buttonECmfoc); + this.groupBox5.Controls.Add(this.buttonEMfRead); + this.groupBox5.Controls.Add(this.buttonEMfoc); + this.groupBox5.Location = new System.Drawing.Point(140, 6); + this.groupBox5.Name = "groupBox5"; + this.groupBox5.Size = new System.Drawing.Size(128, 171); + this.groupBox5.TabIndex = 0; + this.groupBox5.TabStop = false; + this.groupBox5.Text = "[2]读取原卡"; + // + // buttonESelectKey + // + this.buttonESelectKey.Location = new System.Drawing.Point(6, 109); + this.buttonESelectKey.Name = "buttonESelectKey"; + this.buttonESelectKey.Size = new System.Drawing.Size(116, 25); + this.buttonESelectKey.TabIndex = 2; + this.buttonESelectKey.Text = "加载密钥…"; + this.buttonESelectKey.UseVisualStyleBackColor = true; + this.buttonESelectKey.Click += new System.EventHandler(this.buttonESelectKey_Click); + // + // buttonECmfoc + // + this.buttonECmfoc.Location = new System.Drawing.Point(6, 80); + this.buttonECmfoc.Name = "buttonECmfoc"; + this.buttonECmfoc.Size = new System.Drawing.Size(116, 25); + this.buttonECmfoc.TabIndex = 2; + this.buttonECmfoc.Text = "知一密破解"; + this.buttonECmfoc.UseVisualStyleBackColor = true; + this.buttonECmfoc.Click += new System.EventHandler(this.buttonECmfoc_Click); + // + // buttonEMfRead + // + this.buttonEMfRead.Location = new System.Drawing.Point(6, 140); + this.buttonEMfRead.Name = "buttonEMfRead"; + this.buttonEMfRead.Size = new System.Drawing.Size(116, 25); + this.buttonEMfRead.TabIndex = 1; + this.buttonEMfRead.Text = "已知密钥读"; + this.buttonEMfRead.UseVisualStyleBackColor = true; + this.buttonEMfRead.Click += new System.EventHandler(this.button2_Click); + // + // buttonEMfoc + // + this.buttonEMfoc.Location = new System.Drawing.Point(6, 25); + this.buttonEMfoc.Name = "buttonEMfoc"; + this.buttonEMfoc.Size = new System.Drawing.Size(116, 25); + this.buttonEMfoc.TabIndex = 0; + this.buttonEMfoc.Text = "[1]半加密破解"; + this.buttonEMfoc.UseVisualStyleBackColor = true; + this.buttonEMfoc.Click += new System.EventHandler(this.buttonEMfoc_Click); + // + // tabPage1 + // + this.tabPage1.Controls.Add(this.groupBox1); + this.tabPage1.Controls.Add(this.groupBox4); + this.tabPage1.Controls.Add(this.groupBox2); + this.tabPage1.Controls.Add(this.groupBox3); + this.tabPage1.Location = new System.Drawing.Point(4, 25); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(632, 183); + this.tabPage1.TabIndex = 0; + this.tabPage1.Text = "高级操作模式"; + this.tabPage1.UseVisualStyleBackColor = true; + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.statusLabel, + this.runTimeLabel, + this.localVersionLabel, + this.remoteVersionLabel}); + this.statusStrip1.Location = new System.Drawing.Point(0, 522); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(649, 26); + this.statusStrip1.TabIndex = 12; + this.statusStrip1.Text = "statusStrip1"; + // + // statusLabel + // + this.statusLabel.AutoSize = false; + this.statusLabel.Name = "statusLabel"; + this.statusLabel.Size = new System.Drawing.Size(60, 21); + this.statusLabel.Text = "就绪"; + // + // runTimeLabel + // + this.runTimeLabel.AutoSize = false; + this.runTimeLabel.Name = "runTimeLabel"; + this.runTimeLabel.Size = new System.Drawing.Size(150, 21); + this.runTimeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // localVersionLabel + // + this.localVersionLabel.Name = "localVersionLabel"; + this.localVersionLabel.Size = new System.Drawing.Size(0, 21); + this.localVersionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // remoteVersionLabel + // + this.remoteVersionLabel.AutoSize = false; + this.remoteVersionLabel.Name = "remoteVersionLabel"; + this.remoteVersionLabel.Size = new System.Drawing.Size(130, 21); + this.remoteVersionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // timer1 + // + this.timer1.Enabled = true; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // buttonCheckEncrypt + // + this.buttonCheckEncrypt.Location = new System.Drawing.Point(360, 23); + this.buttonCheckEncrypt.Name = "buttonCheckEncrypt"; + this.buttonCheckEncrypt.Size = new System.Drawing.Size(75, 23); + this.buttonCheckEncrypt.TabIndex = 13; + this.buttonCheckEncrypt.Text = "检加密"; + this.buttonCheckEncrypt.UseVisualStyleBackColor = true; + this.buttonCheckEncrypt.Click += new System.EventHandler(this.buttonCheckEncrypt_Click); + // + // buttonECheckEncrypt + // + this.buttonECheckEncrypt.Location = new System.Drawing.Point(6, 87); + this.buttonECheckEncrypt.Name = "buttonECheckEncrypt"; + this.buttonECheckEncrypt.Size = new System.Drawing.Size(116, 25); + this.buttonECheckEncrypt.TabIndex = 5; + this.buttonECheckEncrypt.Text = "[3]检测加密"; + this.buttonECheckEncrypt.UseVisualStyleBackColor = true; + this.buttonECheckEncrypt.Click += new System.EventHandler(this.buttonECheckEncrypt_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(649, 521); + this.ClientSize = new System.Drawing.Size(649, 548); + this.Controls.Add(this.statusStrip1); this.Controls.Add(this.tabControl1); this.Controls.Add(this.richTextBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; @@ -629,12 +706,15 @@ this.groupBox3.ResumeLayout(false); this.groupBox4.ResumeLayout(false); this.tabControl1.ResumeLayout(false); - this.tabPage1.ResumeLayout(false); this.tabPage2.ResumeLayout(false); - this.groupBox5.ResumeLayout(false); - this.groupBox6.ResumeLayout(false); this.groupBox7.ResumeLayout(false); + this.groupBox6.ResumeLayout(false); + this.groupBox5.ResumeLayout(false); + this.tabPage1.ResumeLayout(false); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -687,6 +767,14 @@ private System.Windows.Forms.Button buttonEMfWrite; private System.Windows.Forms.Button buttonEAdv; private System.Windows.Forms.Button buttonEnAcr122u; + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripStatusLabel statusLabel; + private System.Windows.Forms.ToolStripStatusLabel runTimeLabel; + private System.Windows.Forms.ToolStripStatusLabel localVersionLabel; + private System.Windows.Forms.ToolStripStatusLabel remoteVersionLabel; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.Button buttonCheckEncrypt; + private System.Windows.Forms.Button buttonECheckEncrypt; } } diff --git a/MifareOneTool/Form1.cs b/MifareOneTool/Form1.cs index fe5757b..3c3acef 100644 --- a/MifareOneTool/Form1.cs +++ b/MifareOneTool/Form1.cs @@ -24,10 +24,12 @@ namespace MifareOneTool private Process process = new Process(); private bool lprocess = false; + private bool running = false; private void buttonListDev_Click(object sender, EventArgs e) { - if (lprocess) { MessageBox.Show("有任务运行中,不可执行。", "设备忙", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Form1.ActiveForm.Text = "MifareOne Tool - 运行中"; + if (lprocess) { MessageBox.Show("有任务运行中,不可执行。", "设备忙", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } + Form1.ActiveForm.Text = "MifareOne Tool - 运行中"; BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += new DoWorkEventHandler(list_dev); bgw.WorkerReportsProgress = true; @@ -49,7 +51,7 @@ namespace MifareOneTool ofd.DefaultExt = ".mfd"; ofd.Title = "请选择MFD文件保存位置及文件名"; ofd.OverwritePrompt = true; - ofd.Filter = "MFD文件|*.mfd"; + ofd.Filter = "MFD文件|*.mfd|DUMP文件|*.dump"; if (File.Exists(omfd) && new FileInfo(omfd).Length > 1) { if (ofd.ShowDialog() == DialogResult.OK) @@ -95,7 +97,7 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; @@ -103,6 +105,7 @@ namespace MifareOneTool process.BeginErrorReadLine(); process.WaitForExit(); lprocess = false; + running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -110,6 +113,7 @@ namespace MifareOneTool { linkLabel1.Links.Add(0, linkLabel1.Text.Length, "https://github.com/xcicode/MifareOneTool/releases/latest"); logAppend("#软件版本 " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); + localVersionLabel.Text="本地版本 " + Assembly.GetExecutingAssembly().GetName().Version.ToString(); } private void buttonScanCard_Click(object sender, EventArgs e) @@ -132,14 +136,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -186,14 +190,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; if (process.ExitCode == 0) { b.ReportProgress(101, "##运行完毕##"); @@ -285,14 +289,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -335,14 +339,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; if (process.ExitCode == 0) { b.ReportProgress(101, "##运行完毕##"); @@ -364,7 +368,7 @@ namespace MifareOneTool bgw.RunWorkerAsync(); } - string hex(byte[] bytes) + public static string hex(byte[] bytes) { StringBuilder ret = new StringBuilder(); foreach (byte b in bytes) @@ -389,14 +393,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -426,14 +430,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -462,14 +466,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; if (process.ExitCode == 0) { b.ReportProgress(101, "##运行完毕##"); @@ -521,14 +525,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -587,14 +591,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -624,7 +628,7 @@ namespace MifareOneTool BackgroundWorker b = (BackgroundWorker)sender; process=Process.Start(psi); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -680,14 +684,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -717,14 +721,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -760,14 +764,14 @@ namespace MifareOneTool psi.RedirectStandardError = true; lprocess = true; BackgroundWorker b = (BackgroundWorker)sender; - process = Process.Start(psi); + process = Process.Start(psi);running=true; process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); //StreamReader stderr = process.StandardError; process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); - lprocess = false; + lprocess = false;running=false; b.ReportProgress(100, "##运行完毕##"); } @@ -863,9 +867,73 @@ namespace MifareOneTool File.Move("nfc-bin/libnfc(ACR122U).dll", "nfc-bin/libnfc.dll"); logAppend("已打开。"); } - lprocess = false; + lprocess = false;running=false; Text = "MifareOne Tool - 运行完毕"; logAppend("##运行完毕##"); } + + private void timer1_Tick(object sender, EventArgs e) + { + if (running) { + statusLabel.Text = "运行中"; + if(process.HasExited==false){ + DateTime now = DateTime.Now; + TimeSpan runtime = now - process.StartTime; + runTimeLabel.Text = "运行时间:"+((int)runtime.TotalSeconds).ToString()+"秒"; + } + } + else { statusLabel.Text = "空闲"; } + } + + private void buttonCheckEncrypt_Click(object sender, EventArgs e) + { + if (lprocess) { MessageBox.Show("有任务运行中,不可执行。", "设备忙", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Form1.ActiveForm.Text = "MifareOne Tool - 运行中"; + BackgroundWorker bgw = new BackgroundWorker(); + bgw.DoWork += new DoWorkEventHandler(MfDetect); + bgw.WorkerReportsProgress = true; + bgw.ProgressChanged += new ProgressChangedEventHandler(default_rpt); + bgw.RunWorkerAsync(); + } + + void MfDetect(object sender, DoWorkEventArgs e) + { + if (lprocess) { return; } + ProcessStartInfo psi = new ProcessStartInfo("nfc-bin/mfdetect.exe"); + psi.Arguments = "-O dummy.tmp"; + psi.CreateNoWindow = true; + psi.UseShellExecute = false; + psi.RedirectStandardOutput = true; + psi.RedirectStandardError = true; + lprocess = true; + BackgroundWorker b = (BackgroundWorker)sender; + process = Process.Start(psi); running = true; + process.OutputDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); + process.ErrorDataReceived += (s, _e) => b.ReportProgress(0, _e.Data); + //StreamReader stderr = process.StandardError; + process.BeginOutputReadLine(); + process.BeginErrorReadLine(); + process.WaitForExit(); + File.Delete("dummy.tmp"); + lprocess = false; running = false; + if (process.ExitCode == 0) + { + b.ReportProgress(100, "##运行完毕##"); + } + else + { + b.ReportProgress(100, "##运行出错##"); + } + } + + private void buttonHexTool_Click(object sender, EventArgs e) + { + FormHTool fht = new FormHTool(); + fht.Show(); + } + + private void buttonECheckEncrypt_Click(object sender, EventArgs e) + { + buttonCheckEncrypt_Click(sender, e); + } } } diff --git a/MifareOneTool/Form1.resx b/MifareOneTool/Form1.resx index 7e534fd..9f65069 100644 --- a/MifareOneTool/Form1.resx +++ b/MifareOneTool/Form1.resx @@ -120,4 +120,16 @@ 17, 17 + + 17, 17 + + + 157, 17 + + + 297, 17 + + + 71 + \ No newline at end of file diff --git a/MifareOneTool/FormHTool.Designer.cs b/MifareOneTool/FormHTool.Designer.cs new file mode 100644 index 0000000..cd19c63 --- /dev/null +++ b/MifareOneTool/FormHTool.Designer.cs @@ -0,0 +1,543 @@ +namespace MifareOneTool +{ + partial class FormHTool + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.打开ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.保存ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.另存为ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.退出ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.工具ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.修改UIDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.检查全卡ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.buttonSaveSectorEdit = new System.Windows.Forms.Button(); + this.comboBox4 = new System.Windows.Forms.ComboBox(); + this.comboBox3 = new System.Windows.Forms.ComboBox(); + this.comboBox2 = new System.Windows.Forms.ComboBox(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.label9 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.keyBEdit = new System.Windows.Forms.TextBox(); + this.keyAEdit = new System.Windows.Forms.TextBox(); + this.block2Edit = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.block1Edit = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.block0Edit = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.labelCurSec = new System.Windows.Forms.Label(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.s50BindingSource = new System.Windows.Forms.BindingSource(this.components); + this.menuStrip1.SuspendLayout(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.groupBox2.SuspendLayout(); + this.groupBox3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.s50BindingSource)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.文件ToolStripMenuItem, + this.工具ToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(838, 28); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // 文件ToolStripMenuItem + // + this.文件ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.打开ToolStripMenuItem, + this.保存ToolStripMenuItem, + this.另存为ToolStripMenuItem, + this.toolStripSeparator1, + this.退出ToolStripMenuItem}); + this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem"; + this.文件ToolStripMenuItem.Size = new System.Drawing.Size(51, 24); + this.文件ToolStripMenuItem.Text = "文件"; + // + // 打开ToolStripMenuItem + // + this.打开ToolStripMenuItem.Name = "打开ToolStripMenuItem"; + this.打开ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); + this.打开ToolStripMenuItem.Size = new System.Drawing.Size(222, 24); + this.打开ToolStripMenuItem.Text = "打开"; + this.打开ToolStripMenuItem.Click += new System.EventHandler(this.打开ToolStripMenuItem_Click); + // + // 保存ToolStripMenuItem + // + this.保存ToolStripMenuItem.Name = "保存ToolStripMenuItem"; + this.保存ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); + this.保存ToolStripMenuItem.Size = new System.Drawing.Size(222, 24); + this.保存ToolStripMenuItem.Text = "保存"; + this.保存ToolStripMenuItem.Click += new System.EventHandler(this.保存ToolStripMenuItem_Click); + // + // 另存为ToolStripMenuItem + // + this.另存为ToolStripMenuItem.Name = "另存为ToolStripMenuItem"; + this.另存为ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift) + | System.Windows.Forms.Keys.S))); + this.另存为ToolStripMenuItem.Size = new System.Drawing.Size(222, 24); + this.另存为ToolStripMenuItem.Text = "另存为"; + this.另存为ToolStripMenuItem.Click += new System.EventHandler(this.另存为ToolStripMenuItem_Click); + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(219, 6); + // + // 退出ToolStripMenuItem + // + this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem"; + this.退出ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.X))); + this.退出ToolStripMenuItem.Size = new System.Drawing.Size(222, 24); + this.退出ToolStripMenuItem.Text = "退出"; + this.退出ToolStripMenuItem.Click += new System.EventHandler(this.退出ToolStripMenuItem_Click); + // + // 工具ToolStripMenuItem + // + this.工具ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.修改UIDToolStripMenuItem, + this.检查全卡ToolStripMenuItem}); + this.工具ToolStripMenuItem.Name = "工具ToolStripMenuItem"; + this.工具ToolStripMenuItem.Size = new System.Drawing.Size(51, 24); + this.工具ToolStripMenuItem.Text = "工具"; + // + // 修改UIDToolStripMenuItem + // + this.修改UIDToolStripMenuItem.Name = "修改UIDToolStripMenuItem"; + this.修改UIDToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U))); + this.修改UIDToolStripMenuItem.Size = new System.Drawing.Size(191, 24); + this.修改UIDToolStripMenuItem.Text = "修改UID"; + // + // 检查全卡ToolStripMenuItem + // + this.检查全卡ToolStripMenuItem.Name = "检查全卡ToolStripMenuItem"; + this.检查全卡ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.J))); + this.检查全卡ToolStripMenuItem.Size = new System.Drawing.Size(191, 24); + this.检查全卡ToolStripMenuItem.Text = "检查全卡"; + this.检查全卡ToolStripMenuItem.Click += new System.EventHandler(this.检查全卡ToolStripMenuItem_Click); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.dataGridView1); + this.groupBox1.Location = new System.Drawing.Point(12, 31); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(250, 409); + this.groupBox1.TabIndex = 1; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "扇区列表"; + // + // dataGridView1 + // + this.dataGridView1.AllowUserToAddRows = false; + this.dataGridView1.AllowUserToDeleteRows = false; + this.dataGridView1.AllowUserToResizeColumns = false; + this.dataGridView1.AllowUserToResizeRows = false; + this.dataGridView1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Column1}); + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView1.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; + this.dataGridView1.Location = new System.Drawing.Point(3, 21); + this.dataGridView1.MultiSelect = false; + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.ReadOnly = true; + this.dataGridView1.RowHeadersWidth = 20; + this.dataGridView1.RowTemplate.Height = 27; + this.dataGridView1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView1.Size = new System.Drawing.Size(244, 385); + this.dataGridView1.TabIndex = 0; + this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick); + // + // Column1 + // + this.Column1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Column1.HeaderText = "扇区"; + this.Column1.Name = "Column1"; + this.Column1.ReadOnly = true; + this.Column1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.buttonSaveSectorEdit); + this.groupBox2.Controls.Add(this.comboBox4); + this.groupBox2.Controls.Add(this.comboBox3); + this.groupBox2.Controls.Add(this.comboBox2); + this.groupBox2.Controls.Add(this.comboBox1); + this.groupBox2.Controls.Add(this.label9); + this.groupBox2.Controls.Add(this.label8); + this.groupBox2.Controls.Add(this.label7); + this.groupBox2.Controls.Add(this.label6); + this.groupBox2.Controls.Add(this.label5); + this.groupBox2.Controls.Add(this.keyBEdit); + this.groupBox2.Controls.Add(this.keyAEdit); + this.groupBox2.Controls.Add(this.block2Edit); + this.groupBox2.Controls.Add(this.label4); + this.groupBox2.Controls.Add(this.label3); + this.groupBox2.Controls.Add(this.block1Edit); + this.groupBox2.Controls.Add(this.label2); + this.groupBox2.Controls.Add(this.block0Edit); + this.groupBox2.Controls.Add(this.label1); + this.groupBox2.Controls.Add(this.labelCurSec); + this.groupBox2.Location = new System.Drawing.Point(268, 31); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(292, 409); + this.groupBox2.TabIndex = 2; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "扇区信息"; + // + // buttonSaveSectorEdit + // + this.buttonSaveSectorEdit.Location = new System.Drawing.Point(186, 16); + this.buttonSaveSectorEdit.Name = "buttonSaveSectorEdit"; + this.buttonSaveSectorEdit.Size = new System.Drawing.Size(100, 25); + this.buttonSaveSectorEdit.TabIndex = 20; + this.buttonSaveSectorEdit.Text = "修改扇区"; + this.buttonSaveSectorEdit.UseVisualStyleBackColor = true; + this.buttonSaveSectorEdit.Click += new System.EventHandler(this.buttonSaveSectorEdit_Click); + // + // comboBox4 + // + this.comboBox4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox4.DropDownWidth = 400; + this.comboBox4.FormattingEnabled = true; + this.comboBox4.Items.AddRange(new object[] { + "[不可逆]KeyA:A写/AC:A只读/KeyB:A读写", + "KeyA:A写/AC:A读写/KeyB:A读写", + "[不可逆]KeyA:不能读写/AC:A只读/KeyB:A读", + "KeyA:B写/AC:A只读B读写/KeyB:B写", + "[不可逆]KeyA:B写/AC:AB只读/KeyB:B写", + "KeyA:不能读写/AC:A只读B读写/KeyB:不能读写", + "[不可逆]KeyA:不能读写/AC:AB只读/KeyB:不能读写", + "[不可逆]KeyA:不能读写/AC:AB只读/KeyB:不能读写(重复了?)"}); + this.comboBox4.Location = new System.Drawing.Point(6, 379); + this.comboBox4.Name = "comboBox4"; + this.comboBox4.Size = new System.Drawing.Size(280, 23); + this.comboBox4.TabIndex = 19; + this.comboBox4.Validating += new System.ComponentModel.CancelEventHandler(this.comboBox1_Validating); + // + // comboBox3 + // + this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox3.FormattingEnabled = true; + this.comboBox3.Items.AddRange(new object[] { + "KeyAB读写及增减值", + "[只读]KeyAB读及减值/不可写及增值", + "[只读]KeyAB读/不可写及增减值", + "KeyB读写/不可增减值", + "KeyAB读/KeyB写/不可增减值", + "[只读]KeyB读/不可写及增减值", + "KeyAB读及减值/KeyB写及增值", + "[只读]锁死该扇区"}); + this.comboBox3.Location = new System.Drawing.Point(6, 335); + this.comboBox3.Name = "comboBox3"; + this.comboBox3.Size = new System.Drawing.Size(280, 23); + this.comboBox3.TabIndex = 18; + this.comboBox3.Validating += new System.ComponentModel.CancelEventHandler(this.comboBox1_Validating); + // + // comboBox2 + // + this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox2.FormattingEnabled = true; + this.comboBox2.Items.AddRange(new object[] { + "KeyAB读写及增减值", + "[只读]KeyAB读及减值/不可写及增值", + "[只读]KeyAB读/不可写及增减值", + "KeyB读写/不可增减值", + "KeyAB读/KeyB写/不可增减值", + "[只读]KeyB读/不可写及增减值", + "KeyAB读及减值/KeyB写及增值", + "[只读]锁死该扇区"}); + this.comboBox2.Location = new System.Drawing.Point(6, 291); + this.comboBox2.Name = "comboBox2"; + this.comboBox2.Size = new System.Drawing.Size(280, 23); + this.comboBox2.TabIndex = 17; + this.comboBox2.Validating += new System.ComponentModel.CancelEventHandler(this.comboBox1_Validating); + // + // comboBox1 + // + this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Items.AddRange(new object[] { + "KeyAB读写及增减值", + "[只读]KeyAB读及减值/不可写及增值", + "[只读]KeyAB读/不可写及增减值", + "KeyB读写/不可增减值", + "KeyAB读/KeyB写/不可增减值", + "[只读]KeyB读/不可写及增减值", + "KeyAB读及减值/KeyB写及增值", + "[只读]锁死该扇区"}); + this.comboBox1.Location = new System.Drawing.Point(6, 247); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(280, 23); + this.comboBox1.TabIndex = 16; + this.comboBox1.Validating += new System.ComponentModel.CancelEventHandler(this.comboBox1_Validating); + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(3, 361); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(117, 15); + this.label9.TabIndex = 15; + this.label9.Text = "Key/ACbits权限"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(6, 317); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(60, 15); + this.label8.TabIndex = 14; + this.label8.Text = "2块权限"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(3, 273); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(60, 15); + this.label7.TabIndex = 13; + this.label7.Text = "1块权限"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(6, 229); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(60, 15); + this.label6.TabIndex = 12; + this.label6.Text = "0块权限"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(166, 183); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(39, 15); + this.label5.TabIndex = 11; + this.label5.Text = "KeyB"; + // + // keyBEdit + // + this.keyBEdit.Location = new System.Drawing.Point(166, 201); + this.keyBEdit.Name = "keyBEdit"; + this.keyBEdit.Size = new System.Drawing.Size(120, 25); + this.keyBEdit.TabIndex = 10; + this.keyBEdit.Validating += new System.ComponentModel.CancelEventHandler(this.keyAEdit_Validating); + // + // keyAEdit + // + this.keyAEdit.Location = new System.Drawing.Point(6, 201); + this.keyAEdit.Name = "keyAEdit"; + this.keyAEdit.Size = new System.Drawing.Size(120, 25); + this.keyAEdit.TabIndex = 9; + this.keyAEdit.Validating += new System.ComponentModel.CancelEventHandler(this.keyAEdit_Validating); + // + // block2Edit + // + this.block2Edit.Location = new System.Drawing.Point(6, 155); + this.block2Edit.Name = "block2Edit"; + this.block2Edit.Size = new System.Drawing.Size(280, 25); + this.block2Edit.TabIndex = 8; + this.block2Edit.Validating += new System.ComponentModel.CancelEventHandler(this.block0Edit_Validating); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(6, 183); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(39, 15); + this.label4.TabIndex = 7; + this.label4.Text = "KeyA"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(6, 137); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(45, 15); + this.label3.TabIndex = 5; + this.label3.Text = "第2块"; + // + // block1Edit + // + this.block1Edit.Location = new System.Drawing.Point(6, 109); + this.block1Edit.Name = "block1Edit"; + this.block1Edit.Size = new System.Drawing.Size(280, 25); + this.block1Edit.TabIndex = 4; + this.block1Edit.Validating += new System.ComponentModel.CancelEventHandler(this.block0Edit_Validating); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 91); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(45, 15); + this.label2.TabIndex = 3; + this.label2.Text = "第1块"; + // + // block0Edit + // + this.block0Edit.Location = new System.Drawing.Point(6, 63); + this.block0Edit.Name = "block0Edit"; + this.block0Edit.Size = new System.Drawing.Size(280, 25); + this.block0Edit.TabIndex = 2; + this.block0Edit.Validating += new System.ComponentModel.CancelEventHandler(this.block0Edit_Validating); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 45); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(45, 15); + this.label1.TabIndex = 1; + this.label1.Text = "第0块"; + // + // labelCurSec + // + this.labelCurSec.AutoSize = true; + this.labelCurSec.Location = new System.Drawing.Point(6, 21); + this.labelCurSec.Name = "labelCurSec"; + this.labelCurSec.Size = new System.Drawing.Size(142, 15); + this.labelCurSec.TabIndex = 0; + this.labelCurSec.Text = "当前选定扇区:??"; + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.richTextBox1); + this.groupBox3.Location = new System.Drawing.Point(566, 31); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(260, 409); + this.groupBox3.TabIndex = 3; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "输出"; + // + // richTextBox1 + // + this.richTextBox1.BackColor = System.Drawing.Color.Black; + this.richTextBox1.ForeColor = System.Drawing.Color.Cyan; + this.richTextBox1.Location = new System.Drawing.Point(6, 24); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.ReadOnly = true; + this.richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical; + this.richTextBox1.Size = new System.Drawing.Size(248, 379); + this.richTextBox1.TabIndex = 0; + this.richTextBox1.Text = "欢迎使用M1T的集成编辑器S50HTool!\n打开文件请点左上角文件-打开或Ctrl+O\n"; + // + // s50BindingSource + // + this.s50BindingSource.DataSource = typeof(MifareOneTool.S50); + // + // FormHTool + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(838, 452); + this.Controls.Add(this.groupBox3); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.menuStrip1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MainMenuStrip = this.menuStrip1; + this.MaximizeBox = false; + this.Name = "FormHTool"; + this.Text = "S50HTool"; + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.groupBox3.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.s50BindingSource)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem 文件ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 打开ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 保存ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 另存为ToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripMenuItem 退出ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 工具ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 修改UIDToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 检查全卡ToolStripMenuItem; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.DataGridViewTextBoxColumn Column1; + private System.Windows.Forms.BindingSource s50BindingSource; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Label labelCurSec; + private System.Windows.Forms.TextBox block0Edit; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox block1Edit; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox keyBEdit; + private System.Windows.Forms.TextBox keyAEdit; + private System.Windows.Forms.TextBox block2Edit; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Button buttonSaveSectorEdit; + private System.Windows.Forms.ComboBox comboBox4; + private System.Windows.Forms.ComboBox comboBox3; + private System.Windows.Forms.ComboBox comboBox2; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.RichTextBox richTextBox1; + } +} \ No newline at end of file diff --git a/MifareOneTool/FormHTool.cs b/MifareOneTool/FormHTool.cs new file mode 100644 index 0000000..885aed8 --- /dev/null +++ b/MifareOneTool/FormHTool.cs @@ -0,0 +1,275 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.IO; +using System.Text.RegularExpressions; + +namespace MifareOneTool +{ + public partial class FormHTool : Form + { + public FormHTool() + { + InitializeComponent(); + } + + private S50 currentS50 = new S50(); + string currentFilename = ""; + + private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (dataGridView1.SelectedRows.Count > 0) + { + int sectorIndex = dataGridView1.SelectedRows[0].Index; + reloadEdit(sectorIndex); + logAppend("显示扇区" + sectorIndex.ToString()); + } + } + private void logAppend(string msg) + { + richTextBox1.AppendText(msg + "\n"); + richTextBox1.ScrollToCaret(); + } + private void reloadEdit(int sectorIndex) + { + if (sectorIndex == -1) + { + comboBox1.SelectedIndex = 0; + comboBox2.SelectedIndex = 0; + comboBox3.SelectedIndex = 0; + comboBox4.SelectedIndex = 1; + this.keyBEdit.Text = ""; + this.keyAEdit.Text = ""; + this.block2Edit.Text = ""; + this.block1Edit.Text = ""; + this.block0Edit.Text = ""; + this.labelCurSec.Text = "当前选定扇区:??"; + return; + } + labelCurSec.Text = "当前选定扇区:" + sectorIndex.ToString(); + block0Edit.Text = Form1.hex(currentS50.Sectors[sectorIndex].Block[0]); + block1Edit.Text = Form1.hex(currentS50.Sectors[sectorIndex].Block[1]); + block2Edit.Text = Form1.hex(currentS50.Sectors[sectorIndex].Block[2]); + keyAEdit.Text = Form1.hex(currentS50.Sectors[sectorIndex].Block[3].Skip(0).Take(6).ToArray()); + keyBEdit.Text = Form1.hex(currentS50.Sectors[sectorIndex].Block[3].Skip(10).Take(6).ToArray()); + byte[] acbits = Utils.ReadAC(currentS50.Sectors[sectorIndex].Block[3].Skip(6).Take(4).ToArray()); + comboBox1.SelectedIndex = acbits[0] & 0x07; + comboBox2.SelectedIndex = acbits[1] & 0x07; + comboBox3.SelectedIndex = acbits[2] & 0x07; + comboBox4.SelectedIndex = acbits[3] & 0x07; + int res = currentS50.Sectors[sectorIndex].Verify(); + string msg = ""; + if ((res & 0x01) == 0x01) + { + currentS50.Sectors[sectorIndex].Block[0][4] + = (byte)(currentS50.Sectors[sectorIndex].Block[0][0] + ^ currentS50.Sectors[sectorIndex].Block[0][1] + ^ currentS50.Sectors[sectorIndex].Block[0][2] + ^ currentS50.Sectors[sectorIndex].Block[0][3]); + block0Edit.Text = Form1.hex(currentS50.Sectors[sectorIndex].Block[0]); + msg += "该扇区UID校验值错误,已经自动为您更正。\n"; + } + if ((res & 0x02) == 0x02) + { + comboBox1.SelectedIndex = 0; + comboBox2.SelectedIndex = 0; + comboBox3.SelectedIndex = 0; + comboBox4.SelectedIndex = 1; + msg += "该扇区访问控制位无效,写入将会损坏卡片,已重新设置。\n"; + } + if ((res & 0x04) == 0x04) + { + comboBox1.SelectedIndex = 0; + comboBox2.SelectedIndex = 0; + comboBox3.SelectedIndex = 0; + comboBox4.SelectedIndex = 1; + msg += "该扇区访问控制位损坏,写入将会损坏卡片,已重新设置。\n"; + } + if (res != 0x00) { MessageBox.Show(msg.Trim()); } + + this.ValidateChildren(); + } + + private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) + { + reloadEdit(-1); + OpenFileDialog ofd = new OpenFileDialog(); + ofd.CheckFileExists = true; + ofd.Filter = "MFD文件|*.mfd;*.dump"; + ofd.Title = "请选择需要打开的MFD文件"; + ofd.Multiselect = false; + if (ofd.ShowDialog() == DialogResult.OK) + { + currentFilename = ofd.FileName; + } + else + { + return; + } + this.currentS50 = new S50(); + try + { + this.currentS50.LoadFromMfd(currentFilename); + } + catch (IOException ioe) + { + MessageBox.Show(ioe.Message, "打开出错", MessageBoxButtons.OK, MessageBoxIcon.Error); + this.currentS50 = new S50(); + return; + } + reloadList(); + logAppend("打开了"+ofd.FileName); + } + + private void reloadList() + { + dataGridView1.Rows.Clear(); + for (int i = 0; i < 16; i++) + { + Sector sec = currentS50.Sectors[i]; + int index = dataGridView1.Rows.Add(); + dataGridView1.Rows[index].Cells[0].Value = sec.Info(i); + } + } + + private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + this.currentS50.ExportToMfd(currentFilename); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "写入出错", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + logAppend("已保存到" + currentFilename + "。"); + } + + private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e) + { + string filename; + SaveFileDialog ofd = new SaveFileDialog(); + ofd.AddExtension = true; + ofd.DefaultExt = ".mfd"; + ofd.Title = "请选择MFD文件保存位置及文件名"; + ofd.OverwritePrompt = true; + ofd.Filter = "MFD文件|*.mfd"; + if (ofd.ShowDialog() == DialogResult.OK) + { + filename = ofd.FileName; + } + else + { + return; + } + try + { + this.currentS50.ExportToMfd(filename); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "写入出错", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + logAppend("已保存到" + filename + "。"); + } + + private void block0Edit_Validating(object sender, CancelEventArgs e) + { + const string pattern = @"[0-9A-Fa-f]{32}"; + TextBox tb = ((TextBox)sender); + string content = tb.Text.Trim(); + if (!(Regex.IsMatch(content, pattern))) + { + tb.BackColor = Color.Tomato; + //e.Cancel = true; + } + else + { + tb.BackColor = Color.Aquamarine; + tb.Text = content; + } + } + + private void keyAEdit_Validating(object sender, CancelEventArgs e) + { + const string pattern = @"[0-9A-Fa-f]{12}"; + TextBox tb = ((TextBox)sender); + string content = tb.Text.Trim(); + if (!(Regex.IsMatch(content, pattern))) + { + tb.BackColor = Color.Tomato; + //e.Cancel = true; + } + else + { + tb.BackColor = Color.Aquamarine; + tb.Text = content; + } + } + + private void buttonSaveSectorEdit_Click(object sender, EventArgs e) + { + this.ValidateChildren(); + + } + + private void comboBox1_Validating(object sender, CancelEventArgs e) + { + ComboBox tb = ((ComboBox)sender); + if (tb.SelectedIndex < 0 || tb.Text == "##文件中的值错误##") + { + tb.BackColor = Color.Tomato; + //e.Cancel = true; + } + else + { + tb.BackColor = Color.Aquamarine; + } + } + + private void 检查全卡ToolStripMenuItem_Click(object sender, EventArgs e) + { + int[] res = currentS50.Verify(); + if (res[16] == 0) + { + MessageBox.Show("该文件一切正常。"); + } + else + { + string msg = "该文件存在以下错误:\n"; + for (int i = 0; i < 16; i++) + { + msg += "扇区" + i.ToString()+":\n"; + if ((res[i] & 0x01) == 0x01) + { + msg += "该扇区UID校验值错误,请点击打开扇区0来自动更正。\n"; + } + if ((res[i] & 0x02) == 0x02) + { + msg += "该扇区访问控制位无效,写入将会损坏卡片,已重新设置。\n"; + } + if ((res[i] & 0x04) == 0x04) + { + msg += "该扇区访问控制位损坏,写入将会损坏卡片,已重新设置。\n"; + } + if (res[i] == 0) + { + msg += "该扇区一切正常。\n"; + } + } + richTextBox1.Clear(); + logAppend(msg); + } + } + } +} diff --git a/MifareOneTool/FormHTool.resx b/MifareOneTool/FormHTool.resx new file mode 100644 index 0000000..b3bd9fb --- /dev/null +++ b/MifareOneTool/FormHTool.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + True + + + 155, 17 + + \ No newline at end of file diff --git a/MifareOneTool/MifareOneTool.csproj b/MifareOneTool/MifareOneTool.csproj index c8c5072..a576e5e 100644 --- a/MifareOneTool/MifareOneTool.csproj +++ b/MifareOneTool/MifareOneTool.csproj @@ -73,6 +73,12 @@ Form1.cs + + Form + + + FormHTool.cs + Form @@ -85,6 +91,9 @@ Form1.cs + + FormHTool.cs + FormKeyMfd.cs diff --git a/MifareOneTool/Properties/AssemblyInfo.cs b/MifareOneTool/Properties/AssemblyInfo.cs index 635cf54..8ed9f30 100644 --- a/MifareOneTool/Properties/AssemblyInfo.cs +++ b/MifareOneTool/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.0")] -[assembly: AssemblyFileVersion("1.4.0.0")] +[assembly: AssemblyVersion("1.5.0.0")] +[assembly: AssemblyFileVersion("1.5.0.0")]