Exemplo n.º 1
0
        // Compressed files start with an array of offsets to make seeking possible
        private void LoadBlockPositions()
        {
            int blockposcount = (int)((_entry.FileSize + _blockSize - 1) / _blockSize) + 1;

            // Files with metadata have an extra block containing block checksums
            if ((_entry.Flags & MpqFileFlags.FileHasMetadata) != 0)
            {
                blockposcount++;
            }

            _blockPositions = new uint[blockposcount];

            lock (_stream)
            {
                _stream.Seek(_entry.FilePos, SeekOrigin.Begin);
                BinaryReader br = new BinaryReader(_stream);
                for (int i = 0; i < blockposcount; i++)
                {
                    _blockPositions[i] = br.ReadUInt32();
                }
            }

            uint blockpossize = (uint)blockposcount * 4;

            /*
             * if(_blockPositions[0] != blockpossize)
             *  _entry.Flags |= MpqFileFlags.Encrypted;
             */

            if (_entry.IsEncrypted)
            {
                if (_entry.EncryptionSeed == 0)  // This should only happen when the file name is not known
                {
                    _entry.EncryptionSeed = MpqArchive.DetectFileSeed(_blockPositions[0], _blockPositions[1], blockpossize) + 1;
                    if (_entry.EncryptionSeed == 1)
                    {
                        throw new MpqParserException("Unable to determine encyption seed");
                    }
                }

                MpqArchive.DecryptBlock(_blockPositions, _entry.EncryptionSeed - 1);

                if (_blockPositions[0] != blockpossize)
                {
                    throw new MpqParserException("Decryption failed");
                }
                if (_blockPositions[1] > _blockSize + blockpossize)
                {
                    throw new MpqParserException("Decryption failed");
                }
            }
        }
Exemplo n.º 2
0
        private void LoadBlockPositions()
        {
            int num = ((int)(((this._entry.FileSize + this._blockSize) - 1) / ((long)this._blockSize))) + 1;

            if ((this._entry.Flags & MpqFileFlags.FileHasMetadata) != ((MpqFileFlags)0))
            {
                num++;
            }
            this._blockPositions = new uint[num];
            lock (this._stream)
            {
                this._stream.Seek((long)this._entry.FilePos, SeekOrigin.Begin);
                BinaryReader reader = new BinaryReader(this._stream);
                for (int i = 0; i < num; i++)
                {
                    this._blockPositions[i] = reader.ReadUInt32();
                }
            }
            uint decrypted = (uint)(num * 4);

            if (this._entry.IsEncrypted)
            {
                if (this._entry.EncryptionSeed == 0)
                {
                    this._entry.EncryptionSeed = MpqArchive.DetectFileSeed(this._blockPositions[0], this._blockPositions[1], decrypted) + 1;
                    if (this._entry.EncryptionSeed == 1)
                    {
                        throw new MpqParserException("Unable to determine encyption seed");
                    }
                }
                MpqArchive.DecryptBlock(this._blockPositions, this._entry.EncryptionSeed - 1);
                if (this._blockPositions[0] != decrypted)
                {
                    throw new MpqParserException("Decryption failed");
                }
                if (this._blockPositions[1] > (this._blockSize + decrypted))
                {
                    throw new MpqParserException("Decryption failed");
                }
            }
        }