From 83342ec28590965e04782c3aa7bc3c926de04046 Mon Sep 17 00:00:00 2001 From: Bouletmarc Date: Tue, 3 May 2022 12:25:40 -0400 Subject: [PATCH] V1.1.1 --- BootLoaderSumBytesList.txt | 272 ++++++++++++++++++++++++++++++ ClassEditor.cs | 284 +++++++++++++------------------ Class_DefinitionMaker.cs | 336 ++++++++++++++++++++++++++++++++++--- Class_RWD.cs | 5 +- Editortable.cs | 83 ++++++++- FlashToolTest.csproj | 3 + GForm_Main.cs | 14 +- 7 files changed, 789 insertions(+), 208 deletions(-) create mode 100644 BootLoaderSumBytesList.txt diff --git a/BootLoaderSumBytesList.txt b/BootLoaderSumBytesList.txt new file mode 100644 index 0000000..5d58320 --- /dev/null +++ b/BootLoaderSumBytesList.txt @@ -0,0 +1,272 @@ +37805-PCX-U020|142 +37805-PCX-U120|78 +37805-PZD-3090|172 +37805-PZD-4160|180 +37805-PZD-4170|106 +37805-PZD-A380|50 +37805-PZD-A480|232 +37805-PZX-A080|54 +37805-R40-A190|158 +37805-R40-A240|176 +37805-R40-A340|160 +37805-R40-A590|224 +37805-R40-A730|240 +37805-R40-A830|218 +37805-R40-K030|94 +37805-R40-K130|112 +37805-R40-K530|68 +37805-R40-K630|242 +37805-R40-U530|20 +37805-R41-L590|64 +37805-R41-L630|200 +37805-R41-L730|132 +37805-R42-A090|186 +37805-R42-A140|194 +37805-R42-A240|158 +37805-R42-A590|216 +37805-R42-A630|12 +37805-R42-A730|124 +37805-R43-L590|102 +37805-R43-L630|16 +37805-R43-L730|82 +37805-R44-X630|30 +37805-R46-X630|102 +37805-R49-U030|210 +37805-R60-M540|18 +37805-R60-M720|220 +37805-R60-U550|6 +37805-R8A-A560|0 +37805-R8A-A660|0 +37805-R8A-X540|0 +37805-RBJ-3090|2 +37805-RBJ-4050|112 +37805-RBJ-A430|122 +37805-RBJ-A560|252 +37805-RBJ-L440|178 +37805-RBJ-L560|78 +37805-RBJ-T520|164 +37805-RC0-M030|58 +37805-RC0-M530|30 +37805-RC0-M630|226 +37805-RC030|86 +37805-RC1-M030|112 +37805-RC1-M540|110 +37805-RC1-P120|16 +37805-RC1-P520|158 +37805-RC1-P720|64 +37805-RD1-X020|180 +37805-RD1-X520|234 +37805-RDA-A850|176 +37805-RDA-X750|208 +37805-RDB-A040|126 +37805-RDB-A120|102 +37805-RDB-A560|186 +37805-RDB-A630|36 +37805-REX-X540|46 +37805-REZ-A570|132 +37805-RGL-A020|8 +37805-RGL-A840|216 +37805-RGL-A930|214 +37805-RGL-K920|124 +37805-RGL-X830|210 +37805-RGL-X920|118 +37805-RGL-Y820|160 +37805-RGM-A840|214 +37805-RGW-A060|184 +37805-RGW-A960|112 +37805-RJE-A840|162 +37805-RJE-A960|0 +37805-RJE-K020|82 +37805-RJE-K720|0 +37805-RJE-X640|102 +37805-RJE-X730|0 +37805-RK8-N520|186 +37805-RK8-N740|116 +37805-RK8-N840|120 +37805-RKG-A560|222 +37805-RKG-A720|0 +37805-RKG-U520|52 +37805-RKG-X550|220 +37805-RKG-X720|0 +37805-RKG-Y520|78 +37805-RL5-A070|250 +37805-RL5-A120|228 +37805-RL5-A560|170 +37805-RL5-A710|14 +37805-RL5-X020|68 +37805-RL5-X520|214 +37805-RL8-A520|98 +37805-RL8-A730|0 +37805-RL8-X520|234 +37805-RL8-X730|0 +37805-RME-A180|92 +37805-RME-A220|72 +37805-RME-A520|70 +37805-RME-A690|194 +37805-RME-A720|70 +37805-RME-A890|194 +37805-RME-C220|140 +37805-RME-C410|16 +37805-RME-C520|96 +37805-RME-C720|134 +37805-RME-C890|2 +37805-RMX-3250|74 +37805-RMX-5070|154 +37805-RMX-5150|186 +37805-RMX-A060|54 +37805-RMX-A130|246 +37805-RMX-A630|158 +37805-RMX-X050|88 +37805-RMX-X550|98 +37805-RN0-3150|124 +37805-RN0-3160|254 +37805-RN0-A070|0 +37805-RN0-A570|248 +37805-RN0-A630|196 +37805-RN0-A770|116 +37805-RN0-A830|64 +37805-RN0-A970|0 +37805-RN0-C050|0 +37805-RN0-C950|0 +37805-RN0-K030|0 +37805-RN0-K130|0 +37805-RN0-M040|0 +37805-RN0-M830|0 +37805-RN0-M940|0 +37805-RN0-X030|0 +37805-RN0-X560|188 +37805-RN0-X620|132 +37805-RN0-X760|56 +37805-RN0-X820|0 +37805-RN0-X940|0 +37805-RN030|0 +37805-RNA-3260|168 +37805-RNA-3290|96 +37805-RNA-3450|12 +37805-RNA-3470|74 +37805-RNA-A150|230 +37805-RNA-A240|26 +37805-RNA-A340|164 +37805-RNA-A680|106 +37805-RNA-A740|176 +37805-RNA-A840|90 +37805-RNA-C130|226 +37805-RNA-C240|190 +37805-RNA-C340|68 +37805-RNA-C440|194 +37805-RNA-C640|154 +37805-RNA-C740|248 +37805-RNA-C840|126 +37805-RNA-C910|130 +37805-RNA-K080|212 +37805-RNA-K590|64 +37805-RNA-U720|50 +37805-RNA-U840|16 +37805-RNA-U950|36 +37805-RNA-Y030|122 +37805-RNA-Y330|92 +37805-RNA-Y530|70 +37805-RNA-Y720|212 +37805-RNA-Y830|164 +37805-RNB-X040|184 +37805-RNB-X120|134 +37805-RNB-X560|58 +37805-RNB-X620|10 +37805-RND-M030|212 +37805-RND-M530|118 +37805-RND-M620|40 +37805-RND-M720|124 +37805-RND-P030|78 +37805-RND-P540|232 +37805-RND-P740|154 +37805-RNE-A550|224 +37805-RNF-U050|232 +37805-RNF-U540|198 +37805-RNF-U730|42 +37805-RNT-U030|0 +37805-RNT-U520|138 +37805-RNV-B030|2 +37805-RNV-B530|214 +37805-RNV-B630|128 +37805-RNV-B730|208 +37805-RNV-M070|60 +37805-RNV-M560|176 +37805-RNV-M660|90 +37805-RNV-R020|168 +37805-RNV-R520|56 +37805-RNV-R620|2 +37805-RNV-R720|50 +37805-RNV-Z020|180 +37805-RNV-Z520|26 +37805-RNV-Z620|228 +37805-RNV-Z720|18 +37805-RNX-M020|52 +37805-RNX-M520|204 +37805-RNX-M620|132 +37805-RP3-3050|88 +37805-RP3-3060|80 +37805-RP3-3070|140 +37805-RP3-4050|136 +37805-RP3-A170|48 +37805-RP3-A770|98 +37805-RP6-A560|0 +37805-RP6-A640|0 +37805-RP6-A760|0 +37805-RP6-A840|0 +37805-RP6-X560|0 +37805-RP6-X640|0 +37805-RRA-C040|80 +37805-RRA-C540|6 +37805-RRB-3150|4 +37805-RRB-A090|118 +37805-RRB-A140|152 +37805-RRB-K020|162 +37805-RRB-X120|70 +37805-RRD-M220|184 +37805-RRD-P120|178 +37805-RRD20|110 +37805-RRH-U020|6 +37805-RRH-U520|32 +37805-RRH-U620|24 +37805-RTW-3050|76 +37805-RTW-A050|72 +37805-RTW-P020|242 +37805-RV0-3290|0 +37805-RV0-A580|0 +37805-RV0-A650|0 +37805-RV0-A780|0 +37805-RV0-X580|0 +37805-RV0-X640|0 +37805-RV0-X780|0 +37805-RV0-Y640|0 +37805-RV0-Y780|0 +37805-RWC-A570|208 +37805-RWC-A620|236 +37805-RWC-A720|12 +37805-RWC-X560|174 +37805-RWC-X620|28 +37805-RYE-A040|0 +37805-RYE-A140|0 +37805-RYE-A590|220 +37805-RYE-A630|168 +37805-RYE-A750|0 +37805-RYE-A850|0 +37805-RYE-X580|202 +37805-RYE-X620|146 +37805-RYE-X750|0 +37805-RYE-X830|0 +37805-RZA-A570|234 +37805-RZA-A770|198 +37805-RZA-K130|230 +37805-RZA-K230|220 +37805-RZA-K320|2 +37805-RZA-K520|26 +37805-RZA-K620|86 +37805-RZA-K720|60 +37805-RZA-K930|36 +37805-RZA-X630|52 +37805-RZA-X830|16 +37805-RZP-M020|168 +37805-RZP-M520|134 +37805-RZP-M720|104 +37805-RZP-M820|110 diff --git a/ClassEditor.cs b/ClassEditor.cs index 6c21e8d..3fc0ac5 100644 --- a/ClassEditor.cs +++ b/ClassEditor.cs @@ -40,7 +40,8 @@ internal class ClassEditor public List DefinitionsValueMax = new List(); public List DefinitionsChangeAmount = new List(); public List DefinitionsHeaders = new List(); - public List DefinitionsIsInverted = new List(); + public List DefinitionsIsXYInverted = new List(); + public List DefinitionsIsTableInverted = new List(); private Editortable Editortable_0; @@ -238,8 +239,6 @@ public void GetChanges() bool DiffDetected = false; foreach (int num4 in BytesBufferarray) { - //if ((!this.bool_3 || num3 < 200) && num4.ToString() != array[num3].ToString()) - //if (((Is1x20Table && (!this.IsSingleByteX || num3 < 200)) || (!Is1x20Table)) && num4.ToString() != array[num3].ToString()) if (num4.ToString() != array[num3].ToString()) { string BufText = "Change at line: " + num3.ToString() + "[" + array[num3].ToString("X2") + "->" + num4.ToString("X2") + "] | At: 0x" + (this.SelectedROMLocation + num3).ToString("X"); @@ -279,8 +278,6 @@ public void SaveROMBytes(string string_4) //Fix Checksums FixChecksums(); - //if (!this.Editortable_0.IsFullBinary) SavingBytes = this.Editortable_0.GForm_Main_0.VerifyChecksumFWBin(SavingBytes); - //if (this.Editortable_0.IsFullBinary) SavingBytes = this.Editortable_0.GForm_Main_0.VerifyChecksumFullBin(SavingBytes); File.Create(string_4).Dispose(); File.WriteAllBytes(string_4, SavingBytes); @@ -315,13 +312,11 @@ public void FixChecksums() } - public void SetTableValues(int[] TableSize, int ROMLocationX, string TopLeftString, string RowHeaderString, string[] HeaderStringList, string ThisMathX, string ThisFormatX, bool IsInverted, int ROMLocationTable, string ThisMathTable, string ThisTableFormat) + public void SetTableValues(int[] TableSize, int ROMLocationX, string TopLeftString, string RowHeaderString, string[] HeaderStringList, string ThisMathX, string ThisFormatX, bool IsXYInverted, int ROMLocationTable, string ThisMathTable, string ThisTableFormat, bool IsTableInverted) { try { this.SelectedTableSize = TableSize[0] * TableSize[1]; - this.SelectedROMLocation = ROMLocationX; - BufferMath = ThisMathX; BufferValuesArray = new int[SelectedTableSize]; BufferTableSize = TableSize; @@ -332,185 +327,152 @@ public void SetTableValues(int[] TableSize, int ROMLocationX, string TopLeftStri Editortable_0.dataGridView_0.AllowUserToAddRows = false; //Correct the Table Orientation if Bad - if ((TableSize[1] == 1 && IsInverted) || (TableSize[0] == 1 && !IsInverted)) + /*if ((TableSize[1] == 1 && IsInverted) || (TableSize[0] == 1 && !IsInverted)) { int Buf0 = TableSize[1]; int Buf1 = TableSize[0]; TableSize[0] = Buf0; TableSize[1] = Buf1; - } + }*/ - //Check if table size have more than 1x roms (or 1column if inverted) ... aka if it's a 3D table - bool IsMultiTable = true; - /*bool IsMultiTable = false; - if (TableSize[1] > 1 && !IsInverted) IsMultiTable = true; - if (TableSize[0] > 1 && IsInverted) IsMultiTable = true;*/ + SelectedROMLocation = ROMLocationTable; + BufferMath = ThisMathTable; - if (IsMultiTable) + //Apply Columns(Y) + if (IsXYInverted) { - SelectedROMLocation = ROMLocationTable; - BufferMath = ThisMathTable; - - //Apply Columns(Y) - if (IsInverted) + for (int i = 0; i < TableSize[1]; i++) { - for (int i = 0; i < TableSize[1]; i++) + if (ROMLocationX != 0) { - if (ROMLocationX != 0) - { - double num = 0; - if (IsSingleByteX) num = (double)this.GetSingleByteValue(ROMLocationX + i); - else num = (double)this.GetIntValue(ROMLocationX + i * 2); - - string HeaderStr = ""; - if (ThisFormatX != "") HeaderStr = DoMath(num, ThisMathX, false).ToString(ThisFormatX); - if (ThisFormatX == "") HeaderStr = DoMath(num, ThisMathX, false).ToString(); - Editortable_0.dataGridView_0.Columns.Add(HeaderStr, HeaderStr); - } - else - { - Editortable_0.dataGridView_0.Columns.Add(RowHeaderString, RowHeaderString); - } + double num = 0; + if (IsSingleByteX) num = (double)this.GetSingleByteValue(ROMLocationX + i); + else num = (double)this.GetIntValue(ROMLocationX + i * 2); + + string HeaderStr = ""; + if (ThisFormatX != "") HeaderStr = DoMath(num, ThisMathX, false).ToString(ThisFormatX); + if (ThisFormatX == "") HeaderStr = DoMath(num, ThisMathX, false).ToString(); + Editortable_0.dataGridView_0.Columns.Add(HeaderStr, HeaderStr); + } + else + { + Editortable_0.dataGridView_0.Columns.Add(RowHeaderString, RowHeaderString); } } - else - { - for (int j = 0; j < TableSize[0]; j++) Editortable_0.dataGridView_0.Columns.Add(HeaderStringList[j], HeaderStringList[j]); - } + } + else + { + for (int j = 0; j < TableSize[0]; j++) Editortable_0.dataGridView_0.Columns.Add(HeaderStringList[j], HeaderStringList[j]); + } - int index = 0; - while (true) + int index = 0; + while (true) + { + if (index >= SelectedTableSize) // More than TableSize (ex: 10x20.. more than 200) { - if (index >= SelectedTableSize) // More than TableSize (ex: 10x20.. more than 200) + int[,] numArray2 = smethod_35(BufferValuesArray, TableSize[0], TableSize[1]); + int rowIndex = 0; + while (true) { - int[,] numArray2 = smethod_35(BufferValuesArray, TableSize[0], TableSize[1]); - int rowIndex = 0; - while (true) + if ((rowIndex >= TableSize[1] && !IsXYInverted) || (rowIndex >= TableSize[0] && IsXYInverted)) //More than Y (make the 3D table) { - if ((rowIndex >= TableSize[1] && !IsInverted) || (rowIndex >= TableSize[0] && IsInverted)) //More than Y (make the 3D table) + int num10 = 0; + while (true) { - int num10 = 0; - while (true) + if ((num10 >= TableSize[1] && !IsXYInverted) || (num10 >= TableSize[0] && IsXYInverted)) //Another More than Y (set X Header) { - if ((num10 >= TableSize[1] && !IsInverted) || (num10 >= TableSize[0] && IsInverted)) //Another More than Y (set X Header) - { - if (!IsInverted) SetBackColor(TableSize[0], Editortable.float_1[0], Editortable.float_1[1]); - if (IsInverted) SetBackColor(TableSize[1], Editortable.float_1[0], Editortable.float_1[1]); - break; - } - //Rows(X) Math - if (IsInverted) + if (!IsXYInverted) SetBackColor(TableSize[0], Editortable.float_1[0], Editortable.float_1[1]); + if (IsXYInverted) SetBackColor(TableSize[1], Editortable.float_1[0], Editortable.float_1[1]); + break; + } + //Rows(X) Math + if (IsXYInverted) + { + string ThisHeaderVal = HeaderStringList[num10]; + if (ThisHeaderVal == "") ThisHeaderVal = RowHeaderString; + Editortable_0.dataGridView_0.Rows[num10].HeaderCell.Value = ThisHeaderVal; + } + else + { + if (ROMLocationX != 0) { - string ThisHeaderVal = HeaderStringList[num10]; - if (ThisHeaderVal == "") ThisHeaderVal = RowHeaderString; - Editortable_0.dataGridView_0.Rows[num10].HeaderCell.Value = ThisHeaderVal; + double num = 0; + if (IsSingleByteX) num = (double)this.GetSingleByteValue(ROMLocationX + num10); + else num = (double)this.GetIntValue(ROMLocationX + num10 * 2); + if (ThisFormatX != "") Editortable_0.dataGridView_0.Rows[num10].HeaderCell.Value = DoMath(num, ThisMathX, false).ToString(ThisFormatX); + if (ThisFormatX == "") Editortable_0.dataGridView_0.Rows[num10].HeaderCell.Value = DoMath(num, ThisMathX, false).ToString(); } else { - if (ROMLocationX != 0) - { - double num = 0; - if (IsSingleByteX) num = (double)this.GetSingleByteValue(ROMLocationX + num10); - else num = (double)this.GetIntValue(ROMLocationX + num10 * 2); - if (ThisFormatX != "") Editortable_0.dataGridView_0.Rows[num10].HeaderCell.Value = DoMath(num, ThisMathX, false).ToString(ThisFormatX); - if (ThisFormatX == "") Editortable_0.dataGridView_0.Rows[num10].HeaderCell.Value = DoMath(num, ThisMathX, false).ToString(); - } - else - { - Editortable_0.dataGridView_0.Rows[num10].HeaderCell.Value = RowHeaderString; - } + Editortable_0.dataGridView_0.Rows[num10].HeaderCell.Value = RowHeaderString; } - num10++; } - break; + num10++; } + break; + } - //TableMath (Get full 1full row of value at a time) - object[] values = new object[0]; - if (IsInverted) + //TableMath (Get full 1full row of value at a time) + object[] values = new object[0]; + if (IsXYInverted) + { + values = new object[TableSize[1]]; + for (int i = 0; i < TableSize[1]; i++) { - values = new object[TableSize[1]]; - for (int i = 0; i < TableSize[1]; i++) - { - if (ThisTableFormat != "") values[i] = DoMath((double)numArray2[rowIndex, i], ThisMathTable, false).ToString(ThisTableFormat); - if (ThisTableFormat == "") values[i] = DoMath((double)numArray2[rowIndex, i], ThisMathTable, false).ToString(); - } + if (ThisTableFormat != "") values[i] = DoMath((double)numArray2[rowIndex, i], ThisMathTable, false).ToString(ThisTableFormat); + if (ThisTableFormat == "") values[i] = DoMath((double)numArray2[rowIndex, i], ThisMathTable, false).ToString(); } - else + } + else + { + values = new object[TableSize[0]]; + for (int i = 0; i < TableSize[0]; i++) { - values = new object[TableSize[0]]; - for (int i = 0; i < TableSize[0]; i++) - { - if (ThisTableFormat != "") values[i] = DoMath((double)numArray2[i, rowIndex], ThisMathTable, false).ToString(ThisTableFormat); - if (ThisTableFormat == "") values[i] = DoMath((double)numArray2[i, rowIndex], ThisMathTable, false).ToString(); - } + if (ThisTableFormat != "") values[i] = DoMath((double)numArray2[i, rowIndex], ThisMathTable, false).ToString(ThisTableFormat); + if (ThisTableFormat == "") values[i] = DoMath((double)numArray2[i, rowIndex], ThisMathTable, false).ToString(); } - Editortable_0.dataGridView_0.Rows.Insert(rowIndex, values); - rowIndex++; } - break; + Editortable_0.dataGridView_0.Rows.Insert(rowIndex, values); + rowIndex++; } - - //Math perfomed just above - if (IsSingleByteTable) BufferValuesArray[index] = GetSingleByteValue(SelectedROMLocation + index); - else BufferValuesArray[index] = GetIntValue(SelectedROMLocation + (index * 2)); - - index++; + break; } - } - //############################################## - /*else - { - //Normal 'single' table - if (IsInverted) - { - for (int i = 0; i < TableSize[0]; i++) Editortable_0.dataGridView_0.Columns.Add(RowHeaderString, RowHeaderString); - for (int i = 0; i < TableSize[1]; i++) - { - double num = 0; - if (IsSingleByteX) num = (double)this.GetSingleByteValue(ROMLocationX + i); - else num = (double)this.GetIntValue(ROMLocationX + i * 2); + //Math perfomed just above + if (IsSingleByteTable) BufferValuesArray[index] = GetSingleByteValue(SelectedROMLocation + index); + else BufferValuesArray[index] = GetIntValue(SelectedROMLocation + (index * 2)); - BufferValuesArray[i] = (int) num; - - double FinalValue = DoMath(num, ThisMathX, false); + index++; + } - if (ThisFormatX == "") Editortable_0.dataGridView_0.Rows.Add(new object[] { FinalValue.ToString() }); - if (ThisFormatX != "") Editortable_0.dataGridView_0.Rows.Add(new object[] { FinalValue.ToString(ThisFormatX) }); + //############################################################################################################## + //Invert inner tables values X and Y + if (IsTableInverted) + { + int[,] numArray2 = smethod_35(BufferValuesArray, TableSize[1], TableSize[0]); - Editortable_0.dataGridView_0.Rows[i].HeaderCell.Value = HeaderStringList[i]; - } - } - if (!IsInverted) + for (int i = 0; i < Editortable_0.dataGridView_0.ColumnCount; i++) { - for (int j = 0; j < TableSize[0]; j++) Editortable_0.dataGridView_0.Columns.Add(HeaderStringList[j], HeaderStringList[j]); - List list = new List(); - - //################################################################################################################ - for (int k = 0; k < TableSize[0]; k++) + for (int i2 = 0; i2 < Editortable_0.dataGridView_0.RowCount; i2++) { - double num = 0; - if (IsSingleByteX) num = (double)this.GetSingleByteValue(ROMLocationX + k); - else num = (double)this.GetIntValue(ROMLocationX + k * 2); - BufferValuesArray[k] = (int) num; - - //Console.WriteLine("num: " + num); - - if (ThisFormatX == "") list.Add(DoMath(num, ThisMathX, false).ToString()); - if (ThisFormatX != "") list.Add(DoMath(num, ThisMathX, false).ToString(ThisFormatX)); - } - //################################################################################################################ + string valueinner = ""; + if (IsXYInverted) + { + if (ThisTableFormat != "") valueinner = DoMath((double)numArray2[i, i2], ThisMathTable, false).ToString(ThisTableFormat); + if (ThisTableFormat == "") valueinner = DoMath((double)numArray2[i, i2], ThisMathTable, false).ToString(); + } + else + { + if (ThisTableFormat != "") valueinner = DoMath((double)numArray2[i2, i], ThisMathTable, false).ToString(ThisTableFormat); + if (ThisTableFormat == "") valueinner = DoMath((double)numArray2[i2, i], ThisMathTable, false).ToString(); + } - Editortable_0.dataGridView_0.Rows.Add(); - for (int num6 = 0; num6 < TableSize[0]; num6++) - { - DataGridViewRow dataGridViewRow = Editortable_0.dataGridView_0.Rows[0]; - dataGridViewRow.Cells[num6].Value = list[num6]; + Editortable_0.dataGridView_0.Rows[i2].Cells[i].Value = valueinner; } - Editortable_0.dataGridView_0.Rows[0].HeaderCell.Value = RowHeaderString; } - }*/ + } + //############################################################################################################## + foreach (object obj in Editortable_0.dataGridView_0.Columns) { DataGridViewColumn dataGridViewColumn = (DataGridViewColumn)obj; @@ -632,7 +594,8 @@ public double DoMath(double ThisValueCheck, string ThisMath, bool Reverse) { double ReversedVal = DoMathFinal(ReturnVal, ThisMath, true); if (((int) ReversedVal).ToString() != ((int) ThisValueCheck).ToString() - && ((int)ReversedVal + 1).ToString() != ((int)ThisValueCheck).ToString()) + && ((int)ReversedVal + 1).ToString() != ((int)ThisValueCheck).ToString() + && ((int)ReversedVal - 1).ToString() != ((int)ThisValueCheck).ToString()) { Editortable_0.GForm_Main_0.method_1("Problem with math: " + ThisMath + " | Values: " + ((int)ThisValueCheck).ToString() + " != " + ((int)ReversedVal).ToString()); } @@ -661,17 +624,10 @@ public double DoMathFinal(double ThisValue, string ThisMath, bool Reverse) ThisMath = ThisMath.Replace(XandMath, "") + XandMath[1].ToString() + XandMath[0].ToString(); } } - //Console.WriteLine("Math: " + ThisMath + " (" + Reverse + ")"); ThisMath = ThisMath.Replace("X", ThisValue.ToString()); - //Console.WriteLine("Math func: " + ThisMath + " (" + Reverse + ")"); - - //128.0/X*14.7 --> 128/ (X/14.7) (real order: X/14.7*128 - //32767/X --> 32767/X - //X/50 --> X*50 if (Reverse) ThisMath = InvertMathString(ThisMath); - //Console.WriteLine("Math func: " + ThisMath + " (" + Reverse + ")"); bool WeHaveVal1 = false; double Val1 = 0; @@ -682,8 +638,6 @@ public double DoMathFinal(double ThisValue, string ThisMath, bool Reverse) ThisMath = ThisMath.Substring(GetNearestMathIndex(ThisMath) + 1); double Val2 = GetNextValue(ThisMath); - //Console.WriteLine("Math: " + Val1 + MathChar.ToString() + Val2 + " (" + Reverse + ")"); - if (MathChar == '*') ReturnVal = Val1 * Val2; if (MathChar == '/') ReturnVal = Val1 / Val2; if (MathChar == '+') ReturnVal = Val1 + Val2; @@ -694,9 +648,6 @@ public double DoMathFinal(double ThisValue, string ThisMath, bool Reverse) int NearestIndex = GetNearestMathIndex(ThisMath); if (NearestIndex != -1) ThisMath = ThisMath.Substring(GetNearestMathIndex(ThisMath)); - //Console.WriteLine("Math remain: " + ThisMath + " (" + Reverse + ")"); - //Console.WriteLine("New/End Val1: " + ReturnVal + " (" + Reverse + ")"); - WeHaveVal1 = true; Val1 = ReturnVal; @@ -1016,7 +967,8 @@ public void LoadThisECUDefinitions(string ThisECU) DefinitionsFormatX = new List(); DefinitionsHeaders = new List(); DefinitionsFormatY = new List(); - DefinitionsIsInverted = new List(); + DefinitionsIsXYInverted = new List(); + DefinitionsIsTableInverted = new List(); Editortable_0.GForm_Main_0.method_1("Loading ECU definitions for: " + ThisECU); bool ECUFound = false; @@ -1045,13 +997,16 @@ public void LoadThisECUDefinitions(string ThisECU) string CurrentFormatY = ""; string CurrentFormatTable = ""; string CurrentHeaders = ""; - bool CurrentIsInverted = false; + bool CurrentIsXYInverted = false; + bool CurrentIsTableInverted = false; for (int i = 0; i < AllLines.Length; i++) { string Thisline = AllLines[i]; if (Thisline.Contains("ROM Parameters")) GettingEcuList = false; //make sure we are not reading false contents + if (Thisline.Contains("THIS FILE AS BEEN GENERATED")) DarkMessageBox.Show("This Definitions file as been generated to get the ROM Locations.\nThe ROM Locations can possibly be wrong and\nthe tables can display corrupted values!"); + //Get supported ecu list from file and check if it's match if (Thisline[0] != '#' && Thisline != "") { @@ -1088,7 +1043,8 @@ public void LoadThisECUDefinitions(string ThisECU) if (Commands[0] == "FormatY") CurrentFormatY = Commands[1]; if (Commands[0] == "FormatTable") CurrentFormatTable = Commands[1]; if (Commands[0] == "Headers") CurrentHeaders = Commands[1]; - if (Commands[0] == "IsInverted") CurrentIsInverted = bool.Parse(Commands[1].ToLower()); + if (Commands[0] == "IsXYInverted") CurrentIsXYInverted = bool.Parse(Commands[1].ToLower()); + if (Commands[0] == "IsTableInverted") CurrentIsTableInverted = bool.Parse(Commands[1].ToLower()); } } @@ -1119,7 +1075,8 @@ public void LoadThisECUDefinitions(string ThisECU) DefinitionsFormatY.Add(CurrentFormatY); DefinitionsFormatTable.Add(CurrentFormatTable); DefinitionsHeaders.Add(CurrentHeaders); - DefinitionsIsInverted.Add(CurrentIsInverted); + DefinitionsIsXYInverted.Add(CurrentIsXYInverted); + DefinitionsIsTableInverted.Add(CurrentIsTableInverted); //Reset values to default CurrentLocationX = ""; @@ -1142,7 +1099,8 @@ public void LoadThisECUDefinitions(string ThisECU) CurrentHeaders = ""; CurrentFormatY = ""; CurrentFormatTable = ""; - CurrentIsInverted = false; + CurrentIsXYInverted = false; + CurrentIsTableInverted = false; } } } diff --git a/Class_DefinitionMaker.cs b/Class_DefinitionMaker.cs index 95fa0e1..3b947c6 100644 --- a/Class_DefinitionMaker.cs +++ b/Class_DefinitionMaker.cs @@ -12,6 +12,16 @@ class Class_DefinitionMaker List AllFoundFunctions = new List(); List AllFoundAddress = new List(); + + List AllFileNames = new List(); + List AllBootLoaderSumBytes = new List(); + + //########################################################################################################################## + //########################################################################################################################## + //########################################################################################################################## + //########################################################################################################################## + //########################################################################################################################## + public void CreateDefinitionsFiles() { //########################################################################################################################## @@ -30,28 +40,133 @@ public void CreateDefinitionsFiles() for (int i = 0; i < AllBytes.Length; i++) BufferBytes[0x8000 + i] = AllBytes[i]; AllBytes = BufferBytes; - int ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("00 0A 00 0A 00 C8 00"), 16); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "VTEC Engagement", ThisAddr); - - ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("FA 01 2C FF FF 40"), 71); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Revlimiter", ThisAddr); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 1", ThisAddr + 8); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 2", ThisAddr + 16); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 3", ThisAddr + 24); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 4", ThisAddr + 32); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 5", ThisAddr + 36); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 6", ThisAddr + 52); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 7", ThisAddr + 60); - - ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("00 32 00 1E 01 2C 00 00 08 66 66 00 00"), -2); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Speedlimiter", ThisAddr); - - ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("0C 80 0F A0 12 C0 19 00"), 8); - if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Injector Voltage Compensation", ThisAddr); + bool DoneParameter = false; - //ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("00 1E 00 00 00 03 00 05 00 C8"), -8); - ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("00 1E 00 00 00 03 00 05 00"), -8); + //####################################################################################################################### + //####################################################################################################################### + DoneParameter = false; + int ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("00 0A 00 0A 00 C8 00"), 16, false); + if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "VTEC Engagement", ThisAddr); + //####################################################################################################################### + //####################################################################################################################### + DoneParameter = false; + ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("FA 01 2C FF FF 40"), 71, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Revlimiter", ThisAddr); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 1", ThisAddr + 8); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 2", ThisAddr + 16); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 3", ThisAddr + 24); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 4", ThisAddr + 32); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 5", ThisAddr + 36); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 6", ThisAddr + 52); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 7", ThisAddr + 60); + DoneParameter = true; + } + if (ThisAddr == -1 && !DoneParameter) ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("FA 01 2C FF FF 3A"), 71, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Revlimiter", ThisAddr); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 1", ThisAddr + 8); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 2", ThisAddr + 16); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 3", ThisAddr + 24); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 4", ThisAddr + 32); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 5", ThisAddr + 36); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 6", ThisAddr + 52); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 7", ThisAddr + 60); + DoneParameter = true; + } + if (ThisAddr == -1 && !DoneParameter) ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("00 00 00 00 80 00 80 00 00 00 00 00 00"), 84, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Revlimiter", ThisAddr); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 1", ThisAddr + 8); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 2", ThisAddr + 16); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 3", ThisAddr + 24); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 4", ThisAddr + 32); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 5", ThisAddr + 36); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 6", ThisAddr + 52); + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "--Revlimiter 7", ThisAddr + 60); + DoneParameter = true; + } + //####################################################################################################################### + //####################################################################################################################### + DoneParameter = false; + ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("00 32 00 1E 01 2C 00 00 08 66 66 00 00"), -2, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Speedlimiter", ThisAddr); + DoneParameter = true; + } + if (ThisAddr == -1 && !DoneParameter) ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("00 32 00 1E 02 BC 02 DC 01 2C"), -2, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Speedlimiter", ThisAddr); + DoneParameter = true; + } + if (ThisAddr == -1 && !DoneParameter) ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("01 90 00 14 01 2C 00 00 08 66 66 00 00"), -2, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Speedlimiter", ThisAddr); + DoneParameter = true; + } + if (ThisAddr == -1 && !DoneParameter) ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("01 2C 00 00 08 66 66 00 00"), -6, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Speedlimiter", ThisAddr); + DoneParameter = true; + } + //####################################################################################################################### + //####################################################################################################################### + DoneParameter = false; + ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("0C 80 0F A0 12 C0 19 00"), 8, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Injector Voltage Compensation", ThisAddr); + DoneParameter = true; + } + if (ThisAddr == -1 && !DoneParameter) ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("FC 18 FF 38 80 00 80 00"), -92, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Injector Voltage Compensation", ThisAddr); + DoneParameter = true; + } + //####################################################################################################################### + //####################################################################################################################### + //MISSING ON SOME ROMS, HAVE TO CHECK FOR OTHERS BYTES ARRAY + DoneParameter = false; + ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("00 1E 00 00 00 03 00 05 00"), -8, false); if (ThisAddr != -1) AddToList(Path.GetFileNameWithoutExtension(ThisFile), "MAF Load Limit", ThisAddr); + //####################################################################################################################### + //####################################################################################################################### + DoneParameter = false; + ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("7F FF F0 60 EF 98"), 181, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Minimum IPW", ThisAddr); + DoneParameter = true; + } + if (ThisAddr == -1 && !DoneParameter) ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("05 66 05 66 02 00 00 00 00 01"), 36, true); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Minimum IPW", ThisAddr); + DoneParameter = true; + } + //####################################################################################################################### + //####################################################################################################################### + DoneParameter = false; + ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("00 00 00 00 00 00 00 01 00 1E"), 16, false); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Idle Speed", ThisAddr); + DoneParameter = true; + } + if (ThisAddr == -1 && !DoneParameter) ThisAddr = CheckForBytesAndGetAddress(AllBytes, StringToByteArray("C8 01 90 03 20 61 A8 00"), -75, true); + if (ThisAddr != -1 && !DoneParameter) + { + AddToList(Path.GetFileNameWithoutExtension(ThisFile), "Idle Speed", ThisAddr); + DoneParameter = true; + } } GenerateDefinitions(); @@ -138,6 +253,35 @@ private void GenerateDefinitions() AllStringFile = AllStringFile + "ChangeAmount:50" + Environment.NewLine; AllStringFile = AllStringFile + "#############################" + Environment.NewLine; } + + if (FoundFunc == "Minimum IPW") + { + AllStringFile = AllStringFile + "ROMLocationTable:0x" + FoundAddr.ToString("X") + Environment.NewLine; + AllStringFile = AllStringFile + "Name:" + FoundFunc + Environment.NewLine; + AllStringFile = AllStringFile + "Unit1:Min IPW" + Environment.NewLine; + AllStringFile = AllStringFile + "TableSize:1x1" + Environment.NewLine; + AllStringFile = AllStringFile + "ValueMin:-6" + Environment.NewLine; + AllStringFile = AllStringFile + "ValueMax:5" + Environment.NewLine; + AllStringFile = AllStringFile + "ChangeAmount:0.001" + Environment.NewLine; + AllStringFile = AllStringFile + "MathTable:X*0.002" + Environment.NewLine; + AllStringFile = AllStringFile + "FormatTable:0.000" + Environment.NewLine; + AllStringFile = AllStringFile + "#############################" + Environment.NewLine; + } + + if (FoundFunc == "Idle Speed") + { + AllStringFile = AllStringFile + "ROMLocationTable:0x" + FoundAddr.ToString("X") + Environment.NewLine; + //AllStringFile = AllStringFile + "ROMLocationY:0x" + FoundAddr.ToString("X") + Environment.NewLine; + AllStringFile = AllStringFile + "Name:" + FoundFunc + Environment.NewLine; + AllStringFile = AllStringFile + "Unit1:Coolant Temp" + Environment.NewLine; + AllStringFile = AllStringFile + "Unit2:RPM" + Environment.NewLine; + AllStringFile = AllStringFile + "TableSize:8x1" + Environment.NewLine; + AllStringFile = AllStringFile + "ValueMin:-1000" + Environment.NewLine; + AllStringFile = AllStringFile + "ValueMax:4000" + Environment.NewLine; + AllStringFile = AllStringFile + "ChangeAmount:50" + Environment.NewLine; + //AllStringFile = AllStringFile + "MathY:X/10" + Environment.NewLine; + AllStringFile = AllStringFile + "#############################" + Environment.NewLine; + } } CreateFile(AllStringFile, BufECUName); @@ -189,26 +333,166 @@ public byte[] StringToByteArray(string hex) .ToArray(); } - private int CheckForBytesAndGetAddress(byte[] ThisFileBytes, byte[] CheckThisBytes, int AddressOffset) + private int CheckForBytesAndGetAddress(byte[] ThisFileBytes, byte[] CheckThisBytes, int AddressOffset, bool GetLastInstance) { + bool FoundSameBytes = true; + int LastIndexFound = -1; for (int i=0; i < ThisFileBytes.Length; i++) { - bool FoundSameBytes = true; + FoundSameBytes = true; for (int i2 = 0; i2 < CheckThisBytes.Length; i2++) { - if (ThisFileBytes[i + i2] != CheckThisBytes[i2]) + try { - FoundSameBytes = false; + if (ThisFileBytes[i + i2] != CheckThisBytes[i2]) + { + FoundSameBytes = false; + i2 = CheckThisBytes.Length; + } + } + catch + { + //Generally at end of file if causing issue i2 = CheckThisBytes.Length; } } - if (FoundSameBytes) + if (FoundSameBytes && !GetLastInstance) { return i + AddressOffset; } + else + { + LastIndexFound = i + AddressOffset; + } } - return -1; + return LastIndexFound; + } + + //########################################################################################################################## + //########################################################################################################################## + //########################################################################################################################## + //########################################################################################################################## + //########################################################################################################################## + + public void GetFilesDifferenceCount() + { + //########################################################################################################################## + //string FirmwareFolder = Application.StartupPath + @"\Firmwares"; + string FirmwareFolder = @"C:\Users\boule\Documents\Visual Studio 2019\Projects\RWD_2_BIN\bin\Debug\Firmwares"; + //########################################################################################################################## + + string[] AllFiles = Directory.GetFiles(FirmwareFolder, "*.bin"); + string SavingText = "#######################################################################" + Environment.NewLine; + SavingText = SavingText + "# SHOWING THE AMOUNT OF BYTES DIFFERENCES BETWEEN 2 ECU FILE" + Environment.NewLine; + SavingText = SavingText + "# IF THERE WERE MORE THAN 500 DIFFERENCES, THE 2 FILES ARE NOT LISTED" + Environment.NewLine; + SavingText = SavingText + "#######################################################################" + Environment.NewLine; + + + List AllFileDiffChecked = new List(); + + foreach (string ThisFile in AllFiles) + { + byte[] AllBytes = File.ReadAllBytes(ThisFile); + + foreach (string ThisFile2 in AllFiles) + { + if (ThisFile2 != ThisFile) + { + bool CheckedThose2Files = false; + string CheckString = ThisFile2 + "|" + ThisFile; + for (int i = 0; i < AllFileDiffChecked.Count; i++) + { + if (AllFileDiffChecked[i] == CheckString) CheckedThose2Files = true; + } + + if (!CheckedThose2Files) + { + int ByteDiffCount = 0; + byte[] AllBytes2 = File.ReadAllBytes(ThisFile2); + for (int i = 0; i < AllBytes2.Length; i++) + { + if (AllBytes2[i] != AllBytes[i]) ByteDiffCount++; + + if (ByteDiffCount >= 500) i = AllBytes2.Length; + } + + if (ByteDiffCount < 500) + { + Console.WriteLine(Path.GetFileNameWithoutExtension(ThisFile) + " && " + Path.GetFileNameWithoutExtension(ThisFile2) + " > " + ByteDiffCount); + SavingText = SavingText + Path.GetFileNameWithoutExtension(ThisFile) + " && " + Path.GetFileNameWithoutExtension(ThisFile2) + " > " + ByteDiffCount + Environment.NewLine; + } + + AllFileDiffChecked.Add(ThisFile2 + "|" + ThisFile); + AllFileDiffChecked.Add(ThisFile + "|" + ThisFile2); + } + + Application.DoEvents(); + } + } + } + + + string SavingPath = Application.StartupPath + @"\DifferencesCountInECUFiles.txt"; + File.Create(SavingPath).Dispose(); + File.WriteAllText(SavingPath, SavingText); + } + + //########################################################################################################################## + //########################################################################################################################## + //########################################################################################################################## + //########################################################################################################################## + //########################################################################################################################## + + public void ExtractAllBootLoaderSum_1Mb() + { + //########################################################################################################################## + //string FirmwareFolder = Application.StartupPath + @"\Firmwares"; + string FirmwareFolder = @"C:\Users\boule\Documents\Visual Studio 2019\Projects\RWD_2_BIN\bin\Debug\Firmwares"; + //########################################################################################################################## + + AllFileNames = new List(); + AllBootLoaderSumBytes = new List(); + + string[] AllFiles = Directory.GetFiles(FirmwareFolder, "*.bin"); + foreach (string ThisFile in AllFiles) + { + byte[] AllBytes = File.ReadAllBytes(ThisFile); + byte BootLoaderSumByte = GetBootloaderSum(AllBytes); + + AllFileNames.Add(Path.GetFileNameWithoutExtension(ThisFile)); + AllBootLoaderSumBytes.Add(BootLoaderSumByte); + } + + string SavingText = ""; + for (int i = 0; i < AllFileNames.Count; i++) SavingText = SavingText + AllFileNames[i] + "|" + AllBootLoaderSumBytes[i] + Environment.NewLine; + + string SavingPath = Application.StartupPath + @"\BootLoaderSumBytesList.txt"; + File.Create(SavingPath).Dispose(); + File.WriteAllText(SavingPath, SavingText); + } + + public byte GetBootloaderSum(byte[] FWFileBytes) + { + //############################### + //Get Checksum (sum) + byte[] BufferBytes = FWFileBytes; + byte num = BufferBytes[0x400]; + byte num2 = GetNegativeChecksumFWBin(BufferBytes); + byte BTSum = num; + BTSum += num2; + return BTSum; + } + + + public byte GetNegativeChecksumFWBin(byte[] byte_1) + { + byte b = 0; + for (int i = 0; i < byte_1.Length; i++) + { + if (i != 0x400) b -= byte_1[i]; + } + return b; } } diff --git a/Class_RWD.cs b/Class_RWD.cs index 6871850..277c9a1 100644 --- a/Class_RWD.cs +++ b/Class_RWD.cs @@ -437,10 +437,7 @@ public static byte GetNegativeChecksumFWBin(byte[] byte_1) byte b = 0; for (int i = 0; i < byte_1.Length; i++) { - if (i != 0x400) - { - b -= byte_1[i]; - } + if (i != 0x400) b -= byte_1[i]; } return b; } diff --git a/Editortable.cs b/Editortable.cs index 848a164..db903f5 100644 --- a/Editortable.cs +++ b/Editortable.cs @@ -625,7 +625,7 @@ private void treeView1_AfterSelect(object sender, EventArgs e) //Set Y Headers (normal header mode) int DoingThisSize = TableSizze[0]; - if (ClassEditor_0.DefinitionsIsInverted[NodeIndex]) DoingThisSize = TableSizze[1]; + if (ClassEditor_0.DefinitionsIsXYInverted[NodeIndex]) DoingThisSize = TableSizze[1]; string[] textArray1 = new string[DoingThisSize]; if (ClassEditor_0.DefinitionsHeaders[NodeIndex] != "" && ClassEditor_0.DefinitionsHeaders[NodeIndex].Contains(",")) @@ -650,13 +650,70 @@ private void treeView1_AfterSelect(object sender, EventArgs e) } //Show Value in Datagridview - ClassEditor_0.SetTableValues(TableSizze, ParamLocation, ClassEditor_0.DefinitionsUnit1[NodeIndex], ClassEditor_0.DefinitionsUnit2[NodeIndex], textArray1, ClassEditor_0.DefinitionsMathX[NodeIndex], ClassEditor_0.DefinitionsFormatX[NodeIndex], ClassEditor_0.DefinitionsIsInverted[NodeIndex], ClassEditor_0.HexStringToInt(ClassEditor_0.DefinitionsLocationsTable[NodeIndex]), ClassEditor_0.DefinitionsMathTable[NodeIndex], ClassEditor_0.DefinitionsFormatTable[NodeIndex]); + ClassEditor_0.SetTableValues(TableSizze, ParamLocation, ClassEditor_0.DefinitionsUnit1[NodeIndex], ClassEditor_0.DefinitionsUnit2[NodeIndex], textArray1, ClassEditor_0.DefinitionsMathX[NodeIndex], ClassEditor_0.DefinitionsFormatX[NodeIndex], ClassEditor_0.DefinitionsIsXYInverted[NodeIndex], ClassEditor_0.HexStringToInt(ClassEditor_0.DefinitionsLocationsTable[NodeIndex]), ClassEditor_0.DefinitionsMathTable[NodeIndex], ClassEditor_0.DefinitionsFormatTable[NodeIndex], ClassEditor_0.DefinitionsIsTableInverted[NodeIndex]); } } ClassEditor_0.bool_1 = true; } + private int CheckForBootLoaderSum(string ThisECUName) + { + string BLSumPath = Application.StartupPath + @"\BootLoaderSumBytesList.txt"; + if (File.Exists(BLSumPath)) + { + string[] AllLines = File.ReadAllLines(BLSumPath); + + for (int i = 0; i < AllLines.Length; i++) + { + if (AllLines[i].Contains("|")) + { + string[] SplittedCommands = AllLines[i].Split('|'); + + if (SplittedCommands[0] == ThisECUName) + { + return int.Parse(SplittedCommands[1]); + } + } + } + } + + return -1; + } + + public string ExtractECUNameFromThisFile(byte[] ThisFileBytes) + { + string ECUName = ""; + for (int i = 0; i < ThisFileBytes.Length; i++) + { + //37805- + if ((char) ThisFileBytes[i] == '3' + && (char)ThisFileBytes[i + 1] == '7' + && (char)ThisFileBytes[i + 2] == '8' + && (char)ThisFileBytes[i + 3] == '0' + && (char)ThisFileBytes[i + 4] == '5' + && (char)ThisFileBytes[i + 5] == '-') + { + ECUName = ECUName + ((char)ThisFileBytes[i]).ToString(); //3 + ECUName = ECUName + ((char)ThisFileBytes[i + 1]).ToString(); //7 + ECUName = ECUName + ((char)ThisFileBytes[i + 2]).ToString(); //8 + ECUName = ECUName + ((char)ThisFileBytes[i + 3]).ToString(); //0 + ECUName = ECUName + ((char)ThisFileBytes[i + 4]).ToString(); //5 + ECUName = ECUName + ((char)ThisFileBytes[i + 5]).ToString(); //- + ECUName = ECUName + ((char)ThisFileBytes[i + 6]).ToString(); //X + ECUName = ECUName + ((char)ThisFileBytes[i + 7]).ToString(); //X + ECUName = ECUName + ((char)ThisFileBytes[i + 8]).ToString(); //X + ECUName = ECUName + ((char)ThisFileBytes[i + 9]).ToString(); //- + ECUName = ECUName + ((char)ThisFileBytes[i + 10]).ToString(); //X + ECUName = ECUName + ((char)ThisFileBytes[i + 11]).ToString(); //X + ECUName = ECUName + ((char)ThisFileBytes[i + 12]).ToString(); //X + ECUName = ECUName + ((char)ThisFileBytes[i + 13]).ToString(); //X + } + } + + return ECUName; + } + private void button1_Click(object sender, EventArgs e) { DialogResult result = openFileDialog1.ShowDialog(); @@ -686,15 +743,23 @@ private void button1_Click(object sender, EventArgs e) this.Editortable_0.LoadedFilename = openFileDialog1.FileName; this.IsFullBinary = false; - DarkMessageBox.Show(this, "Since this decompressed firmware .bin file is missing the bootloader section\nSelect the firmware .rwd file from which is as been decompressed from", "MISSING BOOTLOADER SECTION FOR CHECKSUMS VERIFICATIONS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + int BtSumInt = CheckForBootLoaderSum(ExtractECUNameFromThisFile(FilesBytes)); + if (BtSumInt == -1) + { + DarkMessageBox.Show(this, "Since this decompressed firmware .bin file is missing the bootloader section\nSelect the firmware .rwd file from which is as been decompressed from", "MISSING BOOTLOADER SECTION FOR CHECKSUMS VERIFICATIONS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - //Open RWD firmware - openFileDialog1.Filter = "Honda Compressed RWD Firmware|*.gz;*.rwd"; - openFileDialog1.DefaultExt = "*.gz"; - result = openFileDialog1.ShowDialog(); - if (result == DialogResult.OK) + //Open RWD firmware + openFileDialog1.Filter = "Honda Compressed RWD Firmware|*.gz;*.rwd"; + openFileDialog1.DefaultExt = "*.gz"; + result = openFileDialog1.ShowDialog(); + if (result == DialogResult.OK) + { + Class_RWD.LoadRWD(openFileDialog1.FileName, true, false); + } + } + else { - Class_RWD.LoadRWD(openFileDialog1.FileName, true, false); + Class_RWD.BootloaderSum = (byte) BtSumInt; } //Load Binary into ROM Table Editor diff --git a/FlashToolTest.csproj b/FlashToolTest.csproj index 4332fbc..92b8e89 100644 --- a/FlashToolTest.csproj +++ b/FlashToolTest.csproj @@ -158,6 +158,9 @@ + + Always + Always diff --git a/GForm_Main.cs b/GForm_Main.cs index e454bf8..428b472 100644 --- a/GForm_Main.cs +++ b/GForm_Main.cs @@ -30,7 +30,7 @@ public class GForm_Main : DarkForm private DarkButton darkButton6; private DarkButton darkButton3; public Editortable Editortable_0; - public string Version = "v1.1.0"; + public string Version = "v1.1.1"; public GForm_Main() { @@ -50,7 +50,9 @@ public GForm_Main() this.Text = this.Text + " (" + Version + ")"; Class_DefinitionMaker Class_DefinitionMaker_0 = new Class_DefinitionMaker(); - Class_DefinitionMaker_0.CreateDefinitionsFiles(); + //Class_DefinitionMaker_0.CreateDefinitionsFiles(); + //Class_DefinitionMaker_0.GetFilesDifferenceCount(); //may not be used anymore + //Class_DefinitionMaker_0.ExtractAllBootLoaderSum_1Mb(); //may not be used anymore } @@ -1031,7 +1033,7 @@ public byte[] VerifyChecksumFullBin(byte[] BinFileBytes) //######################################################## //######################################################## //Verify for 0x10400 - CheckLocation = 0x10400; + /*CheckLocation = 0x10400; num = BufferBytes[CheckLocation]; num2 = GetNegativeChecksumArea(BufferBytes, 0x8000, CheckLocation); if (num != num2) @@ -1043,7 +1045,7 @@ public byte[] VerifyChecksumFullBin(byte[] BinFileBytes) else { this.method_1("Checksum are good at 0x" + CheckLocation.ToString("X") + " | Checksum: 0x" + num2.ToString("X2")); - } + }*/ //######################################################## //######################################################## return BufferBytes; @@ -1074,7 +1076,7 @@ public byte[] VerifyChecksumFWBin(byte[] FWFileBytes) //######################################################## //######################################################## //Verify for 0x8400 (0x10400 in full bin) - CheckLocation = 0x8400; + /*CheckLocation = 0x8400; num = BufferBytes[CheckLocation]; num2 = GetNegativeChecksumArea(BufferBytes, 0, CheckLocation); if (num != num2) @@ -1086,7 +1088,7 @@ public byte[] VerifyChecksumFWBin(byte[] FWFileBytes) else { this.method_1("Checksum are good at 0x" + CheckLocation.ToString("X") + " | Checksum: 0x" + num2.ToString("X2")); - } + }*/ //######################################################## //######################################################## return BufferBytes;