Example #1
0
        public int EndInflate()
        {
            if (this.istate == null)
            {
                throw new ZlibException("No Inflate State!");
            }
            int num = this.istate.End();

            this.istate = null;
            return(num);
        }
Example #2
0
        internal int Inflate(FlushType flush)
        {
            int num = (int)flush;

            if (this._codec.InputBuffer == null)
            {
                throw new ZlibException("InputBuffer is null. ");
            }
            int num2 = (num == 4) ? -5 : 0;
            int r    = -5;

Label_0027:
            switch (this.mode)
            {
            case 0:
            {
                int num6;
                if (this._codec.AvailableBytesIn == 0)
                {
                    return(r);
                }
                r = num2;
                this._codec.AvailableBytesIn--;
                this._codec.TotalBytesIn += 1L;
                InflateManager manager     = this;
                byte[]         inputBuffer = this._codec.InputBuffer;
                int            index       = this._codec.NextIn++;
                manager.method = num6 = inputBuffer[index];
                if ((num6 & 15) == 8)
                {
                    if (((this.method >> 4) + 8) > this.wbits)
                    {
                        this.mode           = 13;
                        this._codec.Message = string.Format("invalid window size ({0})", (this.method >> 4) + 8);
                        this.marker         = 5;
                        goto Label_0027;
                    }
                    this.mode = 1;
                    break;
                }
                this.mode           = 13;
                this._codec.Message = string.Format("unknown compression method (0x{0:X2})", this.method);
                this.marker         = 5;
                goto Label_0027;
            }

            case 1:
                break;

            case 2:
                goto Label_04BA;

            case 3:
                goto Label_0533;

            case 4:
                goto Label_05B4;

            case 5:
                goto Label_0634;

            case 6:
                this.mode           = 13;
                this._codec.Message = "need dictionary";
                this.marker         = 0;
                return(-2);

            case 7:
                r = this.blocks.Process(r);
                if (r != -3)
                {
                    if (r == 0)
                    {
                        r = num2;
                    }
                    if (r != 1)
                    {
                        return(r);
                    }
                    r = num2;
                    this.blocks.Reset(this.was);
                    if (!this.HandleRfc1950HeaderBytes)
                    {
                        this.mode = 12;
                        goto Label_0027;
                    }
                    this.mode = 8;
                    goto Label_0284;
                }
                this.mode   = 13;
                this.marker = 0;
                goto Label_0027;

            case 8:
                goto Label_0284;

            case 9:
                goto Label_02FF;

            case 10:
                goto Label_0382;

            case 11:
                goto Label_0404;

            case 12:
                goto Label_06F1;

            case 13:
                throw new ZlibException(string.Format("Bad state ({0})", this._codec.Message));

            default:
                throw new ZlibException("Stream error.");
            }
            if (this._codec.AvailableBytesIn == 0)
            {
                return(r);
            }
            r = num2;
            this._codec.AvailableBytesIn--;
            this._codec.TotalBytesIn += 1L;
            int num7 = this._codec.InputBuffer[this._codec.NextIn++] & 0xff;

            if ((((this.method << 8) + num7) % 0x1f) != 0)
            {
                this.mode           = 13;
                this._codec.Message = "incorrect header check";
                this.marker         = 5;
            }
            else
            {
                if ((num7 & 0x20) != 0)
                {
                    this.mode = 2;
                    goto Label_04BA;
                }
                this.mode = 7;
            }
            goto Label_0027;
Label_0284:
            if (this._codec.AvailableBytesIn == 0)
            {
                return(r);
            }
            r = num2;
            this._codec.AvailableBytesIn--;
            this._codec.TotalBytesIn += 1L;
            this.need = ((this._codec.InputBuffer[this._codec.NextIn++] & 0xff) << 0x18) & -16777216;
            this.mode = 9;
Label_02FF:
            if (this._codec.AvailableBytesIn == 0)
            {
                return(r);
            }
            r = num2;
            this._codec.AvailableBytesIn--;
            this._codec.TotalBytesIn += 1L;
            this.need += ((this._codec.InputBuffer[this._codec.NextIn++] & 0xff) << 0x10) & 0xff0000L;
            this.mode  = 10;
Label_0382:
            if (this._codec.AvailableBytesIn == 0)
            {
                return(r);
            }
            r = num2;
            this._codec.AvailableBytesIn--;
            this._codec.TotalBytesIn += 1L;
            this.need += ((this._codec.InputBuffer[this._codec.NextIn++] & 0xff) << 8) & 0xff00L;
            this.mode  = 11;
Label_0404:
            if (this._codec.AvailableBytesIn == 0)
            {
                return(r);
            }
            r = num2;
            this._codec.AvailableBytesIn--;
            this._codec.TotalBytesIn += 1L;
            this.need += this._codec.InputBuffer[this._codec.NextIn++] & 0xffL;
            if (((int)this.was[0]) == ((int)this.need))
            {
                this.mode = 12;
                goto Label_06F1;
            }
            this.mode           = 13;
            this._codec.Message = "incorrect data check";
            this.marker         = 5;
            goto Label_0027;
Label_04BA:
            if (this._codec.AvailableBytesIn == 0)
            {
                return(r);
            }
            r = num2;
            this._codec.AvailableBytesIn--;
            this._codec.TotalBytesIn += 1L;
            this.need = ((this._codec.InputBuffer[this._codec.NextIn++] & 0xff) << 0x18) & -16777216;
            this.mode = 3;
Label_0533:
            if (this._codec.AvailableBytesIn == 0)
            {
                return(r);
            }
            r = num2;
            this._codec.AvailableBytesIn--;
            this._codec.TotalBytesIn += 1L;
            this.need += ((this._codec.InputBuffer[this._codec.NextIn++] & 0xff) << 0x10) & 0xff0000L;
            this.mode  = 4;
Label_05B4:
            if (this._codec.AvailableBytesIn == 0)
            {
                return(r);
            }
            r = num2;
            this._codec.AvailableBytesIn--;
            this._codec.TotalBytesIn += 1L;
            this.need += ((this._codec.InputBuffer[this._codec.NextIn++] & 0xff) << 8) & 0xff00L;
            this.mode  = 5;
Label_0634:
            if (this._codec.AvailableBytesIn == 0)
            {
                return(r);
            }
            this._codec.AvailableBytesIn--;
            this._codec.TotalBytesIn += 1L;
            this.need           += this._codec.InputBuffer[this._codec.NextIn++] & 0xffL;
            this._codec._Adler32 = this.need;
            this.mode            = 6;
            return(2);

Label_06F1:
            return(1);
        }
Example #3
0
 public int InitializeInflate(int windowBits, bool expectRfc1950Header)
 {
     this.WindowBits = windowBits;
     this.istate     = new InflateManager(expectRfc1950Header);
     return(this.istate.Initialize(this, windowBits));
 }