Beispiel #1
0
        private void GetBodyKey()
        {
            BodyKey = new byte[0x10];

            _headerStream.Position = 0;
            _headerStream.Read(BodyKey, 0, 0x10);
        }
Beispiel #2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            var read = 0;

            //Unencrypted header from 0 to 0x30; Contains headerkey and magic
            if (Position < 0x30)
            {
                _baseStream.Position = Position;

                var size = Math.Min(count, 0x30 - (int)Position);
                read += _baseStream.Read(buffer, read + offset, size);

                Position += size;
            }

            //Encrypted header from 0x30 to 0x60; Contains bodykey and meta information like size
            //Gets decrypted with BBCipher, headerkey and vkey
            if (Position < 0x60 && read < count)
            {
                _headerStream.Position = Position - 0x30;

                var size = Math.Min(count - read, 0x60 - (int)Position);
                read += _headerStream.Read(buffer, read + offset, size);

                Position += size;
            }

            //Unencrypted MAC data from 0x60 to 0x90; Contains 3 MACs, each validating data portion from 0 to {position of MAC}
            //One MAC is 0x10 bytes long
            if (Position < 0x90 && read < count)
            {
                _baseStream.Position = Position;

                var size = Math.Min(count - read, 0x90 - (int)Position);
                read += _baseStream.Read(buffer, read + offset, size);

                Position += size;
            }

            //Encrypted file data from 0x90 to file end; Contains all file data
            //Gets decrypted with BBCipher, bodykey and vkey
            if (read < count)
            {
                _bodyStream.Position = Position - 0x90;

                var size = Math.Min(count - read, _bodyStream.Length - Position);
                read += _bodyStream.Read(buffer, read + offset, (int)size);

                Position += size;
            }

            return(read);
        }