编辑器完成

This commit is contained in:
XAS-712 2019-01-13 01:43:10 +08:00
parent 9f548dbe44
commit 62436b82f6
4 changed files with 109 additions and 48 deletions

View File

@ -51,34 +51,35 @@ namespace MifareOneTool
{ {
byte[] acbits = new byte[4]; byte[] acbits = new byte[4];
acbits[3] = 0x00; acbits[3] = 0x00;
acbits[1] = (byte)((ac[0]<< 2)& 0x10 acbits[1] = (byte)(((ac[0] << 2) & 0x10)
| (ac[1] << 3) & 0x20 | ((ac[1] << 3) & 0x20)
| (ac[2] << 4) & 0x40 | ((ac[2] << 4) & 0x40)
| (ac[3]<<5)&0x80); | ((ac[3] << 5) & 0x80));
acbits[2] = (byte)((ac[0]>>1)& 0x01 acbits[2] = (byte)(((ac[0] >> 1) & 0x01)
| (ac[1]) & 0x02 | ((ac[1]) & 0x02)
| (ac[2] << 1) & 0x04 | ((ac[2] << 1) & 0x04)
| (ac[3]<<2)&0x08); | ((ac[3] << 2) & 0x08)
acbits[2] = (byte)((ac[0] << 4) & 0x10 | ((ac[0] << 4) & 0x10)
| (ac[1] << 5) & 0x20 | ((ac[1] << 5) & 0x20)
| (ac[2] << 6) & 0x40 | ((ac[2] << 6) & 0x40)
| (ac[3] << 7) & 0x80); | ((ac[3] << 7) & 0x80));
for (int i = 0; i < ac.Length; i++) for (int i = 0; i < ac.Length; i++)
{ {
ac[i] = (byte)(ac[i] ^ 0xff); ac[i] = (byte)~ac[i];
} }
acbits[1] = (byte)((ac[0]) & 0x01 acbits[1] = (byte)(acbits[1] |
| (ac[1] << 1) & 0x02 ((ac[0]) & 0x01)
| (ac[2] << 2) & 0x04 | ((ac[1] << 1) & 0x02)
| (ac[3] << 3) & 0x08); | ((ac[2] << 2) & 0x04)
acbits[0] = (byte)((ac[0]>>2) & 0x01 | ((ac[3] << 3) & 0x08));
| (ac[1] >>1) & 0x02 acbits[0] = (byte)(((ac[0] >> 2) & 0x01)
| (ac[2]) & 0x04 | ((ac[1] >> 1) & 0x02)
| (ac[3] << 1) & 0x08); | ((ac[2]) & 0x04)
acbits[0] = (byte)((ac[0] << 3) & 0x10 | ((ac[3] << 1) & 0x08)
| (ac[1] << 4) & 0x20 | ((ac[0] << 3) & 0x10)
| (ac[2] << 5) & 0x40 | ((ac[1] << 4) & 0x20)
| (ac[3] << 6) & 0x80); | ((ac[2] << 5) & 0x40)
| ((ac[3] << 6) & 0x80));
return acbits; return acbits;
} }
} }
@ -308,6 +309,7 @@ namespace MifareOneTool
public void ExportToMfd(string file) public void ExportToMfd(string file)
{ {
byte[] fileBuffer = this.SectorsRaw; byte[] fileBuffer = this.SectorsRaw;
File.WriteAllBytes(file, fileBuffer);
} }
} }
} }

View File

@ -150,6 +150,7 @@
this.UIDToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U))); 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(191, 24);
this.UIDToolStripMenuItem.Text = "修改UID"; this.UIDToolStripMenuItem.Text = "修改UID";
this.UIDToolStripMenuItem.Click += new System.EventHandler(this.UIDToolStripMenuItem_Click);
// //
// 检查全卡ToolStripMenuItem // 检查全卡ToolStripMenuItem
// //
@ -486,7 +487,7 @@
this.MainMenuStrip = this.menuStrip1; this.MainMenuStrip = this.menuStrip1;
this.MaximizeBox = false; this.MaximizeBox = false;
this.Name = "FormHTool"; this.Name = "FormHTool";
this.Text = "S50HTool"; this.Text = "S50HTool-beta";
this.menuStrip1.ResumeLayout(false); this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout(); this.menuStrip1.PerformLayout();
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);

View File

