Exemplo n.º 1
0
        private ushort getBlockSize(Stream inStream, long hcaOffset)
        {
            ushort blockSize = 0;

            long decChunkOffset;
            long compChunkOffset;

            //----------------
            // 'dec ' offset
            //----------------

            // get 'dec' chunk offset, if exists (v1.3, maybe others?)
            decChunkOffset = ParseFile.GetNextOffsetWithLimitMasked(inStream, hcaOffset,
                                                                    hcaOffset + MAX_HEADER_SIZE, DEC_CHUNK_BYTES, MASK_BYTES, true);

            if (decChunkOffset > -1)
            {
                blockSize = ParseFile.ReadUshortBE(inStream, decChunkOffset + 4);
            }
            else
            {
                //----------------
                // 'comp' offset
                //----------------

                // get 'comp' chunk offset, if exists (v1.3, maybe others?)
                compChunkOffset = ParseFile.GetNextOffsetWithLimitMasked(inStream, hcaOffset,
                                                                         hcaOffset + MAX_HEADER_SIZE, COMP_CHUNK_BYTES, MASK_BYTES, true);

                if (compChunkOffset > -1)
                {
                    blockSize = ParseFile.ReadUshortBE(inStream, compChunkOffset + 4);
                }
                else
                {
                    throw new FormatException(
                              String.Format("Cannot find 'dec' or 'comp' chunk to determine block size for HCA starting at 0x{0}", hcaOffset.ToString("X8")));
                }
            }

            return(blockSize);
        }