Skip to content

Commit

Permalink
V1.1.6 - Several Bugfixes, Additions, Etc
Browse files Browse the repository at this point in the history
  • Loading branch information
bouletmarc committed May 29, 2022
1 parent 1a9ab55 commit 4982825
Show file tree
Hide file tree
Showing 475 changed files with 34,763 additions and 22,032 deletions.
562 changes: 293 additions & 269 deletions BootLoaderSumBytesList.txt

Large diffs are not rendered by default.

37 changes: 23 additions & 14 deletions ClassEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ public void GetChanges()

public void SaveROMBytes(string string_4)
{
try
{
//try
//{
if (this.ValuesChanged && this.SelectedTableSize != 0 && this.SelectedROMLocation != 0)
{
this.GetChanges();
Expand All @@ -328,13 +328,13 @@ public void SaveROMBytes(string string_4)
if (FileFormat == "1mb-fw")
{
byte[] BufferBytes = new byte[SavingBytes.Length - 0x8000];
for (int i = 0; i < SavingBytes.Length; i++) BufferBytes[i] = SavingBytes[i + 0x8000];
for (int i = 0; i < BufferBytes.Length; i++) BufferBytes[i] = SavingBytes[i + 0x8000];
SavingBytes = BufferBytes;
}
if (FileFormat == "2mb-fw" || FileFormat == "4mb-fw")
{
byte[] BufferBytes = new byte[SavingBytes.Length - 0x10000];
for (int i = 0; i < SavingBytes.Length; i++) BufferBytes[i] = SavingBytes[i + 0x10000];
for (int i = 0; i < BufferBytes.Length; i++) BufferBytes[i] = SavingBytes[i + 0x10000];
SavingBytes = BufferBytes;
}
}
Expand Down Expand Up @@ -371,11 +371,11 @@ public void SaveROMBytes(string string_4)
File.Delete(text);
File.Delete(text2);*/
DarkMessageBox.Show("Successfully Saved File!.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
catch
/*}
catch (Exception ex)
{
DarkMessageBox.Show("Failed to save file!.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
DarkMessageBox.Show("Failed to save file! error: " + Environment.NewLine + ex, "Save file failed", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}*/
}

public void FixChecksums()
Expand Down Expand Up @@ -974,7 +974,7 @@ public bool LoadROMbytes(string string_4)
//Console.WriteLine(Editortable_0.IsFullBinary);
//Console.WriteLine(FileFormat);

//Create a fake bootloader section
//Create fake bootloader section
if (!Editortable_0.IsFullBinary)
{
if (FileFormat == "1mb-fw")
Expand Down Expand Up @@ -1168,6 +1168,8 @@ public void LoadSupportedECUDefinitions()

Editortable_0.CheckDefinitionFolderExist();

int LoadedDefCount = 0;

string Folderpath = Application.StartupPath + @"\Definitions";
if (Directory.Exists(Folderpath))
{
Expand All @@ -1188,19 +1190,26 @@ public void LoadSupportedECUDefinitions()
string Thisline = AllLines[i];
if (Thisline.Contains("ROM Parameters") || Thisline.Contains("Checksum ")) GettingEcuList = false; //make sure we are not reading false contents

if (Thisline[0] != '#' && Thisline != "")
if (Thisline != "")
{
if (GettingEcuList)
if (Thisline[0] != '#')
{
Ecus_Definitions_Compatible.Add(Thisline);
Ecus_Definitions_Compatible_filename.Add(ThisFilePath);
Editortable_0.GForm_Main_0.method_1("Definitions found for ecu: " + Thisline);
if (GettingEcuList)
{
Ecus_Definitions_Compatible.Add(Thisline);
Ecus_Definitions_Compatible_filename.Add(ThisFilePath);
Editortable_0.GForm_Main_0.method_1("Definitions found for ecu: " + Thisline);
LoadedDefCount++;
}
}
}

if (!GettingEcuList) i = AllLines.Length;
}
}

Editortable_0.GForm_Main_0.ClearLogs();
Editortable_0.GForm_Main_0.method_1(LoadedDefCount + " definitions loaded!");
}
else
{
Expand Down
50 changes: 43 additions & 7 deletions Class_Checksums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
public class Class_Checksums
{
private GForm_Main GForm_Main_0;
public int LastChecksumLocationLoaded = 0;
public string LastChecksumECUName = "";

public void Load(ref GForm_Main GForm_Main_1)
{
Expand Down Expand Up @@ -52,6 +54,11 @@ public int GetChecksumLocation(byte[] BinFileBytes)
string Thisecuu = GForm_Main_0.Editortable_0.ExtractECUNameFromThisFile(BinFileBytes);
if (Thisecuu != "")
{
if (Thisecuu == LastChecksumECUName)
{
return LastChecksumLocationLoaded;
}

if (GForm_Main_0.Editortable_0.LoadDefinitionsFor(Thisecuu))
{
if (GForm_Main_0.Editortable_0.ClassEditor_0.DefinitionsChecksumLocation != "")
Expand All @@ -69,15 +76,17 @@ public int GetChecksumLocation(byte[] BinFileBytes)
DialogResult result = DarkMessageBox.Show("Checksum location not definied for '" + Thisecuu + "'" + Environment.NewLine + "Do you want to use 'known good' checksum location but they still can possibly be wrong on some ecu?", "Checksum location", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (result == DialogResult.Yes)
{
if (BufferBytes.Length - 1 == 0xF7FFF) CheckLocation = 0x400; //1mb-fw -> 0x8400 in full bin but we dont have the bootloader 0x0000 to 0x8000
if (BufferBytes.Length - 1 == 0xF7FFF) CheckLocation = 0x8400; //1mb-fw -> 0x8400 in full bin but we dont have the bootloader 0x0000 to 0x8000
if (BufferBytes.Length - 1 == 0xFFFFF) CheckLocation = 0x8400; //1mb-full
if (BufferBytes.Length - 1 == 0x1EFFFF) CheckLocation = 0x12; //2mb-fw
if (BufferBytes.Length - 1 == 0x1EFFFF) CheckLocation = 0x10012; //2mb-fw
if (BufferBytes.Length - 1 == 0x1FFFFF) CheckLocation = 0x10012; //2mb-full
if (BufferBytes.Length - 1 == 0x26FFFF) CheckLocation = 0x1F03E6; //4mb-fw
if (BufferBytes.Length - 1 == 0x26FFFF) CheckLocation = 0x2003E6; //4mb-fw
if (BufferBytes.Length - 1 == 0x27FFFF) CheckLocation = 0x2003E6; //4mb-full //0x3FFFFF
}
}

LastChecksumECUName = Thisecuu;
LastChecksumLocationLoaded = CheckLocation;
return CheckLocation;
}

Expand Down Expand Up @@ -121,21 +130,48 @@ public byte[] VerifyChecksumFWBin(byte[] FWFileBytes)
GForm_Main_0.method_1("Checksum location not found!");
return BufferBytes;
}
int CheckLocationInBIN = CheckLocation;

if (FWFileBytes.Length - 1 == 0xF7FFF || FWFileBytes.Length - 1 == 0xFFFFF) CheckLocation -= 0x8000;
if (FWFileBytes.Length - 1 == 0x1EFFFF || FWFileBytes.Length - 1 == 0x1FFFFF ||
FWFileBytes.Length - 1 == 0x26FFFF || FWFileBytes.Length - 1 == 0x27FFFF) CheckLocation -= 0x10000;

if (FWFileBytes.Length - 1 == 0xF7FFF) CheckLocationInBIN -= 0x8000;
if (FWFileBytes.Length - 1 == 0x1EFFFF || FWFileBytes.Length - 1 == 0x1FFFFF) CheckLocationInBIN -= 0x10000;

//Console.WriteLine("Checksum location: " + CheckLocation.ToString("X"));
//Console.WriteLine("Checksum locationin bin: " + CheckLocationInBIN.ToString("X"));

//Remake/remove bootloader section in case the bytes array is a full binary
byte[] BufferBytesForChecking = new byte[] { };
if (FWFileBytes.Length - 1 == 0xFFFFF)
{
BufferBytesForChecking = new byte[FWFileBytes.Length - 0x8000];
for (int i = 0; i < BufferBytesForChecking.Length; i++) BufferBytesForChecking[i] = FWFileBytes[i + 0x8000];
}
if (FWFileBytes.Length - 1 == 0x26FFFF || FWFileBytes.Length - 1 == 0x27FFFF)
{
BufferBytesForChecking = new byte[FWFileBytes.Length - 0x10000];
for (int i = 0; i < BufferBytesForChecking.Length; i++) BufferBytesForChecking[i] = FWFileBytes[i + 0x10000];
}

byte num = Class_RWD.BootloaderSum;
byte num2 = Class_RWD.GetNegativeChecksumFWBin(BufferBytes, CheckLocation);
byte num2 = Class_RWD.GetNegativeChecksumFWBin(BufferBytesForChecking, CheckLocation);
byte ThisSum = num;
ThisSum -= num2;
byte chk = BufferBytes[CheckLocation];
byte chk = BufferBytes[CheckLocationInBIN];
//Console.WriteLine("Bootsum: " + num.ToString("X"));
//Console.WriteLine("ThisSum: " + ThisSum.ToString("X"));
//Console.WriteLine("ThisCheck: " + chk.ToString("X"));
if (chk != ThisSum)
{
GForm_Main_0.method_1("Checksum miss match.");
BufferBytes[CheckLocation] = ThisSum;
BufferBytes[CheckLocationInBIN] = ThisSum;
GForm_Main_0.method_1("Checksum fixed at 0x" + CheckLocation.ToString("X") + " | Checksum: 0x" + num2.ToString("X2"));
}
else
{
GForm_Main_0.method_1("checksum good at 0x" + CheckLocation.ToString("X") + " | Checksum: 0x" + num2.ToString("X2"));
GForm_Main_0.method_1("Checksum good at 0x" + CheckLocation.ToString("X") + " | Checksum: 0x" + num2.ToString("X2"));
}
return BufferBytes;
}
Expand Down
Loading

0 comments on commit 4982825

Please sign in to comment.