Пример #1
0
        private void SkipAttribute(DataReader mReader)
        {
            ulong size = mReader.ReadPackedUInt64();
            if(size > (ulong)mReader.Remaining)
                throw new InvalidDataException();

            mReader.Skip((long)size);
        }
Пример #2
0
        private void ReadUnpackInfo(DataReader mReader, out FolderInfo[] folders)
        {
            WaitAttribute(mReader, BlockType.Folder);
            {
                int numFolders = mReader.ReadPackedUInt31();
                folders = new FolderInfo[numFolders];
                for(int i = 0; i < folders.Length; i++)
                    folders[i] = GetNextFolderItem(mReader);
            }

            WaitAttribute(mReader, BlockType.CodersUnpackSize);
            {
                for(int i = 0; i < folders.Length; i++)
                {
                    var folder = folders[i];
                    folder.UnpackSizes = new ulong[folder.GetNumOutStreams()];
                    for(int j = 0; j < folder.UnpackSizes.Length; j++)
                        folder.UnpackSizes[j] = mReader.ReadPackedUInt64();
                }
            }

            for(; ; )
            {
                var type = ReadBlockType(mReader);
                if(type == BlockType.End)
                    break;

                if(type == BlockType.CRC)
                {
                    BitVector defined;
                    uint[] crcs;
                    ReadHashDigests(mReader, folders.Length, out defined, out crcs);
                    for(int i = 0; i < folders.Length; i++)
                        if(defined[i])
                            folders[i].UnpackCRC = crcs[i];
                    continue;
                }

                SkipAttribute(mReader);
            }
        }
Пример #3
0
        private void ReadPackInfo(DataReader mReader, out ulong[] packSizes, out BitVector packCRCsDefined, out uint[] packCRCs)
        {
            packCRCsDefined = null;
            packCRCs = null;

            ulong dataOffset = mReader.ReadPackedUInt64();
            int numPackStreams = mReader.ReadPackedUInt31();

            WaitAttribute(mReader, BlockType.Size);
            {
                packSizes = new ulong[numPackStreams];
                for(int i = 0; i < numPackStreams; i++)
                    packSizes[i] = mReader.ReadPackedUInt64();
            }

            for(; ; )
            {
                var type = ReadBlockType(mReader);
                if(type == BlockType.End)
                    break;

                if(type == BlockType.CRC)
                    ReadHashDigests(mReader, numPackStreams, out packCRCsDefined, out packCRCs);
                else
                    SkipAttribute(mReader);
            }

            if(packCRCsDefined == null)
            {
                packCRCsDefined = new BitVector(numPackStreams);
                packCRCs = new uint[numPackStreams];
            }
        }
Пример #4
0
        private void ReadSubStreamsInfo(DataReader mReader, FolderInfo[] folders, out int[] numUnpackStreamsInFolders, out List<ulong> unpackSizes, out BitVector crcDefined, out uint[] crcs)
        {
            numUnpackStreamsInFolders = new int[folders.Length];
            for(int i = 0; i < numUnpackStreamsInFolders.Length; i++)
                numUnpackStreamsInFolders[i] = 1;

            BlockType? type;
            for(; ; )
            {
                type = ReadBlockType(mReader);

                if(type == BlockType.NumUnpackStream)
                {
                    for(int i = 0; i < numUnpackStreamsInFolders.Length; i++)
                        numUnpackStreamsInFolders[i] = mReader.ReadPackedUInt31();
                    continue;
                }

                if(type == BlockType.End || type == BlockType.CRC || type == BlockType.Size)
                    break;

                SkipAttribute(mReader);
            }

            for(int i = 0; i < numUnpackStreamsInFolders.Length; i++)
            {
                int numSubstreams = numUnpackStreamsInFolders[i];
                if(numSubstreams == 0)
                    continue;

                ulong sum = 0;
                if(type == BlockType.Size)
                {
                    for(int j = 1; j < numSubstreams; j++)
                    {
                        ulong size = mReader.ReadPackedUInt64();
                        unpackSizes.Add(size);
                        sum += size;
                    }
                }

                unpackSizes.Add(folders[i].GetUnpackSize() - sum);
            }

            if(type == BlockType.Size)
                type = ReadBlockType(mReader);

            int numCRCs = 0;
            int numCRCsTotal = 0;
            for(int i = 0; i < folders.Length; i++)
            {
                int numSubstreams = numUnpackStreamsInFolders[i];
                if(numSubstreams != 1 || folders[i].UnpackCRC == null)
                    numCRCs += numSubstreams;
                numCRCsTotal += numSubstreams;
            }

            for(; ; )
            {
                if(type == BlockType.CRC)
                {
                    BitVector defined2;
                    uint[] crcs2;
                    ReadHashDigests(mReader, numCRCs, out defined2, out crcs2);

                }
                else if(type == BlockType.End)
                    break;
                else
                    SkipAttribute(mReader);

                type = ReadBlockType(mReader);
            }

            if(crcDefined == null)
            {
                throw new NotImplementedException();
            }
        }
Пример #5
0
 private BlockType? ReadBlockType(DataReader mReader)
 {
     ulong value = mReader.ReadPackedUInt64();
     if(value > 25)
         return null;
     else
         return (BlockType)value;
 }