From 7bb279d895ebbb3affa7dcb403f195f5919ec5cc Mon Sep 17 00:00:00 2001 From: XAS-712 Date: Sun, 13 Jan 2019 10:57:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=BB=86=E8=8A=82=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MifareOneTool/ClassMifareS50.cs | 4 ++++ MifareOneTool/FormHTool.Designer.cs | 18 +++++++++++++++--- MifareOneTool/FormHTool.cs | 8 ++++++++ MifareOneTool/Properties/AssemblyInfo.cs | 4 ++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/MifareOneTool/ClassMifareS50.cs b/MifareOneTool/ClassMifareS50.cs index 9133362..6115acc 100644 --- a/MifareOneTool/ClassMifareS50.cs +++ b/MifareOneTool/ClassMifareS50.cs @@ -212,6 +212,10 @@ namespace MifareOneTool { info += " 有数据"; } + if (this.Verify() != 0x00) + { + info += " 有错误"; + } return info; } } diff --git a/MifareOneTool/FormHTool.Designer.cs b/MifareOneTool/FormHTool.Designer.cs index 6c050dd..d16b43d 100644 --- a/MifareOneTool/FormHTool.Designer.cs +++ b/MifareOneTool/FormHTool.Designer.cs @@ -65,6 +65,7 @@ this.labelCurSec = new System.Windows.Forms.Label(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.新建ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.s50BindingSource = new System.Windows.Forms.BindingSource(this.components); this.menuStrip1.SuspendLayout(); this.groupBox1.SuspendLayout(); @@ -88,6 +89,7 @@ // 文件ToolStripMenuItem // this.文件ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.新建ToolStripMenuItem, this.打开ToolStripMenuItem, this.保存ToolStripMenuItem, this.另存为ToolStripMenuItem, @@ -233,11 +235,11 @@ // // buttonSaveSectorEdit // - this.buttonSaveSectorEdit.Location = new System.Drawing.Point(186, 16); + this.buttonSaveSectorEdit.Location = new System.Drawing.Point(147, 16); this.buttonSaveSectorEdit.Name = "buttonSaveSectorEdit"; - this.buttonSaveSectorEdit.Size = new System.Drawing.Size(100, 25); + this.buttonSaveSectorEdit.Size = new System.Drawing.Size(139, 25); this.buttonSaveSectorEdit.TabIndex = 20; - this.buttonSaveSectorEdit.Text = "修改扇区"; + this.buttonSaveSectorEdit.Text = "修改扇区(Enter)"; this.buttonSaveSectorEdit.UseVisualStyleBackColor = true; this.buttonSaveSectorEdit.Click += new System.EventHandler(this.buttonSaveSectorEdit_Click); // @@ -470,12 +472,21 @@ this.richTextBox1.TabIndex = 0; this.richTextBox1.Text = "欢迎使用M1T的集成编辑器S50HTool!\n打开文件请点左上角文件-打开或Ctrl+O\n"; // + // 新建ToolStripMenuItem + // + this.新建ToolStripMenuItem.Name = "新建ToolStripMenuItem"; + this.新建ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N))); + this.新建ToolStripMenuItem.Size = new System.Drawing.Size(222, 24); + this.新建ToolStripMenuItem.Text = "新建"; + this.新建ToolStripMenuItem.Click += new System.EventHandler(this.新建ToolStripMenuItem_Click); + // // s50BindingSource // this.s50BindingSource.DataSource = typeof(MifareOneTool.S50); // // FormHTool // + this.AcceptButton = this.buttonSaveSectorEdit; this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(838, 452); @@ -540,5 +551,6 @@ private System.Windows.Forms.Label label6; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.RichTextBox richTextBox1; + private System.Windows.Forms.ToolStripMenuItem 新建ToolStripMenuItem; } } \ No newline at end of file diff --git a/MifareOneTool/FormHTool.cs b/MifareOneTool/FormHTool.cs index 17b663a..248962e 100644 --- a/MifareOneTool/FormHTool.cs +++ b/MifareOneTool/FormHTool.cs @@ -340,5 +340,13 @@ namespace MifareOneTool logAppend("UID已改为" + Form1.hex(buid) + ",计算得到BCC=" + Form1.hex(new byte[]{bcc})); reloadEdit(0); } + + private void 新建ToolStripMenuItem_Click(object sender, EventArgs e) + { + reloadEdit(-1); + this.currentS50 = new S50(); + reloadList(); + logAppend("已重置并新建卡。"); + } } } diff --git a/MifareOneTool/Properties/AssemblyInfo.cs b/MifareOneTool/Properties/AssemblyInfo.cs index 8ed9f30..5b9539e 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.5.0.0")] -[assembly: AssemblyFileVersion("1.5.0.0")] +[assembly: AssemblyVersion("1.5.1.0")] +[assembly: AssemblyFileVersion("1.5.1.0")] From 189c7befb0c4c3d917eb56e23031206f48dafe72 Mon Sep 17 00:00:00 2001 From: XAS-712 Date: Fri, 18 Jan 2019 22:34:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E5=B9=B6=E7=BA=A0=E6=AD=A3=E5=92=8CMCT=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MifareOneTool/ClassMifareS50.cs | 22 +++++++ MifareOneTool/FormHTool.Designer.cs | 62 ++++++++++++++---- MifareOneTool/FormHTool.cs | 82 +++++++++++++++++++++++- MifareOneTool/FormHTool.resx | 3 + MifareOneTool/Properties/AssemblyInfo.cs | 4 +- 5 files changed, 157 insertions(+), 16 deletions(-) diff --git a/MifareOneTool/ClassMifareS50.cs b/MifareOneTool/ClassMifareS50.cs index 6115acc..e959078 100644 --- a/MifareOneTool/ClassMifareS50.cs +++ b/MifareOneTool/ClassMifareS50.cs @@ -9,6 +9,15 @@ namespace MifareOneTool { class Utils { + public static string Hex2Str(byte[] bytes) + { + StringBuilder ret = new StringBuilder(); + foreach (byte b in bytes) + { + ret.AppendFormat("{0:x2}", b); + } + return ret.ToString(); + } public static byte[] ReadAC(byte[] ac) { byte[] acbits = new byte[4]; @@ -315,5 +324,18 @@ namespace MifareOneTool byte[] fileBuffer = this.SectorsRaw; File.WriteAllBytes(file, fileBuffer); } + public void ExportToMctTxt(string file) + { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 16; i++) + { + sb.AppendLine("+Sector: " + i.ToString()); + for (int j = 0; j < 4; j++) + { + sb.AppendLine(Utils.Hex2Str(this._sectors[i].Block[j])); + } + } + File.WriteAllText(file, sb.ToString()); + } } } diff --git a/MifareOneTool/FormHTool.Designer.cs b/MifareOneTool/FormHTool.Designer.cs index d16b43d..1db0996 100644 --- a/MifareOneTool/FormHTool.Designer.cs +++ b/MifareOneTool/FormHTool.Designer.cs @@ -31,6 +31,7 @@ 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.另存为ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -65,8 +66,11 @@ this.labelCurSec = new System.Windows.Forms.Label(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); - this.新建ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.s50BindingSource = new System.Windows.Forms.BindingSource(this.components); + this.检查并纠正全卡ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); + this.导出为MCT格式ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); @@ -99,6 +103,14 @@ 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.N))); + 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"; @@ -141,7 +153,11 @@ // this.工具ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.修改UIDToolStripMenuItem, - this.检查全卡ToolStripMenuItem}); + this.toolStripSeparator2, + this.检查全卡ToolStripMenuItem, + this.检查并纠正全卡ToolStripMenuItem, + this.toolStripSeparator3, + this.导出为MCT格式ToolStripMenuItem}); this.工具ToolStripMenuItem.Name = "工具ToolStripMenuItem"; this.工具ToolStripMenuItem.Size = new System.Drawing.Size(51, 24); this.工具ToolStripMenuItem.Text = "工具"; @@ -150,7 +166,7 @@ // 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.Size = new System.Drawing.Size(239, 24); this.修改UIDToolStripMenuItem.Text = "修改UID"; this.修改UIDToolStripMenuItem.Click += new System.EventHandler(this.修改UIDToolStripMenuItem_Click); // @@ -158,7 +174,7 @@ // 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.Size = new System.Drawing.Size(239, 24); this.检查全卡ToolStripMenuItem.Text = "检查全卡"; this.检查全卡ToolStripMenuItem.Click += new System.EventHandler(this.检查全卡ToolStripMenuItem_Click); // @@ -472,18 +488,36 @@ this.richTextBox1.TabIndex = 0; this.richTextBox1.Text = "欢迎使用M1T的集成编辑器S50HTool!\n打开文件请点左上角文件-打开或Ctrl+O\n"; // - // 新建ToolStripMenuItem - // - this.新建ToolStripMenuItem.Name = "新建ToolStripMenuItem"; - this.新建ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N))); - this.新建ToolStripMenuItem.Size = new System.Drawing.Size(222, 24); - this.新建ToolStripMenuItem.Text = "新建"; - this.新建ToolStripMenuItem.Click += new System.EventHandler(this.新建ToolStripMenuItem_Click); - // // s50BindingSource // this.s50BindingSource.DataSource = typeof(MifareOneTool.S50); // + // 检查并纠正全卡ToolStripMenuItem + // + this.检查并纠正全卡ToolStripMenuItem.Name = "检查并纠正全卡ToolStripMenuItem"; + this.检查并纠正全卡ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.K))); + this.检查并纠正全卡ToolStripMenuItem.Size = new System.Drawing.Size(239, 24); + this.检查并纠正全卡ToolStripMenuItem.Text = "检查并纠正全卡"; + this.检查并纠正全卡ToolStripMenuItem.Click += new System.EventHandler(this.检查并纠正全卡ToolStripMenuItem_Click); + // + // toolStripSeparator2 + // + this.toolStripSeparator2.Name = "toolStripSeparator2"; + this.toolStripSeparator2.Size = new System.Drawing.Size(245, 6); + // + // toolStripSeparator3 + // + this.toolStripSeparator3.Name = "toolStripSeparator3"; + this.toolStripSeparator3.Size = new System.Drawing.Size(245, 6); + // + // 导出为MCT格式ToolStripMenuItem + // + this.导出为MCT格式ToolStripMenuItem.Name = "导出为MCT格式ToolStripMenuItem"; + this.导出为MCT格式ToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.M))); + this.导出为MCT格式ToolStripMenuItem.Size = new System.Drawing.Size(248, 24); + this.导出为MCT格式ToolStripMenuItem.Text = "导出为MCT格式"; + this.导出为MCT格式ToolStripMenuItem.Click += new System.EventHandler(this.导出为MCT格式ToolStripMenuItem_Click); + // // FormHTool // this.AcceptButton = this.buttonSaveSectorEdit; @@ -552,5 +586,9 @@ private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.ToolStripMenuItem 新建ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 检查并纠正全卡ToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; + private System.Windows.Forms.ToolStripMenuItem 导出为MCT格式ToolStripMenuItem; } } \ No newline at end of file diff --git a/MifareOneTool/FormHTool.cs b/MifareOneTool/FormHTool.cs index 248962e..2de8e32 100644 --- a/MifareOneTool/FormHTool.cs +++ b/MifareOneTool/FormHTool.cs @@ -301,11 +301,11 @@ namespace MifareOneTool } if ((res[i] & 0x02) == 0x02) { - msg += "该扇区访问控制位无效,写入将会损坏卡片,已重新设置。\n"; + msg += "该扇区访问控制位无效,写入将会损坏卡片,请重新设置。\n"; } if ((res[i] & 0x04) == 0x04) { - msg += "该扇区访问控制位损坏,写入将会损坏卡片,已重新设置。\n"; + msg += "该扇区访问控制位损坏,写入将会损坏卡片,请重新设置。\n"; } if (res[i] == 0) { @@ -348,5 +348,83 @@ namespace MifareOneTool reloadList(); logAppend("已重置并新建卡。"); } + + private void 检查并纠正全卡ToolStripMenuItem_Click(object sender, EventArgs e) + { + byte[] defaultAC = new byte[] { 0xff, 0x07, 0x80, 0x69 }; + 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) + { + currentS50.Sectors[i].Block[0][4] + = (byte)(currentS50.Sectors[i].Block[0][0] + ^ currentS50.Sectors[i].Block[0][1] + ^ currentS50.Sectors[i].Block[0][2] + ^ currentS50.Sectors[i].Block[0][3]); + block0Edit.Text = Form1.hex(currentS50.Sectors[i].Block[0]); + msg += "该扇区UID校验值错误,已自动更正。\n"; + } + if ((res[i] & 0x02) == 0x02) + { + for (int j = 6; j < 10; j++) + { + currentS50.Sectors[i].Block[3][j] = defaultAC[j - 6]; + } + msg += "该扇区访问控制位无效,写入将会损坏卡片,已重新设置。\n"; + } + if ((res[i] & 0x04) == 0x04) + { + for (int j = 6; j < 10; j++) + { + currentS50.Sectors[i].Block[3][j] = defaultAC[j - 6]; + } + msg += "该扇区访问控制位损坏,写入将会损坏卡片,已重新设置。\n"; + } + if (res[i] == 0) + { + msg += "该扇区一切正常。\n"; + } + } + richTextBox1.Clear(); + logAppend(msg); + } + } + + private void 导出为MCT格式ToolStripMenuItem_Click(object sender, EventArgs e) + { + string filename; + SaveFileDialog ofd = new SaveFileDialog(); + ofd.AddExtension = true; + ofd.DefaultExt = ".txt"; + ofd.Title = "请选择MCT.txt文件保存位置及文件名"; + ofd.OverwritePrompt = true; + ofd.Filter = "txt文件|*.txt"; + if (ofd.ShowDialog() == DialogResult.OK) + { + filename = ofd.FileName; + } + else + { + return; + } + try + { + this.currentS50.ExportToMctTxt(filename); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "写入出错", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + logAppend("已导出MCT文件" + filename + "。"); + } } } diff --git a/MifareOneTool/FormHTool.resx b/MifareOneTool/FormHTool.resx index b3bd9fb..279a098 100644 --- a/MifareOneTool/FormHTool.resx +++ b/MifareOneTool/FormHTool.resx @@ -123,6 +123,9 @@ True + + True + 155, 17 diff --git a/MifareOneTool/Properties/AssemblyInfo.cs b/MifareOneTool/Properties/AssemblyInfo.cs index 5b9539e..d772b25 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.5.1.0")] -[assembly: AssemblyFileVersion("1.5.1.0")] +[assembly: AssemblyVersion("1.5.2.0")] +[assembly: AssemblyFileVersion("1.5.2.0")]