Beispiel #1
0
        public static Store CreateRoStore(byte[] aData)
        {
            Store store = new Store();

            uint index = 0;

            while (true)
            {
                // get the length
                uint entryBytes = BigEndian.UintAt(aData, index);

                if (entryBytes == 0xffffffff)
                {
                    // end of entries
                    break;
                }

                // get the key
                uint entryKey = BigEndian.UintAt(aData, index + 4);

                // mask off length to see if entry is incomplete and get real length
                bool entryIncomplete = (entryBytes & 0x80000000) != 0;
                entryBytes &= 0x7fffffff;

                // get total length - the entry length rounded up to multiple of 4 bytes
                uint totalBytes = (entryBytes + 3) & 0xfffffffc;

                if (totalBytes < 8)
                {
                    return(null);
                }
                else if (index + totalBytes > aData.Length)
                {
                    return(null);
                }
                else if (entryIncomplete)
                {
                    // skip incomplete enty
                }
                else if (entryKey == 0)
                {
                    // skip obsolete entry
                }
                else
                {
                    // entry is ok

                    byte[] bytes = new byte[entryBytes - 8];

                    Array.Copy(aData, index + 8, bytes, 0, entryBytes - 8);

                    store.Add(new StoreEntry(entryKey, bytes));
                }

                index += totalBytes;
            }

            return(store);
        }
Beispiel #2
0
        public static RomDirEntry Create(byte[] aData, uint aOffset)
        {
            uint key             = BigEndian.UintAt(aData, aOffset);
            uint flashId         = BigEndian.UintAt(aData, aOffset + 4);
            uint offset          = BigEndian.UintAt(aData, aOffset + 8);
            uint bytes           = BigEndian.UintAt(aData, aOffset + 12);
            uint type            = BigEndian.UintAt(aData, aOffset + 16);
            uint crc             = BigEndian.UintAt(aData, aOffset + 20);
            uint originalFlashId = BigEndian.UintAt(aData, aOffset + 24);
            uint originalOffset  = BigEndian.UintAt(aData, aOffset + 28);

            return(new RomDirEntry(key, flashId, offset, bytes, type, crc, originalFlashId, originalOffset));
        }
Beispiel #3
0
        public static RomDir Create(byte[] aData, uint aOffset)
        {
            RomDir romdir = new RomDir();

            uint entries = BigEndian.UintAt(aData, aOffset);

            if (entries > kMaxEntryCount)
            {
                // Rom directory corrupt
                return(null);
            }

            // Read entries

            uint offset = aOffset + 4;

            for (uint i = 0; i < entries; i++)
            {
                romdir.Add(RomDirEntry.Create(aData, offset));
                offset += RomDirEntry.kRomDirEntryBytes;
            }

            return(romdir);
        }
Beispiel #4
0
        public static Store CreateRwStore(byte[] aData, uint aSectorBytes)
        {
            Assert.Check((aSectorBytes & (aSectorBytes - 1)) == 0); // aSectorBytes is power of 2
            Assert.Check(aData.Length % aSectorBytes == 0);         // data length is multiple of aSectorBytes

            Store store = new Store();

            uint numSectors = (uint)aData.Length / aSectorBytes;

            for (uint i = 0; i < numSectors; i++)
            {
                uint sectorIdx = i * aSectorBytes;

                uint sectorFlags = BigEndian.UintAt(aData, sectorIdx);

                if (sectorFlags != 0xcccccccc)
                {
                    // skip free, unknown or erasing sectors
                    Trace.WriteLine(Trace.kCore, "BinaryRwToStore: Sector " + i + " not used: 0x" + sectorFlags.ToString("X"));
                    continue;
                }

                Trace.WriteLine(Trace.kCore, "BinaryRwToStore: Sector " + i + " starting");

                uint currIdx = sectorIdx + 4;

                while (true)
                {
                    // get the length
                    uint entryBytes = BigEndian.UintAt(aData, currIdx);

                    if (entryBytes == 0xffffffff)
                    {
                        // end of entries in this sector
                        break;
                    }

                    // get the key
                    uint entryKey = BigEndian.UintAt(aData, currIdx + 4);

                    // mask off length to see if entry is incomplete and get real length
                    bool entryIncomplete = (entryBytes & 0x80000000) != 0;
                    entryBytes &= 0x7fffffff;

                    // get total length - the entry length rounded up to multiple of 4 bytes
                    uint totalBytes = (entryBytes + 3) & 0xfffffffc;

                    if (totalBytes < 8)
                    {
                        return(null);
                    }
                    else if (currIdx + totalBytes > sectorIdx + aSectorBytes)
                    {
                        return(null);
                    }
                    else if (entryIncomplete)
                    {
                        // skip incomplete enty
                    }
                    else if (entryKey == 0)
                    {
                        // skip obsolete entry
                    }
                    else
                    {
                        // entry is ok

                        byte[] bytes = new byte[entryBytes - 8];

                        Array.Copy(aData, currIdx + 8, bytes, 0, entryBytes - 8);

                        store.Add(new StoreEntry(entryKey, bytes));
                    }

                    currIdx += totalBytes;
                }
            }

            return(store);
        }