@ -8,6 +8,8 @@ using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Security.Cryptography;
using Microsoft.VisualBasic;
namespace MifareOneTool namespace MifareOneTool
{ {
@ -20,6 +22,7 @@ namespace MifareOneTool
private S50 currentS50 = new S50(); private S50 currentS50 = new S50();
string currentFilename = ""; string currentFilename = "";
int currentSector = -1;
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{ {
@ -37,6 +40,7 @@ namespace MifareOneTool
} }
private void reloadEdit(int sectorIndex) private void reloadEdit(int sectorIndex)
{ {
currentSector = sectorIndex;
if (sectorIndex == -1) if (sectorIndex == -1)
{ {
comboBox1.SelectedIndex = 0; comboBox1.SelectedIndex = 0;
@ -188,7 +192,7 @@ namespace MifareOneTool
const string pattern = @"[0-9A-Fa-f]{32}"; const string pattern = @"[0-9A-Fa-f]{32}";
TextBox tb = ((TextBox)sender); TextBox tb = ((TextBox)sender);
string content = tb.Text.Trim(); string content = tb.Text.Trim();
if (!(Regex.IsMatch(content, pattern))) if (!(Regex.IsMatch(content, pattern)&&content.Length==32))
{ {
tb.BackColor = Color.Tomato; tb.BackColor = Color.Tomato;
//e.Cancel = true; //e.Cancel = true;
@ -205,7 +209,7 @@ namespace MifareOneTool
const string pattern = @"[0-9A-Fa-f]{12}"; const string pattern = @"[0-9A-Fa-f]{12}";
TextBox tb = ((TextBox)sender); TextBox tb = ((TextBox)sender);
string content = tb.Text.Trim(); string content = tb.Text.Trim();
if (!(Regex.IsMatch(content, pattern))) if (!(Regex.IsMatch(content, pattern) && content.Length == 12))
{ {
tb.BackColor = Color.Tomato; tb.BackColor = Color.Tomato;
//e.Cancel = true; //e.Cancel = true;
@ -217,10 +221,51 @@ namespace MifareOneTool
} }
} }
private static byte[] Hex2Block(string hex,int bytelen)
{
hex = hex.Replace(" ", "");
byte[] returnBytes = new byte[bytelen];
for (int i = 0; i < bytelen; i++)
returnBytes[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16);
return returnBytes;
}
private void buttonSaveSectorEdit_Click(object sender, EventArgs e) private void buttonSaveSectorEdit_Click(object sender, EventArgs e)
{
if (currentSector >= 0 && currentSector <= 15)
{ {
this.ValidateChildren(); this.ValidateChildren();
if (block0Edit.BackColor != Color.Aquamarine
|| block1Edit.BackColor != Color.Aquamarine
|| block2Edit.BackColor != Color.Aquamarine
|| keyAEdit.BackColor != Color.Aquamarine
|| keyBEdit.BackColor != Color.Aquamarine)
{
MessageBox.Show("当前扇区数据仍有错误,不能执行修改。");
return;
}
currentS50.Sectors[currentSector].Block[0] = Hex2Block(block0Edit.Text.Trim(),16);
currentS50.Sectors[currentSector].Block[1] = Hex2Block(block1Edit.Text.Trim(), 16);
currentS50.Sectors[currentSector].Block[2] = Hex2Block(block2Edit.Text.Trim(), 16);
byte[] kA = Hex2Block(keyAEdit.Text.Trim(), 6);
byte[] kB = Hex2Block(keyBEdit.Text.Trim(), 6);
byte[] ac = new byte[4] {
(byte)comboBox1.SelectedIndex,
(byte)comboBox2.SelectedIndex,
(byte)comboBox3.SelectedIndex,
(byte)comboBox4.SelectedIndex };
byte[] kC = Utils.GenAC(ac);
List<byte> list3=new List<byte>(kA);
list3.AddRange(kC);
list3.AddRange(kB);
byte[] block3 = list3.Take(16).ToArray();
currentS50.Sectors[currentSector].Block[3] = block3;
for (int i = 0; i < 16; i++)
{
dataGridView1.Rows[i].Cells[0].Value = currentS50.Sectors[i].Info(i);
}
logAppend("已更新扇区" + currentSector.ToString());
}
} }
private void comboBox1_Validating(object sender, CancelEventArgs e) private void comboBox1_Validating(object sender, CancelEventArgs e)
@ -271,5 +316,29 @@ namespace MifareOneTool
logAppend(msg); logAppend(msg);
} }
} }
private void UIDToolStripMenuItem_Click(object sender, EventArgs e)
{
reloadEdit(-1);
byte[] buid = new byte[4];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(buid);
string uid = Interaction.InputBox("请输入需要更改的UID卡号共8位十六进制数如E44A3BF1。", "请输入UID号", Form1.hex(buid), -1, -1).Trim();
string pat = "[0-9A-Fa-f]{8}";
if (!Regex.IsMatch(uid, pat))
{
MessageBox.Show("输入的UID号不合法", "InputError", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
buid = Hex2Block(uid, 4);
byte bcc=(byte)(buid[0]^buid[1]^buid[2]^buid[3]);
currentS50.Sectors[0].Block[0][0] = buid[0];
currentS50.Sectors[0].Block[0][1] = buid[1];
currentS50.Sectors[0].Block[0][2] = buid[2];
currentS50.Sectors[0].Block[0][3] = buid[3];
currentS50.Sectors[0].Block[0][4] = bcc;
logAppend("UID已改为" + Form1.hex(buid) + "计算得到BCC=" + Form1.hex(new byte[]{bcc}));
reloadEdit(0);
}
} }
} }

View File

@ -14,17 +14,6 @@ namespace MifareOneTool
{ {
Version localVersion; Version localVersion;
Version remoteVersion; Version remoteVersion;
//public static T FromJSON<T>(this string input)
//{
// try
// {
// return JsonConvert.DeserializeObject<T>(input);
// }
// catch (Exception ex)
// {
// return default(T);
// }
//}
public GitHubUpdate(string GitHubR) public GitHubUpdate(string GitHubR)
{ {
this.localVersion = Assembly.GetExecutingAssembly().GetName().Version; this.localVersion = Assembly.GetExecutingAssembly().GetName().Version;