Пример #1
0
        public byte[] CreateRoStore()
        {
            int bytes = 0;

            foreach (StoreEntry e in iStoreEntryList.Values)
            {
                bytes += (e.Data.Length + 8 + 3) & ~3;
            }

            bytes += 4;

            byte[] data = new byte[bytes];

            for (uint i = 0; i < bytes; i++)
            {
                data[i] = 0xff;
            }

            int offset = 0;

            foreach (StoreEntry e in iStoreEntryList.Values)
            {
                byte[] length = BigEndian.Bytes(e.Data.Length + 8);
                byte[] key    = BigEndian.Bytes(e.Key);

                Array.Copy(length, 0, data, offset, 4);
                Array.Copy(key, 0, data, offset + 4, 4);
                Array.Copy(e.Data, 0, data, offset + 8, e.Data.Length);

                int skip = (e.Data.Length + 8 + 3) & ~3;

                offset += skip;
            }

            return(data);
        }
Пример #2
0
        public byte[] Create()
        {
            byte[] key             = BigEndian.Bytes(iKey);
            byte[] flashId         = BigEndian.Bytes(iFlashId);
            byte[] offset          = BigEndian.Bytes(iOffset);
            byte[] bytes           = BigEndian.Bytes(iBytes);
            byte[] type            = BigEndian.Bytes(iType);
            byte[] crc             = BigEndian.Bytes(iCrc);
            byte[] originalFlashId = BigEndian.Bytes(iOriginalFlashId);
            byte[] originalOffset  = BigEndian.Bytes(iOriginalOffset);

            byte[] data = new byte[kRomDirEntryBytes];

            Array.Copy(key, 0, data, 0, 4);
            Array.Copy(flashId, 0, data, 4, 4);
            Array.Copy(offset, 0, data, 8, 4);
            Array.Copy(bytes, 0, data, 12, 4);
            Array.Copy(type, 0, data, 16, 4);
            Array.Copy(crc, 0, data, 20, 4);
            Array.Copy(originalFlashId, 0, data, 24, 4);
            Array.Copy(originalOffset, 0, data, 28, 4);

            return(data);
        }
Пример #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);
        }
Пример #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);
        }
Пример #5
0
 public static StoreEntry Create(uint aKey, int aValue)
 {
     byte[] bytes = BigEndian.Bytes(aValue);
     return(new StoreEntry(aKey, bytes));
 }