Ejemplo n.º 1
0
        public void FindMetadata()
        {
            const string DensoASCII = "DENSO";
            // Euro5 (not Euro4) diesel as well as newer petrol models have System String
            const string DieselASCII = "DIESEL";
            const string TurboASCII = "TURBO";

            long posDenso = 0;
            long pos;
            string strFound;

            stream.Position = 0;
            if (FindExtendASCII (stream, DensoASCII, out strFound, out pos)) {
                PrintStringInfo (strFound, pos);
                // sometimes i.e. first char is ASCII but wrong, should start with 'C', for "Copr." or similar
                posDenso = pos;
                int i = strFound.IndexOf ('C');
                if (i > 0 && i < 4) {
                    posDenso += i;
                }
            }

            stream.Position = 0;
            if (FindExtendASCII (stream, DieselASCII, out strFound, out pos)) {
                PrintStringInfo (strFound, pos);
            }

            stream.Position = 0;
            if (FindExtendASCII (stream, TurboASCII, out strFound, out pos)) {
                PrintStringInfo (strFound, pos);
            }

            // 0x4000 = 16 KiB
            const int Pos_SH7058_Diesel = 0x4000;
            const int RomIDlongLength = 32;
            const int CIDLength = 8;

            switch (RomType) {
            case RomType.SH7058:
            case RomType.SH7059:
                pos = Pos_SH7058_Diesel;
                break;
            default:
                Console.WriteLine ("Unknown RomType");
                return;
            }

            string romIDlong = ReadASCII (pos, RomIDlongLength).TrimEnd ();
            if (CheckString (romIDlong, Predicate)) {
                Console.WriteLine ("RomIDlong[{0}]: {1}", romIDlong.Length.ToString (), romIDlong);
            }

            string CID = romIDlong.Substring (romIDlong.Length - CIDLength);
            if (CheckString (CID, Predicate)) {
                Console.WriteLine ("CID: {0}", CID);
            }

            // HACK
            bool isDiesel = posDenso > 0x4000;

            if (posDenso > 0) {
                try {
                    stream.Position = posDenso - 3;
                    int year, month, day;

                    if (isDiesel) {
                        year = stream.ReadByte () + 2000;
                        month = stream.ReadByte ();
                        day = stream.ReadByte ();
                    } else {
                        year = ParsePackedNaturalBCD ((byte)stream.ReadByte ()) + 2000;
                        month = ParsePackedNaturalBCD ((byte)stream.ReadByte ());
                        day = ParsePackedNaturalBCD ((byte)stream.ReadByte ());
                    }

                    this.romDate = new DateTime (year, month, day);
                    Console.WriteLine ("RomDate: {0}", RomDateStr);
                } catch (Exception) {
                    Console.Error.WriteLine ("RomDate failed");
                }
            }

            if (posDenso > 0) {
                try {
                    var reflashCounterObj = new ReflashCounter (romType, stream);
                    reflashCount = reflashCounterObj.Read ();
                    Console.WriteLine ("ReflashCount @ 0x{0:X} = {1}", reflashCounterObj.Position, ReflashCountStr);
                } catch (Exception) {
                    Console.Error.WriteLine ("ReflashCount failed");
                }
            }

            byte[] searchBytes = new byte[] { 0xA2, 0x10, 0x14 };
            stream.Position = 0;
            var ssmIDpos = Util.SearchBinary.FindBytes (stream, searchBytes);
            Console.WriteLine ("Diesel SSMID pos: 0x{0:X}", ssmIDpos);

            const int RomIDLength = 5;
            byte[] romidBytes = new byte[RomIDLength];
            long romid;
            if (ssmIDpos.HasValue) {
                stream.Position = ssmIDpos.Value + 3;
                if (stream.Read (romidBytes, 0, RomIDLength) == RomIDLength) {
                    // parse value from 5 bytes, big endian
                    romid = ((long)(romidBytes [0]) << 32) + Util.BinaryHelper.Int32BigEndian (romidBytes, 1);
                    Console.WriteLine ("ROMID: {0}", romid.ToString ("X10"));
                }
            }
        }
