Skip to content

Commit

Permalink
Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
bouletmarc committed May 23, 2022
1 parent e068382 commit 1a9ab55
Show file tree
Hide file tree
Showing 142 changed files with 55,180 additions and 52,997 deletions.
65 changes: 49 additions & 16 deletions ClassEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
internal class ClassEditor
{
public List<string> Ecus_Definitions_Compatible = new List<string>();
public List<string> Ecus_Definitions_Compatible_filename = new List<string>();

//Variables for loaded rom definition
public List<string> DefinitionsLocationsX = new List<string>();
Expand Down Expand Up @@ -48,6 +49,8 @@ internal class ClassEditor
public List<bool> DefinitionsIsReadOnly = new List<bool>();
public List<bool> DefinitionsIsUntested = new List<bool>();
public List<bool> DefinitionsIsNotDefined = new List<bool>();
public string DefinitionsChecksumLocation = "";
public string DefinitionsCurrentLoadedECU = "";

public long SelectedROMLocation;
public int SelectedTableSize;
Expand Down Expand Up @@ -377,8 +380,8 @@ public void SaveROMBytes(string string_4)

public void FixChecksums()
{
if (!this.Editortable_0.IsFullBinary) this.ROM_Bytes = this.Editortable_0.GForm_Main_0.VerifyChecksumFWBin(this.ROM_Bytes);
if (this.Editortable_0.IsFullBinary) this.ROM_Bytes = this.Editortable_0.GForm_Main_0.VerifyChecksumFullBin(this.ROM_Bytes);
if (!this.Editortable_0.IsFullBinary) this.ROM_Bytes = this.Editortable_0.GForm_Main_0.Class_Checksums_0.VerifyChecksumFWBin(this.ROM_Bytes);
if (this.Editortable_0.IsFullBinary) this.ROM_Bytes = this.Editortable_0.GForm_Main_0.Class_Checksums_0.VerifyChecksumFullBin(this.ROM_Bytes);

}

Expand Down Expand Up @@ -1000,7 +1003,11 @@ public bool LoadROMbytes(string string_4)
this.ROM_Bytes[i + 2] == 0x38 &&
this.ROM_Bytes[i + 3] == 0x30 &&
(this.ROM_Bytes[i + 4] == 0x35 || this.ROM_Bytes[i + 4] == 0x36) &&
this.ROM_Bytes[i + 5] == 0x2D)
this.ROM_Bytes[i + 5] == 0x2D &&
this.ROM_Bytes[i + 10] != 0x5A &&
this.ROM_Bytes[i + 11] != 0x5A &&
this.ROM_Bytes[i + 12] != 0x5A &&
this.ROM_Bytes[i + 13] != 0x5A)
{
for (int i2 = 0; i2 < 14; i2++)
{
Expand Down Expand Up @@ -1157,6 +1164,7 @@ public void LoadSupportedECUDefinitions()
try
{
Ecus_Definitions_Compatible = new List<string>();
Ecus_Definitions_Compatible_filename = new List<string>();

Editortable_0.CheckDefinitionFolderExist();

Expand All @@ -1166,8 +1174,13 @@ public void LoadSupportedECUDefinitions()
string[] AllDefinitionFiles = Directory.GetFiles(Folderpath, "*.txt", SearchOption.AllDirectories);

Editortable_0.GForm_Main_0.method_1("Loading definitions files...");
int CurrentIndex = 0;
foreach (string ThisFilePath in AllDefinitionFiles)
{
CurrentIndex++;
int Percent = (int)((CurrentIndex * 100) / AllDefinitionFiles.Length);
Editortable_0.GForm_Main_0.method_4(Percent);

string[] AllLines = File.ReadAllLines(ThisFilePath);
bool GettingEcuList = true;
for (int i = 0; i < AllLines.Length; i++)
Expand All @@ -1180,6 +1193,7 @@ public void LoadSupportedECUDefinitions()
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);
}
}
Expand All @@ -1197,18 +1211,25 @@ public void LoadSupportedECUDefinitions()
{
DarkMessageBox.Show("Failed to load definitions. " + ex.ToString());
}

Editortable_0.GForm_Main_0.ResetProgressBar();
}

