Exemplo n.º 1
0
 public void Reset()
 {
     this.gzipHeaderSubstate             = GZipDecoder.GzipHeaderState.ReadingID1;
     this.gzipFooterSubstate             = GZipDecoder.GzipHeaderState.ReadingCRC;
     this.expectedCrc32                  = 0u;
     this.expectedOutputStreamSizeModulo = 0u;
 }
Exemplo n.º 2
0
 public bool ReadFooter(InputBuffer input)
 {
     input.SkipToByteBoundary();
     if (this.gzipFooterSubstate == GZipDecoder.GzipHeaderState.ReadingCRC)
     {
         for (; this.loopCounter < 4; ++this.loopCounter)
         {
             int bits = input.GetBits(8);
             if (bits < 0)
             {
                 return(false);
             }
             this.expectedCrc32 |= (uint)(bits << 8 * this.loopCounter);
         }
         this.gzipFooterSubstate = GZipDecoder.GzipHeaderState.ReadingFileSize;
         this.loopCounter        = 0;
     }
     if (this.gzipFooterSubstate == GZipDecoder.GzipHeaderState.ReadingFileSize)
     {
         if (this.loopCounter == 0)
         {
             this.expectedOutputStreamSizeModulo = 0U;
         }
         for (; this.loopCounter < 4; ++this.loopCounter)
         {
             int bits = input.GetBits(8);
             if (bits < 0)
             {
                 return(false);
             }
             this.expectedOutputStreamSizeModulo |= (uint)(bits << 8 * this.loopCounter);
         }
     }
     return(true);
 }
Exemplo n.º 3
0
        public bool ReadHeader(InputBuffer input)
        {
            int bits;

            switch (this.gzipHeaderSubstate)
            {
            case GZipDecoder.GzipHeaderState.ReadingID1:
                bits = input.GetBits(8);
                if (bits < 0)
                {
                    return(false);
                }
                if (bits != 31)
                {
                    throw new InvalidDataException(SR.GetString("Corrupted gzip header"));
                }
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingID2;
                break;

            case GZipDecoder.GzipHeaderState.ReadingID2:
                break;

            case GZipDecoder.GzipHeaderState.ReadingCM:
                goto IL_A5;

            case GZipDecoder.GzipHeaderState.ReadingFLG:
                goto IL_CE;

            case GZipDecoder.GzipHeaderState.ReadingMMTime:
                goto IL_F1;

            case GZipDecoder.GzipHeaderState.ReadingXFL:
                goto IL_128;

            case GZipDecoder.GzipHeaderState.ReadingOS:
                goto IL_13D;

            case GZipDecoder.GzipHeaderState.ReadingXLen1:
                goto IL_152;

            case GZipDecoder.GzipHeaderState.ReadingXLen2:
                goto IL_17B;

            case GZipDecoder.GzipHeaderState.ReadingXLenData:
                goto IL_1A8;

            case GZipDecoder.GzipHeaderState.ReadingFileName:
                goto IL_1E5;

            case GZipDecoder.GzipHeaderState.ReadingComment:
                goto IL_212;

            case GZipDecoder.GzipHeaderState.ReadingCRC16Part1:
                goto IL_240;

            case GZipDecoder.GzipHeaderState.ReadingCRC16Part2:
                goto IL_26A;

            case GZipDecoder.GzipHeaderState.Done:
                return(true);

            default:
                throw new InvalidDataException(SR.GetString("Unknown state"));
            }
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            if (bits != 139)
            {
                throw new InvalidDataException(SR.GetString("Corrupted gzip header"));
            }
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingCM;
IL_A5:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            if (bits != 8)
            {
                throw new InvalidDataException(SR.GetString("Unknown compression mode"));
            }
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingFLG;
IL_CE:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzip_header_flag   = bits;
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingMMTime;
            this.loopCounter        = 0;
IL_F1:
            while (this.loopCounter < 4)
            {
                bits = input.GetBits(8);
                if (bits < 0)
                {
                    return(false);
                }
                this.loopCounter++;
            }
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingXFL;
            this.loopCounter        = 0;
IL_128:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingOS;
IL_13D:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingXLen1;
IL_152:
            if ((this.gzip_header_flag & 4) == 0)
            {
                goto IL_1E5;
            }
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzip_header_xlen   = bits;
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingXLen2;
IL_17B:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzip_header_xlen  |= bits << 8;
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingXLenData;
            this.loopCounter        = 0;
IL_1A8:
            while (this.loopCounter < this.gzip_header_xlen)
            {
                bits = input.GetBits(8);
                if (bits < 0)
                {
                    return(false);
                }
                this.loopCounter++;
            }
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingFileName;
            this.loopCounter        = 0;
IL_1E5:
            if ((this.gzip_header_flag & 8) == 0)
            {
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingComment;
            }
            else
            {
                while (true)
                {
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        break;
                    }
                    if (bits == 0)
                    {
                        goto Block_20;
                    }
                }
                return(false);

Block_20:
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingComment;
            }
