public static byte[] Patch(byte[] Data, string UID) { // ToDo: Fix UID Cast byte[] Decrypted_Amiibo; if (IsEncrypted(Data)) { Decrypted_Amiibo = Amiibo_Class.Decrypt(Data, Main_Form.AmiiKeys); } else { Decrypted_Amiibo = Data; } byte[] Password_Amiibo = Amiibo_Class.Generate_Password(UID); byte[] UID_Long = NtagHelpers.StringToByteArrayFastest(UID); Array.Copy(UID_Long, 0x008, Decrypted_Amiibo, 0x000, 0x001); //Put LastChar of Long UID Array.Copy(new byte[] { 0x00, 0x00 }, 0x000, Decrypted_Amiibo, 0x002, 0x002); //Reset Static Lock Bytes Array.Copy(UID_Long, 0x000, Decrypted_Amiibo, 0x1D4, 0x008); //Modify UID Array.Copy(new byte[] { 0x00, 0x00, 0x00 }, 0x000, Decrypted_Amiibo, 0x208, 0x003); //Reset Dynamic Lock Bytes Array.Copy(Password_Amiibo, 0x000, Decrypted_Amiibo, 0x214, 0x004); //Modify Password Array.Copy(new byte[] { 0x80, 0x80 }, 0x000, Decrypted_Amiibo, 0x218, 0x002); //Reset PACK0 & PACK1 return(Amiibo_Class.Encrypt(Decrypted_Amiibo, Main_Form.AmiiKeys)); }
public static byte[] Dump_AppData(byte[] Data) { byte[] Decrypted_Amiibo; if (IsEncrypted(Data)) { Decrypted_Amiibo = Amiibo_Class.Decrypt(Data, Main_Form.AmiiKeys); } else { Decrypted_Amiibo = Data; } byte[] Amiibo_AppData = new byte[0x0D8]; Array.Copy(Decrypted_Amiibo, 0x0DC, Amiibo_AppData, 0x000, 0x0D8); return(Amiibo_AppData); }
public static byte[] WriteAppData(byte[] Data, byte[] AppData) { byte[] Decrypted_Amiibo; if (IsEncrypted(Data)) { Decrypted_Amiibo = Amiibo_Class.Decrypt(Data, Main_Form.AmiiKeys); } else { Decrypted_Amiibo = Data; } Array.Copy(AppData, 0x000, Decrypted_Amiibo, 0x0DC, 0x0D8); if (IsEncrypted(Data)) { return(Amiibo_Class.Encrypt(Decrypted_Amiibo, Main_Form.AmiiKeys)); } else { return(Decrypted_Amiibo); } }
private async void button2_Click(object sender, EventArgs e) { comboBox1.Enabled = false; comboBox2.Enabled = false; comboBox3.Enabled = false; checkBox1.Enabled = false; button2.Enabled = false; textBox1.Text = ""; if (comboBox3.SelectedIndex == 0) { Arduino = new Arduino_Class(comboBox1.SelectedValue.ToString(), comboBox2.SelectedItem.ToString()); if (Arduino.Serial.IsOpen) { toolStripStatusLabel1.Text = i18n.__("NFC_Connected"); string DeviceNFC = i18n.__("NFC_NTAG215"); if (!Action_Write) { DeviceNFC = i18n.__("NFC_Amiibo_NTAG215"); } MessageBox.Show(i18n.__("NFC_Put_NTAG1", DeviceNFC) + Environment.NewLine + i18n.__("NFC_Put_NTAG2"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.Text = i18n.__("NFC_Wait_NTAG"); await Task.Run(() => { while (!NTAG_isHere()) { } }); textBox1.AppendText(i18n.__("NFC_Found_NTAG") + Environment.NewLine + Environment.NewLine); string NTAG_Short_UID = Arduino.SendCommand("/GET_NTAG_UID"); if (NTAG_Short_UID.Length == 14) { if (Action_Write) { textBox1.AppendText(i18n.__("NFC_Short_UID") + " " + NTAG_Short_UID + Environment.NewLine); string NTAG_Long_UID = BitConverter.ToString(Amiibo_Class.Calculate_Long_UID(NTAG_Short_UID)).Replace("-", ""); textBox1.AppendText(i18n.__("NFC_Long_UID") + " " + NTAG_Long_UID + Environment.NewLine + Environment.NewLine); byte[] Amiibo_Data = Amiibo_Class.Patch(File.ReadAllBytes(Current_File_Bin), NTAG_Long_UID); textBox1.AppendText("\"" + Current_File_Bin + "\" " + i18n.__("NFC_Patched") + Environment.NewLine); if (checkBox1.Checked) { Arduino.SendCommand("/WRITE_AMIIBO 1"); } else { Arduino.SendCommand("/WRITE_AMIIBO 0"); } string Result = Arduino.SendCommand(Amiibo_Data); textBox1.AppendText("\"" + Current_File_Bin + "\" " + i18n.__("NFC_Send") + Environment.NewLine + Environment.NewLine); if (Result.Split('/', ' ')[1] == "ERROR") { textBox1.AppendText(i18n.__("NFC_Error") + " " + Result.Substring(1) + Environment.NewLine); } else if (Result.Split('/', ' ')[1] == "END_WRITE") { textBox1.AppendText(i18n.__("NFC_Amiibo_Ready") + Environment.NewLine); } else { textBox1.AppendText(i18n.__("NFC_Unknown_Response") + " " + Result + Environment.NewLine); } } else { byte[] Amiibo_Dump = new byte[540]; int i; for (i = 0; i < 135; i++) { string Result = Arduino.SendCommand("/READ_AMIIBO " + i); string[] SplitResult = Result.Split('/', ' '); if (SplitResult.Length > 1) { if (Result.Split('/', ' ')[1] == "ERROR") { textBox1.AppendText(i18n.__("NFC_Error") + " " + Result.Substring(1) + Environment.NewLine); } else { textBox1.AppendText(i18n.__("NFC_Unknown_Response") + " " + Result + Environment.NewLine); } i = 135; } else { textBox1.AppendText(i18n.__("NFC_Page_Readed", (i + 1)) + Environment.NewLine); byte[] Buffer = Helper_Class.String_To_Byte_Array(Result); Array.Copy(Buffer, 0, Amiibo_Dump, i * 4, Buffer.Length); } } if (i == 135) { textBox1.AppendText(i18n.__("NFC_Reading_Finished") + Environment.NewLine); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = i18n.__("NFC_Save_Dump_Amiibo_Filter", "|*.bin"); saveFileDialog1.Title = i18n.__("NFC_Save_Dump_Amiibo_Title"); saveFileDialog1.InitialDirectory = Bin_Folder; byte[] Decrypted_Amiibo = Amiibo_Class.Decrypt(Amiibo_Dump, Main_Form.AmiiKeys); string[] AmiiboLife_Info = AmiiboInfo_Class.Get_AmiiboInfo(Amiibo_Class.Get_NFC_ID(Decrypted_Amiibo)); byte[] UID = new byte[0x07]; Array.Copy(Amiibo_Dump, 0, UID, 0, UID.Length); saveFileDialog1.FileName = ((AmiiboLife_Info[0].Trim() != "") ? AmiiboLife_Info[0].Trim().Replace(" ", "_") : BitConverter.ToString(UID).Replace("-", "")) + ".bin"; if (saveFileDialog1.ShowDialog(this.Parent) == DialogResult.OK && saveFileDialog1.FileName != "") { File.WriteAllBytes(saveFileDialog1.FileName, Amiibo_Dump); MessageBox.Show(this, i18n.__("NFC_Save_Dump_Amiibo_Message"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } else { textBox1.AppendText(i18n.__("NFC_Wrong_Tag_Model") + Environment.NewLine); } Arduino.SendCommand("/NTAG_HALT"); Arduino.Close(); } else { toolStripStatusLabel1.Text = i18n.__("NFC_No_Connected"); MessageBox.Show(i18n.__("NFC_No_Connection"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } comboBox1.Enabled = true; //comboBox2.Enabled = true; comboBox3.Enabled = true; checkBox1.Enabled = true; button2.Enabled = true; } else { } }
private void decryptToolStripMenuItem_Click(object sender, EventArgs e) { string FileName = listView1.SelectedItems[0].Text.Trim(); if (File_IsEncrypted(FileName)) { File.WriteAllBytes(Path.Combine(Current_Folder, Path.GetFileNameWithoutExtension(FileName) + ".dec.bin"), Amiibo_Class.Decrypt(File.ReadAllBytes(Path.Combine(Current_Folder, FileName)), AmiiKeys)); } else { File.WriteAllBytes(Path.Combine(Current_Folder, Path.GetFileNameWithoutExtension(FileName) + ".enc.bin"), Amiibo_Class.Encrypt(File.ReadAllBytes(Path.Combine(Current_Folder, FileName)), AmiiKeys)); } }
private void Get_FileInfo(string BinFile) { byte[] Decrypted_Amiibo; if (File_IsEncrypted(BinFile)) { Decrypted_Amiibo = Amiibo_Class.Decrypt(File.ReadAllBytes(Path.Combine(Current_Folder, BinFile)), AmiiKeys); spoofRandomIDToolStripMenuItem.Enabled = true; } else { Decrypted_Amiibo = File.ReadAllBytes(Path.Combine(Current_Folder, BinFile)); spoofRandomIDToolStripMenuItem.Enabled = false; } string Char_ID = Amiibo_Class.Get_Character_ID(Decrypted_Amiibo); string GameSeries_ID = Amiibo_Class.Get_GameSeries_ID(Decrypted_Amiibo); string NFC_ID = Amiibo_Class.Get_NFC_ID(Decrypted_Amiibo); currentAmiiboToolStripMenuItem.DropDownItems.Clear(); int Init = Amiibo_Class.Get_Amiibo_Initialize_UserData(Decrypted_Amiibo); if (Init != 0) { if (Init == 16 || Init == 48) { currentAmiiboToolStripMenuItem.DropDownItems.Add(i18n.__("Menu_Amiibo_Owner") + ": " + Amiibo_Class.Get_Amiibo_Mii_Nickname(Decrypted_Amiibo)); currentAmiiboToolStripMenuItem.DropDownItems.Add(i18n.__("Menu_Amiibo_Nickname") + ": " + Amiibo_Class.Get_Amiibo_Nickname(Decrypted_Amiibo)); } if (Init == 48) { currentAmiiboToolStripMenuItem.DropDownItems.Add(i18n.__("Menu_Amiibo_LastModDate") + ": " + Amiibo_Class.Get_Amiibo_LastModifiedDate(Decrypted_Amiibo)); currentAmiiboToolStripMenuItem.DropDownItems.Add(i18n.__("Menu_Amiibo_WriteCounter") + ": " + Amiibo_Class.Get_Amiibo_Write_Counter(Decrypted_Amiibo)); currentAmiiboToolStripMenuItem.DropDownItems.Add(i18n.__("Menu_Amiibo_AppID") + ": " + Amiibo_Class.Get_Amiibo_AppID(Decrypted_Amiibo)); currentAmiiboToolStripMenuItem.DropDownItems.Add(i18n.__("Menu_Amiibo_InitAppID") + ": " + Amiibo_Class.Get_Amiibo_Initialized_AppID(Decrypted_Amiibo)); currentAmiiboToolStripMenuItem.DropDownItems.Add(i18n.__("Menu_Amiibo_Country") + ": " + Amiibo_Class.Get_Amiibo_Country(Decrypted_Amiibo)); } } else { currentAmiiboToolStripMenuItem.DropDownItems.Add(i18n.__("Menu_Amiibo_Sorry")); } foreach (ToolStripMenuItem Item in currentAmiiboToolStripMenuItem.DropDownItems) { Item.RightToLeft = RightToLeft.No; Item.Enabled = false; } string Cache_File_Path = Path.Combine("cache", Path.GetFileNameWithoutExtension(BinFile) + ".amiibomb"); if (File.Exists(Cache_File_Path) && Config.Cache) { Stream stream = File.Open(Cache_File_Path, FileMode.Open); var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); AmiiboInfo_Cache_Class Cache_File = (AmiiboInfo_Cache_Class)binaryFormatter.Deserialize(stream); stream.Close(); if (Helper_Class.ValidSHA1(Decrypted_Amiibo, Cache_File.SHA1)) { Current_NFC_ID = Cache_File.NFC_ID; pictureBox1.Image = Cache_File.Picture; nameToolStripMenuItem.Text = label3.Text = Cache_File.Name; seriesToolStripMenuItem.Text = label4.Text = Cache_File.Serie; } else { File.Delete(Cache_File_Path); Get_FileInfo(BinFile); } } else { Current_NFC_ID = NFC_ID; string[] AmiiboLife_Info = AmiiboInfo_Class.Get_AmiiboInfo(NFC_ID); if (AmiiboLife_Info[2] != "") { pictureBox1.Load(AmiiboLife_Info[2]); pictureBox1.Image = Helper_Class.DropShadow(pictureBox1.Image); } else { pictureBox1.Image = null; } nameToolStripMenuItem.Text = AmiiboLife_Info[0].Trim(); label3.Text = AmiiboLife_Info[0].Trim(); seriesToolStripMenuItem.Text = AmiiboLife_Info[1].Trim(); label4.Text = AmiiboLife_Info[1].Trim(); AmiiboInfo_Cache_Class Cache_File = new AmiiboInfo_Cache_Class(); Cache_File.SHA1 = Helper_Class.SHA1_File(Decrypted_Amiibo); Cache_File.Name = AmiiboLife_Info[0].Trim(); Cache_File.Serie = AmiiboLife_Info[1].Trim(); Cache_File.NFC_ID = Current_NFC_ID; Cache_File.Picture = pictureBox1.Image; if (Config.Cache && AmiiboLife_Info[0] != "" && AmiiboLife_Info[1] != "" && AmiiboLife_Info[2] != "") { Stream stream = File.Open(Cache_File_Path, FileMode.Create); var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); binaryFormatter.Serialize(stream, Cache_File); stream.Close(); } if (AmiiboLife_Info[0] == "" || AmiiboLife_Info[1] == "" || AmiiboLife_Info[2] == "") { moreInformationsToolStripMenuItem.Visible = false; } else { moreInformationsToolStripMenuItem.Visible = true; } } }
private void button1_Click(object sender, EventArgs e) { button1.Enabled = false; MessageBox.Show(i18n.__("PowerSaves_Put_Tag"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); if (thRead_Tag != null && thRead_Tag.IsAlive) { thRead_Tag.Abort(); } thRead_Tag = new Thread(() => { try { USBHID_Device = new HIDDevice(USBHID_DevicePath, false); textBox2.Invoke(new Action(() => textBox2.Text = "")); USBHID_Device.Write(new byte[] { 0x20, 0xFF }); USBHID_Device.Write(new byte[] { 0x11 }); USBHID_Device.Read(); USBHID_Device.Write(new byte[] { 0x10 }); USBHID_Device.Read(); textBox2.Invoke(new Action(() => textBox2.AppendText(i18n.__("PowerSaves_Wait_Tag")))); byte[] UID_Data; while (true) { USBHID_Device.Write(new byte[] { 0x12 }); UID_Data = USBHID_Device.Read(); if (UID_Data.Skip(5).Take(1).ToArray()[0] == 7) { break; } } textBox2.Invoke(new Action(() => textBox2.AppendText(" " + i18n.__("PowerSaves_Found_NTAG") + Environment.NewLine))); textBox2.Invoke(new Action(() => textBox2.AppendText(i18n.__("PowerSaves_Short_UID") + " " + BitConverter.ToString(UID_Data.Skip(6).Take(7).ToArray()).Replace("-", "") + Environment.NewLine + Environment.NewLine))); byte[] Amiibo_Dump = new byte[0]; for (int i = 0x00; i < 0x88; i = i + 0x04) { Read: int Take = 16; if (i == 0x84) { Take = 12; } USBHID_Device.Write(new byte[] { 0x1C, (byte)i }); byte[] Readed_Bytes = USBHID_Device.Read().Skip(3).Take(Take).ToArray(); int Sum = 0; foreach (byte Value in Readed_Bytes) { Sum += Value; } if (Sum == 0) { textBox2.Invoke(new Action(() => textBox2.AppendText(i18n.__("PowerSaves_Pages_Error", i, i + 3) + Environment.NewLine))); goto Read; } textBox2.Invoke(new Action(() => textBox2.AppendText(i18n.__("PowerSaves_Pages_Readed", i, i + 3) + Environment.NewLine))); Array.Resize(ref Amiibo_Dump, Amiibo_Dump.Length + Take); Array.Copy(Readed_Bytes, 0, Amiibo_Dump, Amiibo_Dump.Length - Take, Take); } textBox2.Invoke(new Action(() => textBox2.AppendText(i18n.__("PowerSaves_Reading_Finished") + Environment.NewLine))); this.Invoke(new Action(() => { byte[] Decrypted_Amiibo = Amiibo_Class.Decrypt(Amiibo_Dump, Main_Form.AmiiKeys); string[] AmiiboLife_Info = AmiiboInfo_Class.Get_AmiiboInfo(Amiibo_Class.Get_NFC_ID(Decrypted_Amiibo)); byte[] UID = new byte[0x07]; Array.Copy(Amiibo_Dump, 0, UID, 0, UID.Length); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = i18n.__("PowerSaves_Save_Dump_Amiibo_Filter", "|*.bin"); saveFileDialog1.Title = i18n.__("PowerSaves_Save_Dump_Amiibo_Title"); saveFileDialog1.InitialDirectory = Bin_Folder; saveFileDialog1.FileName = ((AmiiboLife_Info[0].Trim() != "") ? AmiiboLife_Info[0].Trim().Replace(" ", "_") : BitConverter.ToString(UID).Replace("-", "")) + ".bin"; if (saveFileDialog1.ShowDialog(this.Parent) == DialogResult.OK && saveFileDialog1.FileName != "") { File.WriteAllBytes(saveFileDialog1.FileName, Amiibo_Dump); MessageBox.Show(this, i18n.__("PowerSaves_Save_Dump_Amiibo_Message"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } })); USBHID_Device.Write(new byte[] { 0x20, 0x00 }); USBHID_Device.Close(); button1.Invoke(new Action(() => button1.Enabled = true)); } catch (ThreadAbortException) { USBHID_Device.Write(new byte[] { 0x20, 0x00 }); USBHID_Device.Close(); } }); thRead_Tag.Start(); }