Ejemplo n.º 2
0
        public void FindMetadata()
        {
            const string DensoASCII = "DENSO";
            // Euro5 (not Euro4) diesel as well as newer petrol models have System String
            const string DieselASCII = "DIESEL";
            const string TurboASCII  = "TURBO";

            long   posDenso = 0;
            long   pos;
            string strFound;

            stream.Position = 0;
            if (FindExtendASCII(stream, DensoASCII, out strFound, out pos))
            {
                PrintStringInfo(strFound, pos);
                // sometimes i.e. first char is ASCII but wrong, should start with 'C', for "Copr." or similar
                posDenso = pos;
                int i = strFound.IndexOf('C');
                if (i > 0 && i < 4)
                {
                    posDenso += i;
                }
            }

            stream.Position = 0;
            if (FindExtendASCII(stream, DieselASCII, out strFound, out pos))
            {
                PrintStringInfo(strFound, pos);
            }

            stream.Position = 0;
            if (FindExtendASCII(stream, TurboASCII, out strFound, out pos))
            {
                PrintStringInfo(strFound, pos);
            }

            // 0x4000 = 16 KiB
            const int Pos_SH7058_Diesel = 0x4000;
            // 0x8000 = 32 KiB
            const int Pos_SH72543R_Diesel = 0x8000;

            const int RomIDlongLength = 32;
            const int CIDLength       = 8;

            switch (RomType)
            {
            case RomType.SH7058:
            case RomType.SH7059:
                pos = Pos_SH7058_Diesel;
                break;

            case RomType.SH72543R:
                pos = Pos_SH72543R_Diesel;
                break;

            default:
                Console.WriteLine("Unknown RomType");
                return;
            }


            string romIDlong = ReadASCII(pos, RomIDlongLength).TrimEnd();

            if (CheckString(romIDlong, Predicate))
            {
                Console.WriteLine("RomIDlong[{0}]: {1}", romIDlong.Length.ToString(), romIDlong);
            }

            string CID = romIDlong.Substring(romIDlong.Length - CIDLength);

            if (CheckString(CID, Predicate))
            {
                Console.WriteLine("CID: {0}", CID);
            }

            // HACK
            bool isDiesel = posDenso > 0x4000;

            if (posDenso > 0)
            {
                try {
                    stream.Position = posDenso - 3;
                    DateTime?date;

                    if (isDiesel)
                    {
                        date = Util.BinaryHelper.ParseDate(stream);
                    }
                    else
                    {
                        date = Util.BinaryHelper.ParseDatePackedNaturalBCD(stream);
                    }

                    this.romDate = date;
                    Console.WriteLine("RomDate: {0}", RomDateStr);
                } catch (Exception) {
                    Console.Error.WriteLine("Exception: RomDate failed");
                }
            }

            if (posDenso > 0)
            {
                try {
                    var reflashCounterObj = new ReflashCounter(romType, stream);
                    this.reflashCount = reflashCounterObj.Read();
                    Console.WriteLine("ReflashCount @ 0x{0:X} = {1}", reflashCounterObj.Position, ReflashCountStr);
                } catch (Exception) {
                    Console.Error.WriteLine("Exception: ReflashCount failed");
                }
            }

            try {
                var obj = new RomRaiderEditStamp(romType, stream);
                this.romRaiderEditStampData = obj.Read();
                Console.WriteLine("RomRaiderEditStamp @ 0x{0:X} = {1}", obj.Position, romRaiderEditStampData);
            } catch (Exception) {
                Console.Error.WriteLine("Exception: RomRaiderEditStamp failed");
            }

            byte[] searchBytes = new byte[] { 0xA2, 0x10, 0x14 };
            stream.Position = 0;
            var ssmIDpos = Util.SearchBinary.FindBytes(stream, searchBytes);

            Console.WriteLine("Diesel SSMID pos: 0x{0:X}", ssmIDpos);

            const int RomIDLength = 5;

            byte[] romidBytes = new byte[RomIDLength];
            long   romid;

            if (ssmIDpos.HasValue)
            {
                stream.Position = ssmIDpos.Value + 3;
                if (stream.Read(romidBytes, 0, RomIDLength) == RomIDLength)
                {
                    // parse value from 5 bytes, big endian
                    romid = ((long)(romidBytes [0]) << 32) + Util.BinaryHelper.Int32BigEndian(romidBytes, 1);
                    Console.WriteLine("ROMID: {0}", romid.ToString("X10"));
                }
            }
        }