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); }
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; }