public void LoadThisECUDefinitions(string ThisECU)
public void LoadThisECUDefinitions(string ThisECU, int ThisIndexfile)
{
if (DefinitionsCurrentLoadedECU == ThisECU) return;

try
{
Editortable_0.CheckDefinitionFolderExist();

string Folderpath = Application.StartupPath + @"\Definitions";
if (Directory.Exists(Folderpath))
string ThisFilename = Ecus_Definitions_Compatible_filename[ThisIndexfile];

//string Folderpath = Application.StartupPath + @"\Definitions";
//if (Directory.Exists(Folderpath))
if (File.Exists(ThisFilename))
{
string[] AllDefinitionFiles = Directory.GetFiles(Folderpath, "*.txt", SearchOption.AllDirectories);
//string[] AllDefinitionFiles = Directory.GetFiles(Folderpath, "*.txt", SearchOption.AllDirectories);

DefinitionsLocationsX = new List<string>();
DefinitionsLocationsY = new List<string>();
Expand Down Expand Up @@ -1238,13 +1259,17 @@ public void LoadThisECUDefinitions(string ThisECU)
DefinitionsIsReadOnly = new List<bool>();
DefinitionsIsUntested = new List<bool>();
DefinitionsIsNotDefined = new List<bool>();
DefinitionsChecksumLocation = "";
DefinitionsCurrentLoadedECU = ThisECU;

Editortable_0.GForm_Main_0.method_1("Loading ECU definitions for: " + ThisECU);
bool ECUFound = false;
bool ChecksumFound = false;
bool IsFileGenerated = false;
foreach (string ThisFilePath in AllDefinitionFiles)
{
string[] AllLines = File.ReadAllLines(ThisFilePath);
//foreach (string ThisFilePath in AllDefinitionFiles)
//{
//string[] AllLines = File.ReadAllLines(ThisFilePath);
string[] AllLines = File.ReadAllLines(ThisFilename);
bool GettingEcuList = true;

string CurrentLocationX = "";
Expand Down Expand Up @@ -1291,6 +1316,13 @@ public void LoadThisECUDefinitions(string ThisECU)
if (GettingEcuList && Thisline == ThisECU) ECUFound = true;
}

if (!ChecksumFound && Thisline.Contains("ChecksumAddress:"))
{
string[] Commands = Thisline.Split(':');
DefinitionsChecksumLocation = Commands[1];
ChecksumFound = true;
}

if (!GettingEcuList && !ECUFound) i = AllLines.Length;
if (!GettingEcuList && ECUFound)
{
Expand Down Expand Up @@ -1408,16 +1440,17 @@ public void LoadThisECUDefinitions(string ThisECU)
{
Editortable_0.GForm_Main_0.method_1("Definitions loaded!");

//HERE
if (IsFileGenerated) 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!");
return;
}
}
//}

if (!ECUFound) Editortable_0.GForm_Main_0.method_1("Definitions NOT loaded!");
}
else
{
DarkMessageBox.Show("Failed to find definitions folder.");
//if (!ECUFound) Editortable_0.GForm_Main_0.method_1("Definitions NOT loaded!");
/*}
else
{
DarkMessageBox.Show("Failed to find definitions folder.");*/
}
}
catch (Exception ex)
Expand Down
142 changes: 142 additions & 0 deletions Class_Checksums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DarkUI.Forms;

public class Class_Checksums
{
private GForm_Main GForm_Main_0;

public void Load(ref GForm_Main GForm_Main_1)
{
GForm_Main_0 = GForm_Main_1;
}

public byte GetNegativeChecksumArea(byte[] byte_1, int Start, int ChecksumLocation)
{
byte b = 0;
for (int i = Start; i < byte_1.Length; i++)
{
if (i != ChecksumLocation)
{
b -= byte_1[i];
}
}
return b;
}

public int GetChecksumLocationThisECU(string ThisECU)
{
int CheckLocation = 0;
if (GForm_Main_0.Editortable_0.LoadDefinitionsFor(ThisECU))
{
if (GForm_Main_0.Editortable_0.ClassEditor_0.DefinitionsChecksumLocation != "")
{
CheckLocation = int.Parse(GForm_Main_0.Editortable_0.ClassEditor_0.DefinitionsChecksumLocation.Replace("0x", ""), System.Globalization.NumberStyles.HexNumber);
}
}
return CheckLocation;
}

public int GetChecksumLocation(byte[] BinFileBytes)
{
byte[] BufferBytes = BinFileBytes;
int CheckLocation = 0;

string Thisecuu = GForm_Main_0.Editortable_0.ExtractECUNameFromThisFile(BinFileBytes);
if (Thisecuu != "")
{
if (GForm_Main_0.Editortable_0.LoadDefinitionsFor(Thisecuu))
{
if (GForm_Main_0.Editortable_0.ClassEditor_0.DefinitionsChecksumLocation != "")
{
CheckLocation = int.Parse(GForm_Main_0.Editortable_0.ClassEditor_0.DefinitionsChecksumLocation.Replace("0x", ""), System.Globalization.NumberStyles.HexNumber);
}
}
}

if (CheckLocation == 0)
{
//HERE
//GForm_Main_0.method_1("Checksum location not definied for '" + Thisecuu + "', using known checksum location but can possibly be wrong on some ecu!");

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 == 0xFFFFF) CheckLocation = 0x8400; //1mb-full
if (BufferBytes.Length - 1 == 0x1EFFFF) CheckLocation = 0x12; //2mb-fw
if (BufferBytes.Length - 1 == 0x1FFFFF) CheckLocation = 0x10012; //2mb-full
if (BufferBytes.Length - 1 == 0x26FFFF) CheckLocation = 0x1F03E6; //4mb-fw
if (BufferBytes.Length - 1 == 0x27FFFF) CheckLocation = 0x2003E6; //4mb-full //0x3FFFFF
}
}

return CheckLocation;
}

