コード例 #1
0
        public const int ItemSize = (1 + 8 + 4 + 4) + 1;         // 1 more than length of fields

        internal MultiStreamItemHeader(QQnBinaryReader reader)
        {
            byte version = reader.ReadByte();

            if (version == 1)
            {
                _offset   = reader.ReadInt64();
                _length   = reader.ReadUInt32();               // As uint
                _itemType = reader.ReadInt32();
            }
            else if (version == 2)
            {
                // Define some format which allows +4GB substream
                // When this is used we will need some more padding space; but it probably will never be written anyway
                // At least we can read them with this version

                _offset   = reader.ReadInt64();
                _length   = reader.ReadInt64();               // As long
                _itemType = reader.ReadInt32();
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
コード例 #2
0
        /*public AssuredStreamHeader(Stream source)
         *      : this(source, VerificationMode.Full)
         * {
         * }*/

        public AssuredStreamHeader(Stream source, VerificationMode mode)
        {
            QQnBinaryReader br             = new QQnBinaryReader(source);
            uint            vFileSignature = br.ReadUInt32();

            if (vFileSignature != FileSignature)
            {
                throw new FormatException();
            }

            _fileType      = br.ReadString();
            _hashType      = (HashType)br.ReadByte();
            _fileHash      = br.ReadByteArray();
            _hashSignature = br.ReadByteArray();
            byte[] publicKey = br.ReadByteArray();

            if (publicKey.Length > 0)
            {
                _snk = StrongNameKey.LoadFrom(publicKey);

                if (mode != VerificationMode.None)
                {
                    if (!_snk.VerifyHash(_fileHash, _hashSignature))
                    {
                        throw new CryptographicException("Stream hash verification failed");
                    }
                }
            }
            _guid       = new Guid(br.ReadBytes(16));
            _bodyLength = br.ReadInt64();

            _hashPosition = source.Position;
        }