From b7bbf15c3861ee5edc6a6850c44ff902b38ac0dc Mon Sep 17 00:00:00 2001 From: XAS-712 Date: Sat, 2 Feb 2019 18:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Hardnested?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MifareOneTool/Form1.Designer.cs | 34 +++- MifareOneTool/Form1.cs | 47 +++++ MifareOneTool/FormHardNes.Designer.cs | 273 ++++++++++++++++++++++++++ MifareOneTool/FormHardNes.cs | 111 +++++++++++ MifareOneTool/FormHardNes.resx | 120 +++++++++++ MifareOneTool/MifareOneTool.csproj | 9 + 6 files changed, 590 insertions(+), 4 deletions(-) create mode 100644 MifareOneTool/FormHardNes.Designer.cs create mode 100644 MifareOneTool/FormHardNes.cs create mode 100644 MifareOneTool/FormHardNes.resx diff --git a/MifareOneTool/Form1.Designer.cs b/MifareOneTool/Form1.Designer.cs index f87597e..3247e91 100644 --- a/MifareOneTool/Form1.Designer.cs +++ b/MifareOneTool/Form1.Designer.cs @@ -98,6 +98,8 @@ this.label5 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.checkBoxWriteProtect = new System.Windows.Forms.CheckBox(); + this.label7 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); @@ -179,7 +181,7 @@ this.richTextBox1.Location = new System.Drawing.Point(0, 219); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.ReadOnly = true; - this.richTextBox1.Size = new System.Drawing.Size(767, 381); + this.richTextBox1.Size = new System.Drawing.Size(767, 390); this.richTextBox1.TabIndex = 1; this.richTextBox1.Text = "Hello,cardman!\n建议点击\"检测\"以加快后续运行速度\n"; // @@ -486,6 +488,8 @@ // // tabPage2 // + this.tabPage2.Controls.Add(this.label8); + this.tabPage2.Controls.Add(this.label7); this.tabPage2.Controls.Add(this.label6); this.tabPage2.Controls.Add(this.label4); this.tabPage2.Controls.Add(this.label3); @@ -686,13 +690,13 @@ // // buttonHardNested // - this.buttonHardNested.Enabled = false; this.buttonHardNested.Location = new System.Drawing.Point(178, 51); this.buttonHardNested.Name = "buttonHardNested"; this.buttonHardNested.Size = new System.Drawing.Size(104, 25); this.buttonHardNested.TabIndex = 14; this.buttonHardNested.Text = "HardNested"; this.buttonHardNested.UseVisualStyleBackColor = true; + this.buttonHardNested.Click += new System.EventHandler(this.buttonHardNested_Click); // // groupBox9 // @@ -738,7 +742,7 @@ this.localVersionLabel, this.remoteVersionLabel, this.toolStripCheckUpdate}); - this.statusStrip1.Location = new System.Drawing.Point(0, 603); + this.statusStrip1.Location = new System.Drawing.Point(0, 609); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Size = new System.Drawing.Size(767, 26); this.statusStrip1.TabIndex = 12; @@ -870,11 +874,31 @@ this.checkBoxWriteProtect.UseVisualStyleBackColor = true; this.checkBoxWriteProtect.CheckedChanged += new System.EventHandler(this.checkBoxWriteProtect_CheckedChanged); // + // label7 + // + this.label7.AutoSize = true; + this.label7.ForeColor = System.Drawing.Color.Green; + this.label7.Location = new System.Drawing.Point(84, 50); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(37, 30); + this.label7.TabIndex = 11; + this.label7.Text = "请放\r\n原卡"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.ForeColor = System.Drawing.Color.Green; + this.label8.Location = new System.Drawing.Point(392, 9); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(37, 30); + this.label8.TabIndex = 12; + this.label8.Text = "请放\r\n新卡"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(767, 629); + this.ClientSize = new System.Drawing.Size(767, 635); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.tabControl1); this.Controls.Add(this.richTextBox1); @@ -976,6 +1000,8 @@ private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label7; } } diff --git a/MifareOneTool/Form1.cs b/MifareOneTool/Form1.cs index 2ec393c..1622120 100644 --- a/MifareOneTool/Form1.cs +++ b/MifareOneTool/Form1.cs @@ -1113,5 +1113,52 @@ namespace MifareOneTool { Properties.Settings.Default.WriteCheck = checkBoxWriteProtect.Checked; } + + private void buttonHardNested_Click(object sender, EventArgs e) + { + if (lprocess) { MessageBox.Show("有任务运行中,不可执行。", "设备忙", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Form1.ActiveForm.Text = "MifareOne Tool - 运行中"; + FormHardNes fhn = new FormHardNes(); + if (fhn.ShowDialog() == DialogResult.Yes) + { + string hardargs = fhn.GetArg(); + BackgroundWorker bgw = new BackgroundWorker(); + bgw.DoWork += new DoWorkEventHandler(Hardnest); + bgw.WorkerReportsProgress = true; + bgw.ProgressChanged += new ProgressChangedEventHandler(default_rpt); + bgw.RunWorkerAsync(hardargs); + } + else + { + Text = "MifareOne Tool - 已取消"; + } + } + void Hardnest(object sender, DoWorkEventArgs e) + { + if (lprocess) { return; } + ProcessStartInfo psi = new ProcessStartInfo("nfc-bin/libnfc_hardnested.exe"); + psi.Arguments = (string)e.Argument; + 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(); + lprocess = false; running = false; + if (process.ExitCode == 0) + { + b.ReportProgress(100, "##运行完毕##"); + } + else + { + b.ReportProgress(100, "##运行出错##"); + } + } } } diff --git a/MifareOneTool/FormHardNes.Designer.cs b/MifareOneTool/FormHardNes.Designer.cs new file mode 100644 index 0000000..f560829 --- /dev/null +++ b/MifareOneTool/FormHardNes.Designer.cs @@ -0,0 +1,273 @@ +namespace MifareOneTool +{ + partial class FormHardNes + { + /// + /// 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.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.keyEdit = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.radioKey1A = new System.Windows.Forms.RadioButton(); + this.radioKey1B = new System.Windows.Forms.RadioButton(); + this.radioKey2B = new System.Windows.Forms.RadioButton(); + this.radioKey2A = new System.Windows.Forms.RadioButton(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.sector2 = new System.Windows.Forms.TextBox(); + this.sector1 = new System.Windows.Forms.TextBox(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(308, 187); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 25); + this.button1.TabIndex = 0; + this.button1.Text = "解密!"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.button2.Location = new System.Drawing.Point(227, 187); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 25); + this.button2.TabIndex = 1; + this.button2.Text = "取消"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.radioKey1B); + this.groupBox1.Controls.Add(this.radioKey1A); + this.groupBox1.Controls.Add(this.label4); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Controls.Add(this.sector1); + this.groupBox1.Controls.Add(this.keyEdit); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Location = new System.Drawing.Point(12, 12); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(371, 81); + this.groupBox1.TabIndex = 2; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "目标卡信息"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.ForeColor = System.Drawing.Color.Blue; + this.label1.Location = new System.Drawing.Point(12, 192); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(202, 15); + this.label1.TabIndex = 3; + this.label1.Text = "解密时请保证设备良好散热!"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 21); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(76, 15); + this.label2.TabIndex = 0; + this.label2.Text = "已知的Key"; + // + // keyEdit + // + this.keyEdit.Location = new System.Drawing.Point(9, 39); + this.keyEdit.Name = "keyEdit"; + this.keyEdit.Size = new System.Drawing.Size(120, 25); + this.keyEdit.TabIndex = 10; + this.keyEdit.Text = "ffffffffffff"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(132, 21); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(52, 15); + this.label3.TabIndex = 12; + this.label3.Text = "扇区号"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(190, 21); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(37, 15); + this.label4.TabIndex = 13; + this.label4.Text = "类型"; + // + // radioKey1A + // + this.radioKey1A.AutoSize = true; + this.radioKey1A.Checked = true; + this.radioKey1A.Location = new System.Drawing.Point(193, 40); + this.radioKey1A.Name = "radioKey1A"; + this.radioKey1A.Size = new System.Drawing.Size(60, 19); + this.radioKey1A.TabIndex = 14; + this.radioKey1A.TabStop = true; + this.radioKey1A.Text = "KeyA"; + this.radioKey1A.UseVisualStyleBackColor = true; + // + // radioKey1B + // + this.radioKey1B.AutoSize = true; + this.radioKey1B.Location = new System.Drawing.Point(259, 40); + this.radioKey1B.Name = "radioKey1B"; + this.radioKey1B.Size = new System.Drawing.Size(60, 19); + this.radioKey1B.TabIndex = 15; + this.radioKey1B.Text = "KeyB"; + this.radioKey1B.UseVisualStyleBackColor = true; + // + // radioKey2B + // + this.radioKey2B.AutoSize = true; + this.radioKey2B.Location = new System.Drawing.Point(259, 40); + this.radioKey2B.Name = "radioKey2B"; + this.radioKey2B.Size = new System.Drawing.Size(60, 19); + this.radioKey2B.TabIndex = 15; + this.radioKey2B.Text = "KeyB"; + this.radioKey2B.UseVisualStyleBackColor = true; + // + // radioKey2A + // + this.radioKey2A.AutoSize = true; + this.radioKey2A.Checked = true; + this.radioKey2A.Location = new System.Drawing.Point(193, 40); + this.radioKey2A.Name = "radioKey2A"; + this.radioKey2A.Size = new System.Drawing.Size(60, 19); + this.radioKey2A.TabIndex = 14; + this.radioKey2A.TabStop = true; + this.radioKey2A.Text = "KeyA"; + this.radioKey2A.UseVisualStyleBackColor = true; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(190, 21); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(37, 15); + this.label5.TabIndex = 13; + this.label5.Text = "类型"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(132, 21); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(52, 15); + this.label6.TabIndex = 12; + this.label6.Text = "扇区号"; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.radioKey2B); + this.groupBox2.Controls.Add(this.radioKey2A); + this.groupBox2.Controls.Add(this.label5); + this.groupBox2.Controls.Add(this.label6); + this.groupBox2.Controls.Add(this.sector2); + this.groupBox2.Location = new System.Drawing.Point(12, 99); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(371, 81); + this.groupBox2.TabIndex = 16; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "解密设置"; + // + // sector2 + // + this.sector2.Location = new System.Drawing.Point(135, 39); + this.sector2.Name = "sector2"; + this.sector2.Size = new System.Drawing.Size(46, 25); + this.sector2.TabIndex = 11; + this.sector2.Text = "1"; + // + // sector1 + // + this.sector1.Location = new System.Drawing.Point(135, 39); + this.sector1.Name = "sector1"; + this.sector1.Size = new System.Drawing.Size(46, 25); + this.sector1.TabIndex = 11; + this.sector1.Text = "0"; + // + // FormHardNes + // + this.AcceptButton = this.button1; + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.button2; + this.ClientSize = new System.Drawing.Size(395, 224); + this.ControlBox = false; + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.label1); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.KeyPreview = true; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "FormHardNes"; + this.Text = "初始化HardNested解密"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.RadioButton radioKey1B; + private System.Windows.Forms.RadioButton radioKey1A; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox keyEdit; + private System.Windows.Forms.RadioButton radioKey2B; + private System.Windows.Forms.RadioButton radioKey2A; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.TextBox sector2; + private System.Windows.Forms.TextBox sector1; + } +} \ No newline at end of file diff --git a/MifareOneTool/FormHardNes.cs b/MifareOneTool/FormHardNes.cs new file mode 100644 index 0000000..bd5fc0e --- /dev/null +++ b/MifareOneTool/FormHardNes.cs @@ -0,0 +1,111 @@ +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.Text.RegularExpressions; + +namespace MifareOneTool +{ + public partial class FormHardNes : Form + { + public FormHardNes() + { + InitializeComponent(); + } + + static int getBlock(int sector) + {//可能有bug + int trailer_block = 0; + if (sector < 32) + { + trailer_block = sector*4 + 3; + } + else + { + trailer_block = 128+16*(sector-32) + 15; + } + return trailer_block; + } + + public string GetArg() + { + string arg = ""; + arg += keyEdit.Text.ToUpper() + " "; + arg += getBlock(Convert.ToInt32(sector1.Text.Trim())).ToString() + " "; + arg += (radioKey1A.Checked ?"A":"B") + " "; + arg += getBlock(Convert.ToInt32(sector2.Text.Trim())).ToString() + " "; + arg += radioKey2A.Checked ? "A" : "B"; + return arg; + } + + private void button2_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + private void button1_Click(object sender, EventArgs e) + { + bool error = false; + const string pattern = @"[0-9A-Fa-f]{12}"; + TextBox tb = keyEdit; + string content = tb.Text.Trim(); + if (!(Regex.IsMatch(content, pattern) && content.Length == 12)) + { + tb.BackColor = Color.Tomato; + error = true; + } + else + { + tb.BackColor = Color.Aquamarine; + tb.Text = content; + } + int sec1, sec2; + if (!int.TryParse(sector1.Text, out sec1)) + { + sector1.BackColor = Color.Tomato; + error = true; + } + else + { + if (sec1 >= 0) + { + sector1.BackColor = Color.Aquamarine; + } + else + { + sector1.BackColor = Color.Tomato; + error = true; + } + } + if (!int.TryParse(sector2.Text, out sec2)) + { + sector2.BackColor = Color.Tomato; + error = true; + } + else + { + if (sec2 >= 0) + { + sector2.BackColor = Color.Aquamarine; + } + else + { + sector2.BackColor = Color.Tomato; + error = true; + } + } + if (error) + { + MessageBox.Show("设置错误,请修改。"); + return; + } + this.DialogResult = DialogResult.Yes; + this.Close(); + } + } +} diff --git a/MifareOneTool/FormHardNes.resx b/MifareOneTool/FormHardNes.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MifareOneTool/FormHardNes.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/MifareOneTool/MifareOneTool.csproj b/MifareOneTool/MifareOneTool.csproj index a8d4210..84374fc 100644 --- a/MifareOneTool/MifareOneTool.csproj +++ b/MifareOneTool/MifareOneTool.csproj @@ -83,6 +83,12 @@ FormDiff.cs + + Form + + + FormHardNes.cs + Form @@ -98,6 +104,9 @@ FormDiff.cs + + FormHardNes.cs + FormHTool.cs