diff --git a/Class_Cypher.cs b/Class_Cypher.cs index 2ee4361..303a6dc 100644 --- a/Class_Cypher.cs +++ b/Class_Cypher.cs @@ -190,7 +190,7 @@ public class Class_Cypher //######################################### //######################################### IL_170: - //(((k2 != 0 ? s * k1 % k2 : s * k1) ^ (s + k0)) & 0xFFFF) + //PERFORM CYPHER WORK BELLOW /*Console.WriteLine("num:" + num.ToString()); //num = 2920096767U -> FF-23-0D-AE Console.WriteLine("num2:" + num2.ToString()); //num2 = 1080383667U -> B3-58-65-40 Console.WriteLine("num3:" + num3.ToString()); //num3 = 0 diff --git a/Class_RWD.cs b/Class_RWD.cs index 839a387..7f3db96 100644 --- a/Class_RWD.cs +++ b/Class_RWD.cs @@ -16,6 +16,12 @@ static class Class_RWD public static byte[] _firmware_encrypted = new byte[] { }; public static UInt32 start = 0U; public static UInt32 size = 0U; + private static string[] SuppportedVersions = new string[] { }; + private static string[] SuppportedFWKeys = new string[] { }; + private static string CanAddress = ""; + private static byte[] DecodersBytes = new byte[] { }; //Used to decode rwd to bin + private static byte[] EncodersBytes = new byte[] { }; //Used to encode bin to rwd + private static byte[] RWD_encrypted_StartFile = new byte[] { }; //Used to encode bin to rwd private static GForm_Main GForm_Main_0; @@ -24,17 +30,99 @@ static class Class_RWD GForm_Main_0 = GForm_Main_1; } + public static void CompressFile(string ThisFile, string CompressedName) + { + FileStream originalFileStream = File.Open(ThisFile, FileMode.Open); + FileStream compressedFileStream = File.Create(CompressedName); + GZipStream compressor = new GZipStream(compressedFileStream, CompressionMode.Compress); + originalFileStream.CopyTo(compressor); + } + public static byte[] Decompress(string ThisFile) { Stream compressedStream = new MemoryStream(File.ReadAllBytes(ThisFile)); - var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress); + GZipStream zipStream = new GZipStream(compressedStream, CompressionMode.Decompress); MemoryStream resultStream = new MemoryStream(); zipStream.CopyTo(resultStream); return resultStream.ToArray(); } + public static UInt16 ToUInt16BE(byte[] TwoBytes) + { + UInt16 k0 = BitConverter.ToUInt16(TwoBytes, 0); + UInt16 k1 = BitConverter.ToUInt16(BitConverter.GetBytes(k0).Reverse().ToArray(), 0); + return k1; + } - public static void LoadRWD(string f_name, bool FullDecrypt) + private static UInt16 checksum_by_sum(byte[] fw, uint start, uint end) + { + int s = 0; + uint valuescount = (end - start) / 2; + for (int i = 0; i < valuescount; i++) + { + byte[] ThisTwoBytes = new byte[2] { fw[start + (i*2)], fw[start + (i * 2) + 1] }; + s += ToUInt16BE(ThisTwoBytes); + + if (s > 0xFFFF) s -= 0xFFFF; + } + return (UInt16) s; + } + + private static UInt16 checksum_by_negative_sum(byte[] fw, uint start, uint end) + { + int s = 0; + uint valuescount = (end - start) / 2; + for (int i = 0; i < valuescount; i++) + { + byte[] ThisTwoBytes = new byte[2] { fw[start + (i * 2)], fw[start + (i * 2) + 1] }; + s -= ToUInt16BE(ThisTwoBytes); + + if (s < 0) s += 0xFFFF; + } + return (UInt16) s; + } + + //###################################################################################################### + //###################################################################################################### + public static void LoadBIN(string f_name, string f_nameFW) + { + byte[] data = File.ReadAllBytes(f_name); + GForm_Main_0.method_1("Encrypting file: " + f_name); + + //Load .rwd file for obtaining 'encryption' method and then encrypt the .bin using the same method. + LoadRWD(f_nameFW, true, false); + + //Copy Start file bytes from the selected rwd file + byte[] dataEncrypted = new byte[RWD_encrypted_StartFile.Length + data.Length]; + for (int i = 0; i < RWD_encrypted_StartFile.Length; i++) dataEncrypted[i] = RWD_encrypted_StartFile[i]; + + //Encrypt .bin data bytes to .rwd format + for (int i = 0; i < data.Length; i++) + { + byte ThisByte = data[i]; + dataEncrypted[RWD_encrypted_StartFile.Length + i] = EncodersBytes[ThisByte]; + } + + //Fix Checksums + //TODO HERE ####################################### + + //Save Encrypted rwd firmware + string ThisPath = Path.GetDirectoryName(f_name) + @"\" + Path.GetFileNameWithoutExtension(f_name) + ".rwd"; + File.Create(ThisPath).Dispose(); + File.WriteAllBytes(ThisPath, dataEncrypted); + GForm_Main_0.method_1("Saved encrypted firmware file: " + ThisPath); + + //Save ZIPPED Encrypted firmware + CompressFile(ThisPath, ThisPath + ".gz"); + } + + /*'39990-TLA-A030': { #CR-V thanks to joe1 + 'checksum-offsets': [(0, 0x6bf80), (1, 0x6bffe)] #original bin checksums are 0x419b at offset 0x6FF80 and 0x24ef at 0x6FFFE, but since we start the bin from 0x4000 after bootloader, we offset the checksum accordingly + },*/ + + //###################################################################################################### + //###################################################################################################### + public static void LoadRWD(string f_name, bool FullDecrypt, bool Saving) { byte[] data = new byte[] { }; if (Path.GetExtension(f_name).ToLower().Contains("gz")) data = Decompress(f_name); @@ -90,6 +178,10 @@ static class Class_RWD size = ReadUInt32BE(data, idx); idx += 4; + //Get Start file bytes array + RWD_encrypted_StartFile = new byte[idx]; + for (int i = 0; i < idx; i++) RWD_encrypted_StartFile[i] = data[i]; + byte[] firmware = Slice(data, idx, data.Length - 4); idx += firmware.Length; @@ -102,10 +194,55 @@ static class Class_RWD _firmware_encrypted = firmware; _keys = headers5; - if (FullDecrypt) DecryptRWD(f_name); + //Get supported versions and supported firmwares keys + int VersionsCount = (headers3.Length / 16); + SuppportedVersions = new string[VersionsCount]; + SuppportedFWKeys = new string[VersionsCount]; + string SoftwareKey = _keys[0].ToString("X2") + _keys[1].ToString("X2") + _keys[2].ToString("X2"); + for (int i = 0; i < VersionsCount; i++) + { + //Get Supported versions + byte[] buf = new byte[16]; + int EmptyCount = 0; + for (int i2 = 0; i2 < 16; i2++) + { + buf[i2] = headers3[(i * 16) + i2]; + if (buf[i2] == 0) + { + buf[i2] = 0x2E; + EmptyCount++; + } + } + //Remove Empty chars + byte[] bufRedo = new byte[16 - EmptyCount]; + for (int i2 = 0; i2 < bufRedo.Length; i2++) bufRedo[i2] = buf[i2]; + SuppportedVersions[i] = System.Text.Encoding.ASCII.GetString(bufRedo); + + //Get supported Firmwares keys according to the supported versions + byte[] bufkey = new byte[6]; + for (int i2 = 0; i2 < 6; i2++) + { + bufkey[i2] = headers4[(i * 6) + i2]; + } + SuppportedFWKeys[i] = bufkey[0].ToString("X2") + bufkey[1].ToString("X2") + bufkey[2].ToString("X2") + bufkey[3].ToString("X2") + bufkey[4].ToString("X2") + bufkey[5].ToString("X2"); + } + + //Get CanAddress Infos + CanAddress = "18DA" + headers2[0].ToString("X") + "F1"; + + //Print/Log Informations + GForm_Main_0.method_1("Firmware Start: 0x" + start.ToString("X")); + GForm_Main_0.method_1("Firmware Size: 0x" + size.ToString("X")); + GForm_Main_0.method_1("CanAddress: 0x" + CanAddress); + GForm_Main_0.method_1("Software Keys: 0x" + SoftwareKey); + GForm_Main_0.method_1("Supported Versions (and keys): "); + for (int i = 0; i < SuppportedVersions.Length; i++) GForm_Main_0.method_1(SuppportedVersions[i] + " (0x" + SuppportedFWKeys[i] + ")"); + + //Perform FULL decryption (convert .rwd to .bin) + if (FullDecrypt) DecryptRWD(f_name, Saving); } - private static void DecryptRWD(string f_name) + private static void DecryptRWD(string f_name, bool Saving) { part_number_prefix = get_part_number_prefix(f_name); firmware_candidates = decrypt(part_number_prefix); @@ -125,6 +262,24 @@ static class Class_RWD return; } + //Remove duplicated Candidates + if (firmware_candidates.Count > 1) + { + List firmware_candidatesBUFFER = firmware_candidates; + firmware_candidates = new List(); + + byte[] LastCandidate = firmware_candidatesBUFFER[firmware_candidatesBUFFER.Count - 1]; + for (int i = 0; i < firmware_candidatesBUFFER.Count - 1; i++) + { + byte[] CurrentCandidate = firmware_candidatesBUFFER[i]; + if (CurrentCandidate != LastCandidate) + { + firmware_candidates.Add(CurrentCandidate); + } + } + firmware_candidates.Add(LastCandidate); + } + if (firmware_candidates.Count > 1) GForm_Main_0.method_1("multiple sets of keys resulted in data containing the part number"); //################################################################### @@ -182,13 +337,23 @@ static class Class_RWD //################################################################### //Saving Decrypted Firmwares - foreach (byte[] f_data in firmware_candidates) - //foreach (byte[] f_data in firmware_good) + if (Saving) { - uint start_addr = start; - string ThisPath = Path.GetDirectoryName(f_name) + @"\" + Path.GetFileNameWithoutExtension(f_name).Replace(".rwd", "").Replace(".RWD", "") + ".0x" + start_addr.ToString("X") + ".bin"; - File.Create(ThisPath).Dispose(); - File.WriteAllBytes(ThisPath, f_data); //-> f_data[start_addr:] + bool AsSavedFile = false; + int FileCount = 1; + foreach (byte[] f_data in firmware_candidates) + { + string FileNumber = ""; + if (firmware_candidates.Count > 1) FileNumber = "_" + FileCount; + string ThisPath = Path.GetDirectoryName(f_name) + @"\" + Path.GetFileNameWithoutExtension(f_name).Replace(".rwd", "").Replace(".RWD", "") + ".0x" + start.ToString("X") + FileNumber + ".bin"; + File.Create(ThisPath).Dispose(); + File.WriteAllBytes(ThisPath, f_data); //-> f_data[start_addr:] + GForm_Main_0.method_1("Saved decrypted firmware file: " + ThisPath); + AsSavedFile = true; + FileCount++; + } + + if (AsSavedFile) GForm_Main_0.method_1("Note: The decrypted firmware file (.bin), is not a complete .bin file! It cannot be used to perform a 'Flash Rom' to the ECU, the bootloader section from 0x0000 to 0x" + start.ToString("X") + " of the rom is Missing."); } } @@ -403,6 +568,21 @@ static class Class_RWD return BufferedContent; } + private static void MakeEncoderArray() + { + EncodersBytes = new byte[256]; + if (DecodersBytes.Length != EncodersBytes.Length) + { + GForm_Main_0.method_1("Something went wrong getting Encoders bytes!"); + } + else + { + for (int i = 0; i < EncodersBytes.Length; i++) + { + EncodersBytes[DecodersBytes[i]] = (byte) i; + } + } + } private static List decrypt(string search_value) { @@ -415,13 +595,14 @@ static class Class_RWD search_value_padded += ThisChar + "."; } GForm_Main_0.method_1("Searching:"); - GForm_Main_0.method_1(search_value); - GForm_Main_0.method_1(search_value_padded); + //GForm_Main_0.method_1(search_value); + //GForm_Main_0.method_1(search_value_padded); + + string search_exact = search_value.ToUpper(); + string search_padded = search_value_padded.ToUpper(); + GForm_Main_0.method_1(search_exact); + GForm_Main_0.method_1(search_padded); - string search_exact = search_value; - string search_padded = search_value_padded; - //string search_exact = re.compile(".*" + search_value + ".*", flags = re.IGNORECASE | re.MULTILINE | re.DOTALL); //############################### - //string search_padded = re.compile(".*" + search_value_padded + ".*", flags = re.IGNORECASE | re.MULTILINE | re.DOTALL); //############################### string[] operators = new string[8] { "fn:^", //XOR "fn:&", //AND @@ -439,7 +620,13 @@ static class Class_RWD string k = _keys[i].ToString("x2"); keys.Add(String.Format("val:" + k + ",sym:" + "k{0}", i)); } - //assert len(keys) == 3, "excatly three keys currently required!"; + + if (keys.Count != 3) + { + GForm_Main_0.method_1("excatly three keys currently required, cannot perform decryption!"); + return new List { }; + //return null; + } List firmware_candidates_0 = new List { }; @@ -495,6 +682,7 @@ static class Class_RWD DoneCount++; } } + //Get operators values foreach (string LineOP in op_perms) { @@ -514,20 +702,22 @@ static class Class_RWD } } + //Perform decoding of bytes and search for ECU name string int Percent = (CurrentDone * 100) / (key_perms.Length * op_perms.Length); GForm_Main_0.method_4(Percent); CurrentDone++; - byte[] decoder = _get_decoder(k1, k2, k3, o1, o2, o3); - if (decoder != null && !attempted_decoders.Contains(decoder)) + DecodersBytes = _get_decoder(k1, k2, k3, o1, o2, o3); + //MakeEncoderArray(); + if (DecodersBytes != null && !attempted_decoders.Contains(DecodersBytes)) { - attempted_decoders.Add(decoder); + attempted_decoders.Add(DecodersBytes); byte[] candidate = new byte[_firmware_encrypted.Length]; char[] decryptedCharArr = new char[_firmware_encrypted.Length]; for (int i2 = 0; i2 < _firmware_encrypted.Length; i2++) { - byte ThisByte = decoder[_firmware_encrypted[i2]]; + byte ThisByte = DecodersBytes[_firmware_encrypted[i2]]; candidate[i2] = ThisByte; decryptedCharArr[i2] = (char) ThisByte; } @@ -535,6 +725,7 @@ static class Class_RWD if ((decrypted.Contains(search_exact) || decrypted.Contains(search_padded)) && !firmware_candidates_0.Contains(candidate)) { + MakeEncoderArray(); GForm_Main_0.method_Log("X"); firmware_candidates_0.Add(candidate); display_ciphers.Add(string.Format("(((i {0} {1}) {2} {3}) {4} {5}) & 0xFF", @@ -551,6 +742,8 @@ static class Class_RWD } } + GForm_Main_0.ResetProgressBar(); + GForm_Main_0.method_1(Environment.NewLine); foreach (string cipher in display_ciphers) { GForm_Main_0.method_1(String.Format("cipher: {0}", cipher)); diff --git a/FlashToolTest.csproj b/FlashToolTest.csproj index 083dbe3..2178ac9 100644 --- a/FlashToolTest.csproj +++ b/FlashToolTest.csproj @@ -62,6 +62,9 @@ + + Form + Form @@ -73,6 +76,9 @@ + + GForm_ConvertBIN.cs + GForm_Main.cs diff --git a/GForm_ConvertBIN.cs b/GForm_ConvertBIN.cs new file mode 100644 index 0000000..1c93012 --- /dev/null +++ b/GForm_ConvertBIN.cs @@ -0,0 +1,194 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using System.Runtime.CompilerServices; +using System.Windows.Forms; +using DarkUI.Controls; +using DarkUI.Forms; + + +public class GForm_ConvertBIN : DarkForm +{ + + public GForm_ConvertBIN() + { + this.InitializeComponent(); + } + + public string FileBIN { get; set; } + public string FileRWD { get; set; } + + private void method_0(object sender, EventArgs e) + { + this.FileBIN = this.textBox_bin.Text; + this.FileRWD = this.textBox_rwd.Text; + base.Close(); + } + + private void method_1(object sender, EventArgs e) + { + + } + + private void method_2(object sender, EventArgs e) + { + base.DialogResult = DialogResult.Abort; + base.Close(); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing && this.icontainer_0 != null) + { + this.icontainer_0.Dispose(); + } + base.Dispose(disposing); + } + + private void InitializeComponent() + { + this.darkButton_0 = new DarkUI.Controls.DarkButton(); + this.darkButton_1 = new DarkUI.Controls.DarkButton(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBox_bin = new System.Windows.Forms.TextBox(); + this.textBox_rwd = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.SuspendLayout(); + // + // darkButton_0 + // + this.darkButton_0.Checked = false; + this.darkButton_0.DialogResult = System.Windows.Forms.DialogResult.OK; + this.darkButton_0.Location = new System.Drawing.Point(257, 154); + this.darkButton_0.Name = "darkButton_0"; + this.darkButton_0.Size = new System.Drawing.Size(75, 23); + this.darkButton_0.TabIndex = 4; + this.darkButton_0.Text = "Accept"; + this.darkButton_0.Click += new System.EventHandler(this.method_0); + // + // darkButton_1 + // + this.darkButton_1.Checked = false; + this.darkButton_1.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.darkButton_1.Location = new System.Drawing.Point(12, 154); + this.darkButton_1.Name = "darkButton_1"; + this.darkButton_1.Size = new System.Drawing.Size(75, 23); + this.darkButton_1.TabIndex = 5; + this.darkButton_1.Text = "Cancel"; + this.darkButton_1.Click += new System.EventHandler(this.method_2); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.ForeColor = System.Drawing.SystemColors.ControlLight; + this.label1.Location = new System.Drawing.Point(12, 61); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(168, 13); + this.label1.TabIndex = 6; + this.label1.Text = "Select decrypted firmware .bin file:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.ForeColor = System.Drawing.SystemColors.ControlLight; + this.label2.Location = new System.Drawing.Point(12, 106); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(171, 13); + this.label2.TabIndex = 7; + this.label2.Text = "Select encrypted firmware .rwd file:"; + // + // textBox_bin + // + this.textBox_bin.Location = new System.Drawing.Point(12, 79); + this.textBox_bin.Name = "textBox_bin"; + this.textBox_bin.Size = new System.Drawing.Size(320, 20); + this.textBox_bin.TabIndex = 8; + this.textBox_bin.DoubleClick += new System.EventHandler(this.textBox_bin_DoubleClick); + // + // textBox_rwd + // + this.textBox_rwd.Location = new System.Drawing.Point(12, 124); + this.textBox_rwd.Name = "textBox_rwd"; + this.textBox_rwd.Size = new System.Drawing.Size(320, 20); + this.textBox_rwd.TabIndex = 9; + this.textBox_rwd.DoubleClick += new System.EventHandler(this.textBox_rwd_DoubleClick); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.ForeColor = System.Drawing.SystemColors.ControlLight; + this.label3.Location = new System.Drawing.Point(11, 10); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(324, 39); + this.label3.TabIndex = 10; + this.label3.Text = "To create a firmware .rwd file from a decrypted .bin, you must select\r\nthe .rwd f" + + "irmware from which it has been decrypted from in\r\norder to use the same encrypti" + + "on method"; + this.label3.TextAlign = System.Drawing.ContentAlignment.TopCenter; + // + // openFileDialog1 + // + this.openFileDialog1.Title = "Select File"; + // + // GForm_ConvertBIN + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(344, 187); + this.ControlBox = false; + this.Controls.Add(this.label3); + this.Controls.Add(this.textBox_rwd); + this.Controls.Add(this.textBox_bin); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.darkButton_1); + this.Controls.Add(this.darkButton_0); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "GForm_ConvertBIN"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Convert .bin to .rwd"; + this.Load += new System.EventHandler(this.method_1); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + [CompilerGenerated] + private IContainer icontainer_0; + private DarkButton darkButton_0; + private Label label1; + private Label label2; + private TextBox textBox_bin; + private TextBox textBox_rwd; + private Label label3; + private OpenFileDialog openFileDialog1; + private DarkButton darkButton_1; + + private void textBox_bin_DoubleClick(object sender, EventArgs e) + { + this.openFileDialog1.Filter = "Honda decompressed firmware binary|*.bin"; + this.openFileDialog1.DefaultExt = "*.bin"; + + DialogResult result = this.openFileDialog1.ShowDialog(); + if (result == DialogResult.OK) + { + this.textBox_bin.Text = this.openFileDialog1.FileName; + } + } + + private void textBox_rwd_DoubleClick(object sender, EventArgs e) + { + this.openFileDialog1.Filter = "Honda compressed firmware file|*.rwd;*.gz"; + this.openFileDialog1.DefaultExt = "*.gz"; + + DialogResult result = this.openFileDialog1.ShowDialog(); + if (result == DialogResult.OK) + { + this.textBox_rwd.Text = this.openFileDialog1.FileName; + } + } +} diff --git a/GForm_ConvertBIN.resx b/GForm_ConvertBIN.resx new file mode 100644 index 0000000..3a7d671 --- /dev/null +++ b/GForm_ConvertBIN.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/GForm_Main.cs b/GForm_Main.cs index 268be0a..2036bc8 100644 --- a/GForm_Main.cs +++ b/GForm_Main.cs @@ -22,9 +22,9 @@ public class GForm_Main : DarkForm private OpenFileDialog openFileDialog1; byte Unlocking_Mode = 0x41; bool WritingBinaryMode = true; //if false we are in writing firmware mode - private DarkButton darkButton3; + private DarkButton darkButton_FlashFW; GForm_Main GForm_Main_0; - UInt16 block_size = 0; + private DarkButton darkButton3; public GForm_Main() { @@ -113,7 +113,8 @@ public class GForm_Main : DarkForm this.darkButton_DownloadROM.Enabled = false; this.darkButton_Unlock41.Enabled = false; this.darkButton_Unlock01.Enabled = false; - this.darkButton_5.Enabled = false; + this.darkButton_FlashRom.Enabled = false; + this.darkButton_FlashFW.Enabled = false; using (API api = APIFactory.GetAPI(GForm_Main.string_0)) { @@ -236,6 +237,13 @@ public class GForm_Main : DarkForm Application.DoEvents(); } + public void ResetProgressBar() + { + this.darkProgressBar_0.Value = 0; + this.darkLabel_7.Text = "Status"; + Application.DoEvents(); + } + private void method_6(object sender, ProgressChangedEventArgs e) { @@ -273,7 +281,8 @@ public class GForm_Main : DarkForm this.darkButton_DownloadROM.Enabled = false; this.darkButton_Unlock41.Enabled = false; this.darkButton_Unlock01.Enabled = false; - this.darkButton_5.Enabled = false; + this.darkButton_FlashRom.Enabled = false; + this.darkButton_FlashFW.Enabled = false; } private void darkButton2_Click(object sender, EventArgs e) @@ -473,15 +482,26 @@ public class GForm_Main : DarkForm { this.method_1("Security Authorized: ECU Unlocked" + Environment.NewLine); ECU_Unlocked = true; - this.darkButton_DownloadROM.Enabled = true; - this.darkButton_5.Enabled = true; + if (!TwoBytesMode) + { + //Unlock ALL buttons (Read&Writes) for 0x27,0x41 Unlock + this.darkButton_DownloadROM.Enabled = true; + this.darkButton_FlashRom.Enabled = true; + this.darkButton_FlashFW.Enabled = true; + } + else + { + //Unlock FlashFW button (Write FW ONLY) for 0x27,0x01 Unlock + this.darkButton_FlashFW.Enabled = true; + } } else { this.method_1("Recv:" + GForm_Main.smethod_1(Received) + Environment.NewLine); ECU_Unlocked = false; this.darkButton_DownloadROM.Enabled = false; - this.darkButton_5.Enabled = false; + this.darkButton_FlashRom.Enabled = false; + this.darkButton_FlashFW.Enabled = false; MessageBox.Show("Failed to Unlock ECU, Check Log"); } } @@ -1024,7 +1044,7 @@ public class GForm_Main : DarkForm WritingBinaryMode = false; //Decrypt firmware file and get needed variable (Decryption byte) - Class_RWD.LoadRWD(openFileDialog1.FileName, false); + Class_RWD.LoadRWD(openFileDialog1.FileName, false, false); //############################### //Get Checksum and Fix it @@ -1465,28 +1485,29 @@ public class GForm_Main : DarkForm this.darkButton_DownloadROM = new DarkUI.Controls.DarkButton(); this.darkButton_0 = new DarkUI.Controls.DarkButton(); this.darkGroupBox_0 = new DarkUI.Controls.DarkGroupBox(); + this.darkButton3 = new DarkUI.Controls.DarkButton(); + this.darkButton_FlashFW = new DarkUI.Controls.DarkButton(); this.darkButton2 = new DarkUI.Controls.DarkButton(); this.darkButton_Unlock01 = new DarkUI.Controls.DarkButton(); + this.darkTextBox_4 = new DarkUI.Controls.DarkTextBox(); this.darkButton_Unlock41 = new DarkUI.Controls.DarkButton(); + this.darkTextBox_3 = new DarkUI.Controls.DarkTextBox(); this.darkButton1 = new DarkUI.Controls.DarkButton(); this.darkButton_6 = new DarkUI.Controls.DarkButton(); - this.darkButton_5 = new DarkUI.Controls.DarkButton(); + this.darkButton_FlashRom = new DarkUI.Controls.DarkButton(); + this.darkLabel_3 = new DarkUI.Controls.DarkLabel(); this.darkButton_4 = new DarkUI.Controls.DarkButton(); + this.darkLabel_2 = new DarkUI.Controls.DarkLabel(); this.darkLabel_0 = new DarkUI.Controls.DarkLabel(); this.darkLabel_1 = new DarkUI.Controls.DarkLabel(); - this.darkLabel_2 = new DarkUI.Controls.DarkLabel(); - this.darkLabel_3 = new DarkUI.Controls.DarkLabel(); this.darkLabel_4 = new DarkUI.Controls.DarkLabel(); this.darkLabel_5 = new DarkUI.Controls.DarkLabel(); this.darkTextBox_1 = new DarkUI.Controls.DarkTextBox(); this.darkTextBox_2 = new DarkUI.Controls.DarkTextBox(); - this.darkTextBox_3 = new DarkUI.Controls.DarkTextBox(); - this.darkTextBox_4 = new DarkUI.Controls.DarkTextBox(); this.darkProgressBar_0 = new DarkUI.Controls.DarkProgressBar(); this.darkLabel_7 = new DarkUI.Controls.DarkLabel(); this.darkLabel_8 = new DarkUI.Controls.DarkLabel(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); - this.darkButton3 = new DarkUI.Controls.DarkButton(); this.darkGroupBox_0.SuspendLayout(); this.SuspendLayout(); // @@ -1535,7 +1556,7 @@ public class GForm_Main : DarkForm // this.darkButton_0.Checked = false; this.darkButton_0.Enabled = false; - this.darkButton_0.Location = new System.Drawing.Point(6, 309); + this.darkButton_0.Location = new System.Drawing.Point(6, 338); this.darkButton_0.Name = "darkButton_0"; this.darkButton_0.Size = new System.Drawing.Size(192, 23); this.darkButton_0.TabIndex = 50; @@ -1547,6 +1568,7 @@ public class GForm_Main : DarkForm // this.darkGroupBox_0.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); this.darkGroupBox_0.Controls.Add(this.darkButton3); + this.darkGroupBox_0.Controls.Add(this.darkButton_FlashFW); this.darkGroupBox_0.Controls.Add(this.darkButton2); this.darkGroupBox_0.Controls.Add(this.darkButton_Unlock01); this.darkGroupBox_0.Controls.Add(this.darkTextBox_4); @@ -1554,7 +1576,7 @@ public class GForm_Main : DarkForm this.darkGroupBox_0.Controls.Add(this.darkTextBox_3); this.darkGroupBox_0.Controls.Add(this.darkButton1); this.darkGroupBox_0.Controls.Add(this.darkButton_6); - this.darkGroupBox_0.Controls.Add(this.darkButton_5); + this.darkGroupBox_0.Controls.Add(this.darkButton_FlashRom); this.darkGroupBox_0.Controls.Add(this.darkLabel_3); this.darkGroupBox_0.Controls.Add(this.darkButton_4); this.darkGroupBox_0.Controls.Add(this.darkButton_0); @@ -1569,6 +1591,27 @@ public class GForm_Main : DarkForm this.darkGroupBox_0.TabStop = false; this.darkGroupBox_0.Text = "J2534 Controls"; // + // darkButton3 + // + this.darkButton3.Checked = false; + this.darkButton3.Location = new System.Drawing.Point(6, 309); + this.darkButton3.Name = "darkButton3"; + this.darkButton3.Size = new System.Drawing.Size(192, 23); + this.darkButton3.TabIndex = 67; + this.darkButton3.Text = "Convert Firmware .bin to .rwd"; + this.darkButton3.Click += new System.EventHandler(this.darkButton3_Click_1); + // + // darkButton_FlashFW + // + this.darkButton_FlashFW.Checked = false; + this.darkButton_FlashFW.Enabled = false; + this.darkButton_FlashFW.Location = new System.Drawing.Point(6, 251); + this.darkButton_FlashFW.Name = "darkButton_FlashFW"; + this.darkButton_FlashFW.Size = new System.Drawing.Size(192, 23); + this.darkButton_FlashFW.TabIndex = 60; + this.darkButton_FlashFW.Text = "Flash Firmware (.rwd)"; + this.darkButton_FlashFW.Click += new System.EventHandler(this.darkButton3_Click); + // // darkButton2 // this.darkButton2.Checked = false; @@ -1576,7 +1619,7 @@ public class GForm_Main : DarkForm this.darkButton2.Name = "darkButton2"; this.darkButton2.Size = new System.Drawing.Size(192, 23); this.darkButton2.TabIndex = 59; - this.darkButton2.Text = "Convert .rwd to .bin"; + this.darkButton2.Text = "Convert Firmware .rwd to .bin"; this.darkButton2.Click += new System.EventHandler(this.darkButton2_Click_1); // // darkButton_Unlock01 @@ -1590,6 +1633,14 @@ public class GForm_Main : DarkForm this.darkButton_Unlock01.Text = "UNLOCK ECU (0x27,0x01)"; this.darkButton_Unlock01.Click += new System.EventHandler(this.darkButton_Unlock01_Click); // + // darkTextBox_4 + // + this.darkTextBox_4.Location = new System.Drawing.Point(85, 474); + this.darkTextBox_4.Name = "darkTextBox_4"; + this.darkTextBox_4.Size = new System.Drawing.Size(113, 20); + this.darkTextBox_4.TabIndex = 66; + this.darkTextBox_4.Visible = false; + // // darkButton_Unlock41 // this.darkButton_Unlock41.Checked = false; @@ -1601,6 +1652,14 @@ public class GForm_Main : DarkForm this.darkButton_Unlock41.Text = "UNLOCK ECU (0x27,0x41)"; this.darkButton_Unlock41.Click += new System.EventHandler(this.darkButton2_Click); // + // darkTextBox_3 + // + this.darkTextBox_3.Location = new System.Drawing.Point(85, 450); + this.darkTextBox_3.Name = "darkTextBox_3"; + this.darkTextBox_3.Size = new System.Drawing.Size(113, 20); + this.darkTextBox_3.TabIndex = 65; + this.darkTextBox_3.Visible = false; + // // darkButton1 // this.darkButton1.Checked = false; @@ -1622,22 +1681,33 @@ public class GForm_Main : DarkForm this.darkButton_6.Text = "Select ECU"; this.darkButton_6.Click += new System.EventHandler(this.method_20); // - // darkButton_5 + // darkButton_FlashRom // - this.darkButton_5.Checked = false; - this.darkButton_5.Enabled = false; - this.darkButton_5.Location = new System.Drawing.Point(6, 222); - this.darkButton_5.Name = "darkButton_5"; - this.darkButton_5.Size = new System.Drawing.Size(192, 23); - this.darkButton_5.TabIndex = 54; - this.darkButton_5.Text = "Flash Rom (.bin)"; - this.darkButton_5.Click += new System.EventHandler(this.method_17); + this.darkButton_FlashRom.Checked = false; + this.darkButton_FlashRom.Enabled = false; + this.darkButton_FlashRom.Location = new System.Drawing.Point(6, 222); + this.darkButton_FlashRom.Name = "darkButton_FlashRom"; + this.darkButton_FlashRom.Size = new System.Drawing.Size(192, 23); + this.darkButton_FlashRom.TabIndex = 54; + this.darkButton_FlashRom.Text = "Flash Rom (.bin)"; + this.darkButton_FlashRom.Click += new System.EventHandler(this.method_17); + // + // darkLabel_3 + // + this.darkLabel_3.AutoSize = true; + this.darkLabel_3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); + this.darkLabel_3.Location = new System.Drawing.Point(24, 476); + this.darkLabel_3.Name = "darkLabel_3"; + this.darkLabel_3.Size = new System.Drawing.Size(56, 13); + this.darkLabel_3.TabIndex = 60; + this.darkLabel_3.Text = "Read Size"; + this.darkLabel_3.Visible = false; // // darkButton_4 // this.darkButton_4.Checked = false; this.darkButton_4.Enabled = false; - this.darkButton_4.Location = new System.Drawing.Point(6, 338); + this.darkButton_4.Location = new System.Drawing.Point(6, 367); this.darkButton_4.Name = "darkButton_4"; this.darkButton_4.Size = new System.Drawing.Size(192, 23); this.darkButton_4.TabIndex = 51; @@ -1645,26 +1715,6 @@ public class GForm_Main : DarkForm this.darkButton_4.Visible = false; this.darkButton_4.Click += new System.EventHandler(this.method_16); // - // darkLabel_0 - // - this.darkLabel_0.AutoSize = true; - this.darkLabel_0.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); - this.darkLabel_0.Location = new System.Drawing.Point(228, 14); - this.darkLabel_0.Name = "darkLabel_0"; - this.darkLabel_0.Size = new System.Drawing.Size(62, 13); - this.darkLabel_0.TabIndex = 57; - this.darkLabel_0.Text = "Vin Number"; - // - // darkLabel_1 - // - this.darkLabel_1.AutoSize = true; - this.darkLabel_1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); - this.darkLabel_1.Location = new System.Drawing.Point(228, 40); - this.darkLabel_1.Name = "darkLabel_1"; - this.darkLabel_1.Size = new System.Drawing.Size(70, 13); - this.darkLabel_1.TabIndex = 58; - this.darkLabel_1.Text = "Calibration ID"; - // // darkLabel_2 // this.darkLabel_2.AutoSize = true; @@ -1676,16 +1726,25 @@ public class GForm_Main : DarkForm this.darkLabel_2.Text = "Read address"; this.darkLabel_2.Visible = false; // - // darkLabel_3 + // darkLabel_0 // - this.darkLabel_3.AutoSize = true; - this.darkLabel_3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); - this.darkLabel_3.Location = new System.Drawing.Point(24, 476); - this.darkLabel_3.Name = "darkLabel_3"; - this.darkLabel_3.Size = new System.Drawing.Size(56, 13); - this.darkLabel_3.TabIndex = 60; - this.darkLabel_3.Text = "Read Size"; - this.darkLabel_3.Visible = false; + this.darkLabel_0.AutoSize = true; + this.darkLabel_0.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); + this.darkLabel_0.Location = new System.Drawing.Point(218, 14); + this.darkLabel_0.Name = "darkLabel_0"; + this.darkLabel_0.Size = new System.Drawing.Size(62, 13); + this.darkLabel_0.TabIndex = 57; + this.darkLabel_0.Text = "Vin Number"; + // + // darkLabel_1 + // + this.darkLabel_1.AutoSize = true; + this.darkLabel_1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); + this.darkLabel_1.Location = new System.Drawing.Point(218, 40); + this.darkLabel_1.Name = "darkLabel_1"; + this.darkLabel_1.Size = new System.Drawing.Size(70, 13); + this.darkLabel_1.TabIndex = 58; + this.darkLabel_1.Text = "Calibration ID"; // // darkLabel_4 // @@ -1703,43 +1762,27 @@ public class GForm_Main : DarkForm this.darkLabel_5.AutoSize = true; this.darkLabel_5.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F); this.darkLabel_5.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); - this.darkLabel_5.Location = new System.Drawing.Point(214, 514); + this.darkLabel_5.Location = new System.Drawing.Point(12, 512); this.darkLabel_5.Name = "darkLabel_5"; this.darkLabel_5.Size = new System.Drawing.Size(0, 20); this.darkLabel_5.TabIndex = 51; // // darkTextBox_1 // - this.darkTextBox_1.Location = new System.Drawing.Point(304, 11); + this.darkTextBox_1.Location = new System.Drawing.Point(294, 11); this.darkTextBox_1.Name = "darkTextBox_1"; this.darkTextBox_1.ReadOnly = true; - this.darkTextBox_1.Size = new System.Drawing.Size(375, 20); + this.darkTextBox_1.Size = new System.Drawing.Size(385, 20); this.darkTextBox_1.TabIndex = 63; // // darkTextBox_2 // - this.darkTextBox_2.Location = new System.Drawing.Point(304, 37); + this.darkTextBox_2.Location = new System.Drawing.Point(294, 37); this.darkTextBox_2.Name = "darkTextBox_2"; this.darkTextBox_2.ReadOnly = true; - this.darkTextBox_2.Size = new System.Drawing.Size(375, 20); + this.darkTextBox_2.Size = new System.Drawing.Size(385, 20); this.darkTextBox_2.TabIndex = 64; // - // darkTextBox_3 - // - this.darkTextBox_3.Location = new System.Drawing.Point(85, 450); - this.darkTextBox_3.Name = "darkTextBox_3"; - this.darkTextBox_3.Size = new System.Drawing.Size(113, 20); - this.darkTextBox_3.TabIndex = 65; - this.darkTextBox_3.Visible = false; - // - // darkTextBox_4 - // - this.darkTextBox_4.Location = new System.Drawing.Point(85, 474); - this.darkTextBox_4.Name = "darkTextBox_4"; - this.darkTextBox_4.Size = new System.Drawing.Size(113, 20); - this.darkTextBox_4.TabIndex = 66; - this.darkTextBox_4.Visible = false; - // // darkProgressBar_0 // this.darkProgressBar_0.Location = new System.Drawing.Point(98, 537); @@ -1761,7 +1804,7 @@ public class GForm_Main : DarkForm // this.darkLabel_8.AutoSize = true; this.darkLabel_8.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); - this.darkLabel_8.Location = new System.Drawing.Point(220, 518); + this.darkLabel_8.Location = new System.Drawing.Point(228, 516); this.darkLabel_8.Name = "darkLabel_8"; this.darkLabel_8.Size = new System.Drawing.Size(0, 13); this.darkLabel_8.TabIndex = 69; @@ -1769,20 +1812,9 @@ public class GForm_Main : DarkForm // openFileDialog1 // this.openFileDialog1.DefaultExt = "*.gz"; - this.openFileDialog1.Filter = "Honda Compressed RWD Firmware|*.gz|Honda RWD Firmware|*.rwd"; + this.openFileDialog1.Filter = "Honda Compressed RWD Firmware|*.gz;*.rwd"; this.openFileDialog1.Title = "Open Honda RWD Firmware File"; // - // darkButton3 - // - this.darkButton3.Checked = false; - this.darkButton3.Enabled = false; - this.darkButton3.Location = new System.Drawing.Point(6, 251); - this.darkButton3.Name = "darkButton3"; - this.darkButton3.Size = new System.Drawing.Size(192, 23); - this.darkButton3.TabIndex = 60; - this.darkButton3.Text = "Flash Firmware (.rwd)"; - this.darkButton3.Click += new System.EventHandler(this.darkButton3_Click); - // // GForm_Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1803,6 +1835,7 @@ public class GForm_Main : DarkForm this.MinimumSize = new System.Drawing.Size(710, 573); this.Name = "GForm_Main"; this.Text = "Honda CANBUS Tools"; + this.Load += new System.EventHandler(this.GForm_Main_Load); this.darkGroupBox_0.ResumeLayout(false); this.darkGroupBox_0.PerformLayout(); this.ResumeLayout(false); @@ -1991,7 +2024,7 @@ public class GForm_Main : DarkForm - private DarkButton darkButton_5; + private DarkButton darkButton_FlashRom; private DarkButton darkButton_6; @@ -2122,7 +2155,26 @@ public class GForm_Main : DarkForm DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { - Class_RWD.LoadRWD(openFileDialog1.FileName, true); + Class_RWD.LoadRWD(openFileDialog1.FileName, true, true); } } + + private void GForm_Main_Load(object sender, EventArgs e) + { + + } + + private void darkButton3_Click_1(object sender, EventArgs e) + { + GForm_ConvertBIN gform = new GForm_ConvertBIN(); + if (gform.ShowDialog() == DialogResult.OK) + { + string ThisB = gform.FileBIN; + string ThisR = gform.FileRWD; + gform.Dispose(); + Class_RWD.LoadBIN(ThisB, ThisR); + return; + } + this.darkTextBox_0.Text = "Couldn't open file selection form"; + } } diff --git a/bin/Debug/FlashToolTest.exe b/bin/Debug/FlashToolTest.exe index 14c9706..4fbc492 100644 Binary files a/bin/Debug/FlashToolTest.exe and b/bin/Debug/FlashToolTest.exe differ diff --git a/bin/Debug/FlashToolTest.pdb b/bin/Debug/FlashToolTest.pdb index b42ecc2..6f8e5de 100644 Binary files a/bin/Debug/FlashToolTest.pdb and b/bin/Debug/FlashToolTest.pdb differ