public byte[] VerifyChecksumFullBin(byte[] BinFileBytes)
{
//###############################
//Get Checksum and Fix it
byte[] BufferBytes = BinFileBytes;
int CheckLocation = GetChecksumLocation(BinFileBytes);

if (CheckLocation == 0)
{
GForm_Main_0.method_1("Checksum location not found!");
return BufferBytes;
}

byte num = BufferBytes[CheckLocation];
byte num2 = GetNegativeChecksumArea(BufferBytes, 0, CheckLocation);
if (num != num2)
{
GForm_Main_0.method_1("Checksum miss match.");
BufferBytes[CheckLocation] = num2;
GForm_Main_0.method_1("Checksum fixed at 0x" + CheckLocation.ToString("X") + " | Checksum: 0x" + num2.ToString("X2"));
}
else
{
GForm_Main_0.method_1("Checksum are good at 0x" + CheckLocation.ToString("X") + " | Checksum: 0x" + num2.ToString("X2"));
}
return BufferBytes;
}

public byte[] VerifyChecksumFWBin(byte[] FWFileBytes)
{
//###############################
//Get Checksum and Fix it
byte[] BufferBytes = FWFileBytes;
int CheckLocation = GetChecksumLocation(FWFileBytes);

if (CheckLocation == 0)
{
GForm_Main_0.method_1("Checksum location not found!");
return BufferBytes;
}

byte num = Class_RWD.BootloaderSum;
byte num2 = Class_RWD.GetNegativeChecksumFWBin(BufferBytes, CheckLocation);
byte ThisSum = num;
ThisSum -= num2;
byte chk = BufferBytes[CheckLocation];
if (chk != ThisSum)
{
GForm_Main_0.method_1("Checksum miss match.");
BufferBytes[CheckLocation] = 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"));
}
return BufferBytes;
}
}
Loading

0 comments on commit 1a9ab55

Please sign in to comment.