IL_212:
            if ((this.gzip_header_flag & 16) == 0)
            {
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingCRC16Part1;
            }
            else
            {
                while (true)
                {
                    bits = input.GetBits(8);
                    if (bits < 0)
                    {
                        break;
                    }
                    if (bits == 0)
                    {
                        goto Block_23;
                    }
                }
                return(false);

Block_23:
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingCRC16Part1;
            }
IL_240:
            if ((this.gzip_header_flag & 2) == 0)
            {
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.Done;
                return(true);
            }
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingCRC16Part2;
IL_26A:
            bits = input.GetBits(8);
            if (bits < 0)
            {
                return(false);
            }
            this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.Done;
            return(true);
        }
Exemplo n.º 4
0
        public bool ReadHeader(InputBuffer input)
        {
            int num;

            switch (this.gzipHeaderSubstate)
            {
            case GZipDecoder.GzipHeaderState.ReadingID1:
                int bits1 = input.GetBits(8);
                if (bits1 < 0)
                {
                    return(false);
                }
                if (bits1 != 31)
                {
                    throw new InvalidDataException(SR.GetString("Corrupted gzip header"));
                }
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingID2;
                goto case GZipDecoder.GzipHeaderState.ReadingID2;

            case GZipDecoder.GzipHeaderState.ReadingID2:
                int bits2 = input.GetBits(8);
                if (bits2 < 0)
                {
                    return(false);
                }
                if (bits2 != 139)
                {
                    throw new InvalidDataException(SR.GetString("Corrupted gzip header"));
                }
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingCM;
                goto case GZipDecoder.GzipHeaderState.ReadingCM;

            case GZipDecoder.GzipHeaderState.ReadingCM:
                int bits3 = input.GetBits(8);
                if (bits3 < 0)
                {
                    return(false);
                }
                if (bits3 != 8)
                {
                    throw new InvalidDataException(SR.GetString("Unknown compression mode"));
                }
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingFLG;
                goto case GZipDecoder.GzipHeaderState.ReadingFLG;

            case GZipDecoder.GzipHeaderState.ReadingFLG:
                int bits4 = input.GetBits(8);
                if (bits4 < 0)
                {
                    return(false);
                }
                this.gzip_header_flag   = bits4;
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingMMTime;
                this.loopCounter        = 0;
                goto case GZipDecoder.GzipHeaderState.ReadingMMTime;

            case GZipDecoder.GzipHeaderState.ReadingMMTime:
                num = 0;
                for (; this.loopCounter < 4; ++this.loopCounter)
                {
                    if (input.GetBits(8) < 0)
                    {
                        return(false);
                    }
                }
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingXFL;
                this.loopCounter        = 0;
                goto case GZipDecoder.GzipHeaderState.ReadingXFL;

            case GZipDecoder.GzipHeaderState.ReadingXFL:
                if (input.GetBits(8) < 0)
                {
                    return(false);
                }
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingOS;
                goto case GZipDecoder.GzipHeaderState.ReadingOS;

            case GZipDecoder.GzipHeaderState.ReadingOS:
                if (input.GetBits(8) < 0)
                {
                    return(false);
                }
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingXLen1;
                goto case GZipDecoder.GzipHeaderState.ReadingXLen1;

            case GZipDecoder.GzipHeaderState.ReadingXLen1:
                if ((this.gzip_header_flag & 4) != 0)
                {
                    int bits5 = input.GetBits(8);
                    if (bits5 < 0)
                    {
                        return(false);
                    }
                    this.gzip_header_xlen   = bits5;
                    this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingXLen2;
                    goto case GZipDecoder.GzipHeaderState.ReadingXLen2;
                }
                else
                {
                    goto case GZipDecoder.GzipHeaderState.ReadingFileName;
                }

            case GZipDecoder.GzipHeaderState.ReadingXLen2:
                int bits6 = input.GetBits(8);
                if (bits6 < 0)
                {
                    return(false);
                }
                this.gzip_header_xlen  |= bits6 << 8;
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingXLenData;
                this.loopCounter        = 0;
                goto case GZipDecoder.GzipHeaderState.ReadingXLenData;

            case GZipDecoder.GzipHeaderState.ReadingXLenData:
                num = 0;
                for (; this.loopCounter < this.gzip_header_xlen; ++this.loopCounter)
                {
                    if (input.GetBits(8) < 0)
                    {
                        return(false);
                    }
                }
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingFileName;
                this.loopCounter        = 0;
                goto case GZipDecoder.GzipHeaderState.ReadingFileName;

            case GZipDecoder.GzipHeaderState.ReadingFileName:
                if ((this.gzip_header_flag & 8) == 0)
                {
                    this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingComment;
                    goto case GZipDecoder.GzipHeaderState.ReadingComment;
                }
                else
                {
                    while (true)
                    {
                        int bits5 = input.GetBits(8);
                        if (bits5 >= 0)
                        {
                            if (bits5 == 0)
                            {
                                goto label_50;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    return(false);

label_50:
                    this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingComment;
                    goto case GZipDecoder.GzipHeaderState.ReadingComment;
                }

            case GZipDecoder.GzipHeaderState.ReadingComment:
                if ((this.gzip_header_flag & 16) == 0)
                {
                    this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingCRC16Part1;
                    goto case GZipDecoder.GzipHeaderState.ReadingCRC16Part1;
                }
                else
                {
                    while (true)
                    {
                        int bits5 = input.GetBits(8);
                        if (bits5 >= 0)
                        {
                            if (bits5 == 0)
                            {
                                goto label_57;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    return(false);

label_57:
                    this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingCRC16Part1;
                    goto case GZipDecoder.GzipHeaderState.ReadingCRC16Part1;
                }

            case GZipDecoder.GzipHeaderState.ReadingCRC16Part1:
                if ((this.gzip_header_flag & 2) == 0)
                {
                    this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.Done;
                    goto case GZipDecoder.GzipHeaderState.Done;
                }
                else
                {
                    if (input.GetBits(8) < 0)
                    {
                        return(false);
                    }
                    this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.ReadingCRC16Part2;
                    goto case GZipDecoder.GzipHeaderState.ReadingCRC16Part2;
                }

            case GZipDecoder.GzipHeaderState.ReadingCRC16Part2:
                if (input.GetBits(8) < 0)
                {
                    return(false);
                }
                this.gzipHeaderSubstate = GZipDecoder.GzipHeaderState.Done;
                goto case GZipDecoder.GzipHeaderState.Done;

            case GZipDecoder.GzipHeaderState.Done:
                return(true);

            default:
                Debug.Assert(false, "We should not reach unknown state!");
                throw new InvalidDataException(SR.GetString("Unknown state"));
            }
        }