加入检测并纠正和MCT文件导出功能
This commit is contained in:
parent
7bb279d895
commit
189c7befb0
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
62
MifareOneTool/FormHTool.Designer.cs
generated
62
MifareOneTool/FormHTool.Designer.cs
generated
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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 + "。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,6 +123,9 @@
|
||||
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="s50BindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>155, 17</value>
|
||||
</metadata>
|
||||
|
||||
@ -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")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user