This commit is contained in:
XAS-712 2019-01-18 22:52:01 +08:00
commit c9580b1fe4
5 changed files with 175 additions and 10 deletions

View File

@ -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];
@ -212,6 +221,10 @@ namespace MifareOneTool
{
info += " 有数据";
}
if (this.Verify() != 0x00)
{
info += " 有错误";
}
return info;
}
}
@ -311,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());
}
}
}

View File

@ -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();
@ -66,6 +67,10 @@
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
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();
@ -88,6 +93,7 @@
// 文件ToolStripMenuItem
//
this.ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem,
this.ToolStripMenuItem,
this.ToolStripMenuItem,
this.ToolStripMenuItem,
@ -97,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";
@ -139,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 = "工具";
@ -148,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);
//
@ -156,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);
//
@ -233,11 +251,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);
//
@ -474,8 +492,35 @@
//
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;
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 +585,10 @@
private System.Windows.Forms.Label label6;
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;
}
}

View File

@ -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)
{
@ -340,5 +340,91 @@ 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("已重置并新建卡。");
}
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 + "。");
}
}
}

View File

@ -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>

View File

@ -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.2.0")]
[assembly: AssemblyFileVersion("1.5.2.0")]