private ChecksumResult CalculateEDC15PChecksum(string filename, byte[] allBytes, bool verifyOnly, out ChecksumResultDetails result) { ChecksumResult res = new ChecksumResult(); // checksum for EDC15P is implemented result = new ChecksumResultDetails(); result.CalculationResult = ChecksumResult.ChecksumFail; // default = failed result.TypeResult = ChecksumType.VAG_EDC15P_V41; if (allBytes.Length != 0x80000) { return(res); } if (allBytes[0x50008] == 'V' && allBytes[0x50009] == '4' && allBytes[0x5000A] == '.' && allBytes[0x5000B] == '1') { // checksum V4.1 rev.1 result.TypeResult = ChecksumType.VAG_EDC15P_V41; } else if (allBytes[0x58008] == 'V' && allBytes[0x58009] == '4' && allBytes[0x5800A] == '.' && allBytes[0x5800B] == '1') { // checksum V4.1 rev.2 result.TypeResult = ChecksumType.VAG_EDC15P_V41V2; } //allBytes = reverseEndian(allBytes); EDC15P_checksum chks = new EDC15P_checksum(); if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) { res = chks.tdi41_checksum_search(allBytes, (uint)allBytes.Length, false); } else { res = chks.tdi41v2_checksum_search(allBytes, (uint)allBytes.Length, false); } result.NumberChecksumsTotal = chks.ChecksumsFound; result.NumberChecksumsFail = chks.ChecksumsIncorrect; result.NumberChecksumsOk = chks.ChecksumsFound - chks.ChecksumsIncorrect; if (res == ChecksumResult.ChecksumOK) { Console.WriteLine("Checksum V4.1 matched"); result.CalculationOk = true; } else if (res == ChecksumResult.ChecksumFail) { Console.WriteLine("UpdateChecksum: Checksum failed " + filename); if (!verifyOnly) { File.WriteAllBytes(filename, allBytes); result.CalculationOk = true; Console.WriteLine("UpdateChecksum: Checksum fixed"); } } else if (res == ChecksumResult.ChecksumTypeError) { result.TypeResult = ChecksumType.VAG_EDC15P_V41_2002; EDC15P_checksum chks2002 = new EDC15P_checksum(); allBytes = File.ReadAllBytes(filename); //chks2002.DumpChecksumLocations("V41 2002", allBytes); // for debug info only ChecksumResult res2002 = chks2002.tdi41_2002_checksum_search(allBytes, (uint)allBytes.Length, false); result.NumberChecksumsTotal = chks2002.ChecksumsFound; result.NumberChecksumsFail = chks2002.ChecksumsIncorrect; result.NumberChecksumsOk = chks2002.ChecksumsFound - chks2002.ChecksumsIncorrect; if (res2002 == ChecksumResult.ChecksumOK) { Console.WriteLine("Checksum 2002 matched " + filename); result.CalculationOk = true; } else if (res2002 == ChecksumResult.ChecksumFail) { Console.WriteLine("UpdateChecksum: Checksum 2002 failed " + filename); if (!verifyOnly) { File.WriteAllBytes(filename, allBytes); result.CalculationOk = true; Console.WriteLine("UpdateChecksum: Checksum fixed"); } } else if (res2002 == ChecksumResult.ChecksumTypeError) { // unknown checksum type result.CalculationOk = false; result.CalculationResult = ChecksumResult.ChecksumTypeError; result.TypeResult = ChecksumType.Unknown; } } return(res); }
public ChecksumResultDetails UpdateChecksum(string filename, bool verifyOnly) { byte[] allBytes; ChecksumResult res = new ChecksumResult();; ChecksumResultDetails result = new ChecksumResultDetails(); EDCFileType fileType = DetermineFileType(filename, false); switch (fileType) { case EDCFileType.EDC15P: case EDCFileType.EDC15P6: allBytes = File.ReadAllBytes(filename); res = CalculateEDC15PChecksum(filename, allBytes, verifyOnly, out result); break; case EDCFileType.EDC15V: // EDC15VM+ is similar to EDC15P allBytes = File.ReadAllBytes(filename); res = CalculateEDC15VMChecksum(filename, allBytes, verifyOnly, out result); break; case EDCFileType.EDC15C: //TODO: Implement EDC15C checksum routine here break; case EDCFileType.EDC15M: //TODO: Implement EDC15M checksum routine here break; case EDCFileType.EDC16: //TODO: Implement EDC16x checksum routine here break; case EDCFileType.EDC17: //TODO: Implement EDC17x checksum routine here break; case EDCFileType.MSA15: case EDCFileType.MSA12: case EDCFileType.MSA11: //TODO: Implement MSA15 checksum routine here // this should be Bosch TDI V3.1 (Version 2.04) /* result.TypeResult = ChecksumType.VAG_EDC15P_V41; * allBytes = File.ReadAllBytes(filename); * //allBytes = reverseEndian(allBytes); * MSA15_checksum msa15chks = new MSA15_checksum(); * * res = msa15chks.tdi41_checksum_search(allBytes, (uint)allBytes.Length, false); * result.NumberChecksumsTotal = msa15chks.ChecksumsFound; * result.NumberChecksumsFail = msa15chks.ChecksumsIncorrect; * result.NumberChecksumsOk = msa15chks.ChecksumsFound - msa15chks.ChecksumsIncorrect; * if (res == ChecksumResult.ChecksumOK) * { * //Console.WriteLine("Checksum matched"); * result.CalculationOk = true; * } * else if (res == ChecksumResult.ChecksumFail) * { * Console.WriteLine("UpdateChecksum: Checksum failed " + filename); * if (!verifyOnly) * { * File.WriteAllBytes(filename, allBytes); * result.CalculationOk = true; * Console.WriteLine("UpdateChecksum: Checksum fixed"); * } * * }*/ break; case EDCFileType.MSA6: //TODO: Implement MSA6 checksum routine here break; } if (result.CalculationOk) { result.CalculationResult = ChecksumResult.ChecksumOK; } return(result); }
private ChecksumResult CalculateEDC15VMChecksum(string filename, byte[] allBytes, bool verifyOnly, out ChecksumResultDetails result) { ChecksumResult res = new ChecksumResult(); result = new ChecksumResultDetails(); result.CalculationResult = ChecksumResult.ChecksumFail; // default = failed result.TypeResult = ChecksumType.VAG_EDC15VM_V41; if (/*allBytes.Length != 0x40000 && */allBytes.Length != 0x80000 && allBytes.Length != 0x100000) return res; if (allBytes.Length >= 0x80000) { if (allBytes[0x50008] == 'V' && allBytes[0x50009] == '4' && allBytes[0x5000A] == '.' && allBytes[0x5000B] == '1') { // checksum V4.1 rev.1 result.TypeResult = ChecksumType.VAG_EDC15VM_V41; } else if (allBytes[0x58008] == 'V' && allBytes[0x58009] == '4' && allBytes[0x5800A] == '.' && allBytes[0x5800B] == '1') { // checksum V4.1 rev.2 result.TypeResult = ChecksumType.VAG_EDC15VM_V41V2; } } //allBytes = reverseEndian(allBytes); EDC15VM_checksum chks = new EDC15VM_checksum(); if (result.TypeResult == ChecksumType.VAG_EDC15VM_V41) { res = chks.tdi41_checksum_search(allBytes, (uint)allBytes.Length, false); } else { res = chks.tdi41v2_checksum_search(allBytes, (uint)allBytes.Length, false); } result.NumberChecksumsTotal = chks.ChecksumsFound; result.NumberChecksumsFail = chks.ChecksumsIncorrect; result.NumberChecksumsOk = chks.ChecksumsFound - chks.ChecksumsIncorrect; if (res == ChecksumResult.ChecksumOK) { Console.WriteLine("Checksum V4.1 matched"); result.CalculationOk = true; } else if (res == ChecksumResult.ChecksumFail) { Console.WriteLine("UpdateChecksum: Checksum failed " + filename); if (!verifyOnly) { File.WriteAllBytes(filename, allBytes); result.CalculationOk = true; Console.WriteLine("UpdateChecksum: Checksum fixed"); } } else if (res == ChecksumResult.ChecksumTypeError) { result.TypeResult = ChecksumType.VAG_EDC15VM_V41_2002; EDC15VM_checksum chks2002 = new EDC15VM_checksum(); allBytes = File.ReadAllBytes(filename); ChecksumResult res2002 = chks2002.tdi41_2002_checksum_search(allBytes, (uint)allBytes.Length, false); result.NumberChecksumsTotal = chks2002.ChecksumsFound; result.NumberChecksumsFail = chks2002.ChecksumsIncorrect; result.NumberChecksumsOk = chks2002.ChecksumsFound - chks2002.ChecksumsIncorrect; if (res2002 == ChecksumResult.ChecksumOK) { Console.WriteLine("Checksum 2002 matched " + filename); result.CalculationOk = true; } else if (res2002 == ChecksumResult.ChecksumFail) { Console.WriteLine("UpdateChecksum: Checksum 2002 failed " + filename); if (!verifyOnly) { File.WriteAllBytes(filename, allBytes); result.CalculationOk = true; Console.WriteLine("UpdateChecksum: Checksum fixed"); } } else if (res2002 == ChecksumResult.ChecksumTypeError) { // unknown checksum type result.CalculationOk = false; result.CalculationResult = ChecksumResult.ChecksumTypeError; result.TypeResult = ChecksumType.Unknown; } } return res; }
public ChecksumResultDetails UpdateChecksum(string filename, bool verifyOnly) { byte[] allBytes; ChecksumResult res = new ChecksumResult(); ; ChecksumResultDetails result = new ChecksumResultDetails(); EDCFileType fileType = DetermineFileType(filename, false); switch (fileType) { case EDCFileType.EDC15P: case EDCFileType.EDC15P6: allBytes = File.ReadAllBytes(filename); res = CalculateEDC15PChecksum(filename, allBytes, verifyOnly, out result); break; case EDCFileType.EDC15V: // EDC15VM+ is similar to EDC15P allBytes = File.ReadAllBytes(filename); res = CalculateEDC15VMChecksum(filename, allBytes, verifyOnly, out result); break; case EDCFileType.EDC15C: //TODO: Implement EDC15C checksum routine here break; case EDCFileType.EDC15M: //TODO: Implement EDC15M checksum routine here break; case EDCFileType.EDC16: //TODO: Implement EDC16x checksum routine here break; case EDCFileType.EDC17: //TODO: Implement EDC17x checksum routine here break; case EDCFileType.MSA15: case EDCFileType.MSA12: case EDCFileType.MSA11: //TODO: Implement MSA15 checksum routine here // this should be Bosch TDI V3.1 (Version 2.04) /* result.TypeResult = ChecksumType.VAG_EDC15P_V41; allBytes = File.ReadAllBytes(filename); //allBytes = reverseEndian(allBytes); MSA15_checksum msa15chks = new MSA15_checksum(); res = msa15chks.tdi41_checksum_search(allBytes, (uint)allBytes.Length, false); result.NumberChecksumsTotal = msa15chks.ChecksumsFound; result.NumberChecksumsFail = msa15chks.ChecksumsIncorrect; result.NumberChecksumsOk = msa15chks.ChecksumsFound - msa15chks.ChecksumsIncorrect; if (res == ChecksumResult.ChecksumOK) { //Console.WriteLine("Checksum matched"); result.CalculationOk = true; } else if (res == ChecksumResult.ChecksumFail) { Console.WriteLine("UpdateChecksum: Checksum failed " + filename); if (!verifyOnly) { File.WriteAllBytes(filename, allBytes); result.CalculationOk = true; Console.WriteLine("UpdateChecksum: Checksum fixed"); } }*/ break; case EDCFileType.MSA6: //TODO: Implement MSA6 checksum routine here break; } if (result.CalculationOk) result.CalculationResult = ChecksumResult.ChecksumOK; return result; }
private void LoadFiles() { loading = true; simpleButton1.Text = "Cancel"; simpleButton2.Enabled = false; SetProgressVisibility(true); SetScanProgress("scanning...", 0); Application.DoEvents(); ctrlAirmassResult airmassResult = new ctrlAirmassResult(); partNumberConverter pnc = new partNumberConverter(); List <ScannedFile> detectedFiles = new List <ScannedFile>(); int fileCounter = 0; if (Directory.Exists(buttonEdit1.Text)) { string[] files = Directory.GetFiles(buttonEdit1.Text, "*.*", SearchOption.AllDirectories); foreach (string file in files) { fileCounter++; int percentage = (fileCounter * 100) / files.Length; SetScanProgress("importing...", percentage); if (cancelLoad) { cancelLoad = false; break; } FileInfo fi = new FileInfo(file); this.Text = "Library builder - " + Path.GetFileNameWithoutExtension(file); Application.DoEvents(); if (IsValidLength(fi.Length)) { IEDCFileParser parser = Tools.Instance.GetParserForFile(file, false); byte[] allBytes = File.ReadAllBytes(file); string boschPartnumber = parser.ExtractBoschPartnumber(allBytes); List <CodeBlock> newCodeBlocks = new List <CodeBlock>(); List <AxisHelper> newAxisHelpers = new List <AxisHelper>(); if (boschPartnumber != string.Empty) { //string additionalInfo = parser.ExtractInfo(allBytes); SymbolCollection sc = parser.parseFile(file, out newCodeBlocks, out newAxisHelpers); ECUInfo info = pnc.ConvertPartnumber(boschPartnumber, allBytes.Length); ScannedFile newFile = new ScannedFile(); newFile.CarMake = info.CarMake; newFile.CarType = info.CarType; newFile.EcuType = info.EcuType; newFile.EngineType = info.EngineType; newFile.FuellingType = info.FuellingType; newFile.FuelType = info.FuelType; newFile.HP = info.HP; newFile.PartNumber = info.PartNumber; newFile.SoftwareID = info.SoftwareID; newFile.TQ = info.TQ; if (info.EcuType.Contains("EDC15P-6")) { newFile.Filetype = EDCFileType.EDC15P6; } else if (info.EcuType.Contains("EDC15P")) { newFile.Filetype = EDCFileType.EDC15P; } else if (info.EcuType.Contains("EDC15M")) { newFile.Filetype = EDCFileType.EDC15M; } else if (info.EcuType.Contains("EDC15V-5.")) { newFile.Filetype = EDCFileType.MSA15; } else if (info.EcuType.Contains("EDC15V")) { newFile.Filetype = EDCFileType.EDC15V; } else if (info.EcuType.Contains("EDC15C")) { newFile.Filetype = EDCFileType.EDC15C; } else if (info.EcuType.Contains("EDC16")) { newFile.Filetype = EDCFileType.EDC16; } else if (info.EcuType.Contains("EDC17")) { newFile.Filetype = EDCFileType.EDC17; } else if (info.EcuType.Contains("MSA15")) { newFile.Filetype = EDCFileType.MSA15; } else if (info.EcuType.Contains("MSA12")) { newFile.Filetype = EDCFileType.MSA12; } else if (info.EcuType.Contains("MSA11")) { newFile.Filetype = EDCFileType.MSA11; } else if (info.EcuType.Contains("MSA6")) { newFile.Filetype = EDCFileType.MSA6; } else if (boschPartnumber != string.Empty) { if (fi.Length == 1024 * 1024 * 2) { newFile.Filetype = EDCFileType.EDC17; } else if (boschPartnumber.StartsWith("EDC17")) { newFile.Filetype = EDCFileType.EDC17; } else { newFile.Filetype = EDCFileType.EDC15V; } } else { newFile.Filetype = EDCFileType.EDC16; // default to EDC16??? } newFile.Filename = file; newFile.Filesize = (int)fi.Length; ChecksumResultDetails crd = Tools.Instance.UpdateChecksum(file, true); string chkType = string.Empty; if (crd.TypeResult == ChecksumType.VAG_EDC15P_V41) { chkType = "VAG EDC15P V4.1"; } else if (crd.TypeResult == ChecksumType.VAG_EDC15P_V41V2) { chkType = "VAG EDC15P V4.1v2"; } else if (crd.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) { chkType = "VAG EDC15P V4.1 2002+"; } newFile.ChecksumType = chkType; newFile.ChecksumResult = crd.CalculationResult.ToString(); newFile.NumberChecksums = crd.NumberChecksumsTotal; newFile.NumberChecksumsFail = crd.NumberChecksumsFail; newFile.NumberChecksumsOk = crd.NumberChecksumsOk; newFile.NumberMapsDetected = sc.Count; string _message = string.Empty; newFile.MapsOk = CheckMajorMapsPresent(sc, newFile.Filetype, out _message); newFile.Messages = _message; foreach (SymbolHelper sh in sc) { if (!sh.Varname.StartsWith("3D") && !sh.Varname.StartsWith("2D")) { newFile.NumberMapsRecognized++; } } try { airmassResult.Currentfile = file; airmassResult.Symbols = sc; airmassResult.Currentfile_size = (int)fi.Length; string additionalInfo = parser.ExtractInfo(allBytes); airmassResult.NumberCylinders = pnc.GetNumberOfCylinders(info.EngineType, additionalInfo); airmassResult.ECUType = info.EcuType; PerformanceResults pr = airmassResult.Calculate(file, sc); newFile.RealHP = pr.Horsepower; newFile.RealTQ = pr.Torque; } catch (Exception) { } detectedFiles.Add(newFile); } else if (file.ToUpper().EndsWith(".BIN") || file.ToUpper().EndsWith(".ORI")) { Console.WriteLine("Missed " + file); // add it as well if (checkEdit1.Checked) { ScannedFile newFile = new ScannedFile(); newFile.CarMake = ""; newFile.CarType = ""; newFile.EcuType = "Unknown"; newFile.EngineType = ""; newFile.FuellingType = ""; newFile.FuelType = ""; newFile.HP = 0; newFile.PartNumber = ""; newFile.SoftwareID = ""; newFile.TQ = 0; newFile.Filetype = EDCFileType.Unknown; newFile.Filename = file; newFile.Filesize = (int)fi.Length; newFile.ChecksumType = ""; newFile.ChecksumResult = ""; newFile.NumberChecksums = 0; newFile.NumberChecksumsFail = 0; newFile.NumberChecksumsOk = 0; newFile.NumberMapsDetected = 0; newFile.MapsOk = false; newFile.Messages = ""; newFile.NumberMapsRecognized = 0; detectedFiles.Add(newFile); } } } } gridControl1.DataSource = detectedFiles; } loading = false; SetScanProgress("done", 100); SetProgressVisibility(false); this.Text = "Library builder"; simpleButton1.Text = "Close"; simpleButton2.Enabled = true; Application.DoEvents(); }
private void VerifyChecksum(string filename, bool showQuestion, bool showInfo) { string chkType = string.Empty; barChecksum.Caption = "---"; ChecksumResultDetails result = new ChecksumResultDetails(); if (m_appSettings.AutoChecksum) { result = Tools.Instance.UpdateChecksum(filename, false); if (showInfo) { if (result.CalculationOk) { if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = " V4.1"; else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = " V4.1v2"; else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = " V4.1 2002"; else if (result.TypeResult != ChecksumType.Unknown) chkType = result.TypeResult.ToString(); frmInfoBox info = new frmInfoBox("Checksums are correct [" + chkType + "]"); } else { if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = " V4.1"; else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = " V4.1v2"; else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = " V4.1 2002"; else if (result.TypeResult != ChecksumType.Unknown) chkType = result.TypeResult.ToString(); frmInfoBox info = new frmInfoBox("Checksums are INCORRECT [" + chkType + "]"); } } } else { result = Tools.Instance.UpdateChecksum(filename, true); if (!result.CalculationOk) { if (showQuestion && result.TypeResult != ChecksumType.Unknown) { if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = " V4.1"; else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = " V4.1v2"; else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = " V4.1 2002"; else if (result.TypeResult != ChecksumType.Unknown) chkType = result.TypeResult.ToString(); frmChecksumIncorrect frmchk = new frmChecksumIncorrect(); frmchk.ChecksumType = chkType; frmchk.NumberChecksums = result.NumberChecksumsTotal; frmchk.NumberChecksumsFailed = result.NumberChecksumsFail; frmchk.NumberChecksumsPassed = result.NumberChecksumsOk; if(frmchk.ShowDialog() == DialogResult.OK) //if (MessageBox.Show("Checksums are invalid. Do you wish to correct them?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes) { result = Tools.Instance.UpdateChecksum(filename, false); } } else if (showInfo && result.TypeResult == ChecksumType.Unknown) { frmInfoBox info = new frmInfoBox("Checksum for this filetype is not yet implemented"); } } else { if (showInfo) { if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = " V4.1"; else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = " V4.1v2"; else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = " V4.1 2002"; else if (result.TypeResult != ChecksumType.Unknown) chkType = result.TypeResult.ToString(); frmInfoBox info = new frmInfoBox("Checksums are correct [" + chkType + "]"); } } } if (result.TypeResult == ChecksumType.VAG_EDC15P_V41) chkType = " V4.1"; else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41V2) chkType = " V4.1v2"; else if (result.TypeResult == ChecksumType.VAG_EDC15P_V41_2002) chkType = " V4.1 2002"; if (!result.CalculationOk) { barChecksum.Caption = "Checksum failed" + chkType; } else { barChecksum.Caption = "Checksum Ok" + chkType; } Application.DoEvents(); }