tdi41v2_checksum_search() public method

public tdi41v2_checksum_search ( byte file_buffer, UInt32 file_size, bool debug ) : ChecksumResult
file_buffer byte
file_size System.UInt32
debug bool
return ChecksumResult
Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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;
        }