Beispiel #1
0
        byte[] _Read(uint count)
        {
            byte[] data = Reader.ReadBytes((int)count);
            for (int i = 0; i < data.Length; i++)
            {
                Key      = CryptedDtbStream.XorKey(Key);
                data[i] ^= (byte)Key;
            }
            Offset += (uint)data.Length;

            return(data);
        }
Beispiel #2
0
        void _Write(byte[] buffer, uint offset, uint count)
        {
            byte[] buf = new byte[count];
            for (int i = 0; i < count; i++)
            {
                Key    = CryptedDtbStream.XorKey(Key);
                buf[i] = (byte)(buffer[i + offset] ^ Key);
            }
            Stream.Write(buf, 0, (int)count);

            Offset += count;
        }
Beispiel #3
0
        public ChunkedDtbStream(EndianReader reader)
        {
            Mode   = ChunkedMode.Chunk;
            Stream = reader.Base;
            Reader = reader;

            uint i, j;

            Stream.Position = 4;
            Key             = Reader.ReadInt32();

            ChunkMap = new int[Chunks + 1];
            Seeds    = new int[SeedIndexCount];

            ChunkMap[0] = -8;
            for (i = 1; i <= Chunks; i++)
            {
                int pos;
                Stream.Position = (i - 1) * ChunkSize;
                byte[] buffer = Reader.ReadBytes(ChunkSize);
                for (pos = ChunkSize; pos > 0; pos--)
                {
                    if (buffer[pos - 1] != 0)
                    {
                        break;
                    }
                }
                ChunkMap[i] = ChunkMap[i - 1] + pos;
            }

            length = (uint)ChunkMap[ChunkMap.Length - 1];
            //Length = ChunkMap[(sizeof(ChunkMap)/sizeof(ChunkMap[0]))-1];

            // calculate seeds for faster seeking
            for (i = 0; i < length; i += SeedLength)
            {
                Seeds[i / SeedLength] = Key;
                for (j = 0; j < SeedLength; j++)
                {
                    Key = CryptedDtbStream.XorKey(Key);
                }
            }

            Offset          = 0;
            Key             = Seeds[0];
            Stream.Position = 8;
        }