Beispiel #1
0
        internal int SetDictionary(byte[] dictionary)
        {
            int start = 0;
            int num   = dictionary.Length;

            if (this.mode != InflateManager.InflateManagerMode.DICT0)
            {
                throw new ZlibException("Stream error.");
            }
            int result;

            if (Adler.Adler32(1u, dictionary, 0, dictionary.Length) != this._codec._Adler32)
            {
                result = -3;
            }
            else
            {
                this._codec._Adler32 = Adler.Adler32(0u, null, 0, 0);
                if (num >= 1 << this.wbits)
                {
                    num   = (1 << this.wbits) - 1;
                    start = dictionary.Length - num;
                }
                this.blocks.SetDictionary(dictionary, start, num);
                this.mode = InflateManager.InflateManagerMode.BLOCKS;
                result    = 0;
            }
            return(result);
        }
Beispiel #2
0
 internal int Reset()
 {
     this._codec.TotalBytesIn = (this._codec.TotalBytesOut = 0L);
     this._codec.Message      = null;
     this.mode = ((!this.HandleRfc1950HeaderBytes) ? InflateManager.InflateManagerMode.BLOCKS : InflateManager.InflateManagerMode.METHOD);
     this.blocks.Reset();
     return(0);
 }
Beispiel #3
0
        internal int Reset()
        {
            this._codec.TotalBytesIn = this._codec.TotalBytesOut = 0L;
            this._codec.Message      = (string)null;
            this.mode = this.HandleRfc1950HeaderBytes ? InflateManager.InflateManagerMode.METHOD : InflateManager.InflateManagerMode.BLOCKS;
            int num = (int)this.blocks.Reset();

            return(0);
        }
Beispiel #4
0
        internal int Sync()
        {
            if (this.mode != InflateManager.InflateManagerMode.BAD)
            {
                this.mode   = InflateManager.InflateManagerMode.BAD;
                this.marker = 0;
            }
            int num;
            int result;

            if ((num = this._codec.AvailableBytesIn) == 0)
            {
                result = -5;
            }
            else
            {
                int num2 = this._codec.NextIn;
                int num3 = this.marker;
                while (num != 0 && num3 < 4)
                {
                    if (this._codec.InputBuffer[num2] == InflateManager.mark[num3])
                    {
                        num3++;
                    }
                    else if (this._codec.InputBuffer[num2] != 0)
                    {
                        num3 = 0;
                    }
                    else
                    {
                        num3 = 4 - num3;
                    }
                    num2++;
                    num--;
                }
                this._codec.TotalBytesIn    += (long)(num2 - this._codec.NextIn);
                this._codec.NextIn           = num2;
                this._codec.AvailableBytesIn = num;
                this.marker = num3;
                if (num3 != 4)
                {
                    result = -3;
                }
                else
                {
                    long totalBytesIn  = this._codec.TotalBytesIn;
                    long totalBytesOut = this._codec.TotalBytesOut;
                    this.Reset();
                    this._codec.TotalBytesIn  = totalBytesIn;
                    this._codec.TotalBytesOut = totalBytesOut;
                    this.mode = InflateManager.InflateManagerMode.BLOCKS;
                    result    = 0;
                }
            }
            return(result);
        }
Beispiel #5
0
        internal int Sync()
        {
            if (this.mode != InflateManager.InflateManagerMode.BAD)
            {
                this.mode   = InflateManager.InflateManagerMode.BAD;
                this.marker = 0;
            }
            int num1;

            if ((num1 = this._codec.AvailableBytesIn) == 0)
            {
                return(-5);
            }
            int index1 = this._codec.NextIn;
            int index2;

            for (index2 = this.marker; num1 != 0 && index2 < 4; --num1)
            {
                if ((int)this._codec.InputBuffer[index1] == (int)InflateManager.mark[index2])
                {
                    ++index2;
                }
                else
                {
                    index2 = (int)this._codec.InputBuffer[index1] == 0 ? 4 - index2 : 0;
                }
                ++index1;
            }
            this._codec.TotalBytesIn    += (long)(index1 - this._codec.NextIn);
            this._codec.NextIn           = index1;
            this._codec.AvailableBytesIn = num1;
            this.marker = index2;
            if (index2 != 4)
            {
                return(-3);
            }
            long num2 = this._codec.TotalBytesIn;
            long num3 = this._codec.TotalBytesOut;

            this.Reset();
            this._codec.TotalBytesIn  = num2;
            this._codec.TotalBytesOut = num3;
            this.mode = InflateManager.InflateManagerMode.BLOCKS;
            return(0);
        }
Beispiel #6
0
        internal int SetDictionary(byte[] dictionary)
        {
            int start = 0;
            int n     = dictionary.Length;

            if (this.mode != InflateManager.InflateManagerMode.DICT0)
            {
                throw new ZlibException("Stream error.");
            }
            if ((int)Adler.Adler32(1U, dictionary, 0, dictionary.Length) != (int)this._codec._Adler32)
            {
                return(-3);
            }
            this._codec._Adler32 = Adler.Adler32(0U, (byte[])null, 0, 0);
            if (n >= 1 << this.wbits)
            {
                n     = (1 << this.wbits) - 1;
                start = dictionary.Length - n;
            }
            this.blocks.SetDictionary(dictionary, start, n);
            this.mode = InflateManager.InflateManagerMode.BLOCKS;
            return(0);
        }
Beispiel #7
0
        internal int Inflate(FlushType flush)
        {
            if (this._codec.InputBuffer == null)
            {
                throw new ZlibException("InputBuffer is null. ");
            }
            int num1 = 0;
            int r    = -5;

            while (true)
            {
                switch (this.mode)
                {
                case InflateManager.InflateManagerMode.METHOD:
                    if (this._codec.AvailableBytesIn != 0)
                    {
                        r = num1;
                        --this._codec.AvailableBytesIn;
                        ++this._codec.TotalBytesIn;
                        if (((this.method = (int)this._codec.InputBuffer[this._codec.NextIn++]) & 15) != 8)
                        {
                            this.mode           = InflateManager.InflateManagerMode.BAD;
                            this._codec.Message = string.Format("unknown compression method (0x{0:X2})", (object)this.method);
                            this.marker         = 5;
                            break;
                        }
                        if ((this.method >> 4) + 8 > this.wbits)
                        {
                            this.mode           = InflateManager.InflateManagerMode.BAD;
                            this._codec.Message = string.Format("invalid window size ({0})", (object)((this.method >> 4) + 8));
                            this.marker         = 5;
                            break;
                        }
                        this.mode = InflateManager.InflateManagerMode.FLAG;
                        break;
                    }
                    goto label_4;

                case InflateManager.InflateManagerMode.FLAG:
                    if (this._codec.AvailableBytesIn != 0)
                    {
                        r = num1;
                        --this._codec.AvailableBytesIn;
                        ++this._codec.TotalBytesIn;
                        int num2 = (int)this._codec.InputBuffer[this._codec.NextIn++] & (int)byte.MaxValue;
                        if (((this.method << 8) + num2) % 31 != 0)
                        {
                            this.mode           = InflateManager.InflateManagerMode.BAD;
                            this._codec.Message = "incorrect header check";
                            this.marker         = 5;
                            break;
                        }
                        this.mode = (num2 & 32) == 0 ? InflateManager.InflateManagerMode.BLOCKS : InflateManager.InflateManagerMode.DICT4;
                        break;
                    }
                    goto label_11;

                case InflateManager.InflateManagerMode.DICT4:
                    if (this._codec.AvailableBytesIn != 0)
                    {
                        r = num1;
                        --this._codec.AvailableBytesIn;
                        ++this._codec.TotalBytesIn;
                        this.expectedCheck = (uint)((ulong)((int)this._codec.InputBuffer[this._codec.NextIn++] << 24) & 4278190080UL);
                        this.mode          = InflateManager.InflateManagerMode.DICT3;
                        break;
                    }
                    goto label_16;

                case InflateManager.InflateManagerMode.DICT3:
                    if (this._codec.AvailableBytesIn != 0)
                    {
                        r = num1;
                        --this._codec.AvailableBytesIn;
                        ++this._codec.TotalBytesIn;
                        this.expectedCheck += (uint)((int)this._codec.InputBuffer[this._codec.NextIn++] << 16 & 16711680);
                        this.mode           = InflateManager.InflateManagerMode.DICT2;
                        break;
                    }
                    goto label_19;

                case InflateManager.InflateManagerMode.DICT2:
                    if (this._codec.AvailableBytesIn != 0)
                    {
                        r = num1;
                        --this._codec.AvailableBytesIn;
                        ++this._codec.TotalBytesIn;
                        this.expectedCheck += (uint)((int)this._codec.InputBuffer[this._codec.NextIn++] << 8 & 65280);
                        this.mode           = InflateManager.InflateManagerMode.DICT1;
                        break;
                    }
                    goto label_22;

                case InflateManager.InflateManagerMode.DICT1:
                    goto label_24;

                case InflateManager.InflateManagerMode.DICT0:
                    goto label_27;

                case InflateManager.InflateManagerMode.BLOCKS:
                    r = this.blocks.Process(r);
                    if (r == -3)
                    {
                        this.mode   = InflateManager.InflateManagerMode.BAD;
                        this.marker = 0;
                        break;
                    }
                    if (r == 0)
                    {
                        r = num1;
                    }
                    if (r == 1)
                    {
                        r = num1;
                        this.computedCheck = this.blocks.Reset();
                        if (this.HandleRfc1950HeaderBytes)
                        {
                            this.mode = InflateManager.InflateManagerMode.CHECK4;
                            break;
                        }
                        goto label_35;
                    }
                    else
                    {
                        goto label_33;
                    }

                case InflateManager.InflateManagerMode.CHECK4:
                    if (this._codec.AvailableBytesIn != 0)
                    {
                        r = num1;
                        --this._codec.AvailableBytesIn;
                        ++this._codec.TotalBytesIn;
                        this.expectedCheck = (uint)((ulong)((int)this._codec.InputBuffer[this._codec.NextIn++] << 24) & 4278190080UL);
                        this.mode          = InflateManager.InflateManagerMode.CHECK3;
                        break;
                    }
                    goto label_38;

                case InflateManager.InflateManagerMode.CHECK3:
                    if (this._codec.AvailableBytesIn != 0)
                    {
                        r = num1;
                        --this._codec.AvailableBytesIn;
                        ++this._codec.TotalBytesIn;
                        this.expectedCheck += (uint)((int)this._codec.InputBuffer[this._codec.NextIn++] << 16 & 16711680);
                        this.mode           = InflateManager.InflateManagerMode.CHECK2;
                        break;
                    }
                    goto label_41;

                case InflateManager.InflateManagerMode.CHECK2:
                    if (this._codec.AvailableBytesIn != 0)
                    {
                        r = num1;
                        --this._codec.AvailableBytesIn;
                        ++this._codec.TotalBytesIn;
                        this.expectedCheck += (uint)((int)this._codec.InputBuffer[this._codec.NextIn++] << 8 & 65280);
                        this.mode           = InflateManager.InflateManagerMode.CHECK1;
                        break;
                    }
                    goto label_44;

                case InflateManager.InflateManagerMode.CHECK1:
                    if (this._codec.AvailableBytesIn != 0)
                    {
                        r = num1;
                        --this._codec.AvailableBytesIn;
                        ++this._codec.TotalBytesIn;
                        this.expectedCheck += (uint)this._codec.InputBuffer[this._codec.NextIn++] & (uint)byte.MaxValue;
                        if ((int)this.computedCheck != (int)this.expectedCheck)
                        {
                            this.mode           = InflateManager.InflateManagerMode.BAD;
                            this._codec.Message = "incorrect data check";
                            this.marker         = 5;
                            break;
                        }
                        goto label_50;
                    }
                    else
                    {
                        goto label_47;
                    }

                case InflateManager.InflateManagerMode.DONE:
                    goto label_51;

                case InflateManager.InflateManagerMode.BAD:
                    goto label_52;

                default:
                    goto label_53;
                }
            }
label_4:
            return(r);

label_11:
            return(r);

label_16:
            return(r);

label_19:
            return(r);

label_22:
            return(r);

label_24:
            if (this._codec.AvailableBytesIn == 0)
            {
                return(r);
            }
            --this._codec.AvailableBytesIn;
            ++this._codec.TotalBytesIn;
            this.expectedCheck  += (uint)this._codec.InputBuffer[this._codec.NextIn++] & (uint)byte.MaxValue;
            this._codec._Adler32 = this.expectedCheck;
            this.mode            = InflateManager.InflateManagerMode.DICT0;
            return(2);

label_27:
            this.mode           = InflateManager.InflateManagerMode.BAD;
            this._codec.Message = "need dictionary";
            this.marker         = 0;
            return(-2);

label_33:
            return(r);

label_35:
            this.mode = InflateManager.InflateManagerMode.DONE;
            return(1);

label_38:
            return(r);

label_41:
            return(r);

label_44:
            return(r);

label_47:
            return(r);

label_50:
            this.mode = InflateManager.InflateManagerMode.DONE;
            return(1);

label_51:
            return(1);

label_52:
            throw new ZlibException(string.Format("Bad state ({0})", (object)this._codec.Message));
label_53:
            throw new ZlibException("Stream error.");
        }
Beispiel #8
0
        internal int Inflate(FlushType flush)
        {
            if (this._codec.InputBuffer == null)
            {
                throw new ZlibException("InputBuffer is null. ");
            }
            int num  = 0;
            int num2 = -5;

            while (true)
            {
                switch (this.mode)
                {
                case InflateManager.InflateManagerMode.METHOD:
                    if (this._codec.AvailableBytesIn == 0)
                    {
                        return(num2);
                    }
                    num2 = num;
                    this._codec.AvailableBytesIn--;
                    this._codec.TotalBytesIn += 1L;
                    if (((this.method = (int)this._codec.InputBuffer[this._codec.NextIn++]) & 15) != 8)
                    {
                        this.mode           = InflateManager.InflateManagerMode.BAD;
                        this._codec.Message = string.Format("unknown compression method (0x{0:X2})", this.method);
                        this.marker         = 5;
                        continue;
                    }
                    if ((this.method >> 4) + 8 > this.wbits)
                    {
                        this.mode           = InflateManager.InflateManagerMode.BAD;
                        this._codec.Message = string.Format("invalid window size ({0})", (this.method >> 4) + 8);
                        this.marker         = 5;
                        continue;
                    }
                    this.mode = InflateManager.InflateManagerMode.FLAG;
                    continue;

                case InflateManager.InflateManagerMode.FLAG:
                {
                    if (this._codec.AvailableBytesIn == 0)
                    {
                        return(num2);
                    }
                    num2 = num;
                    this._codec.AvailableBytesIn--;
                    this._codec.TotalBytesIn += 1L;
                    int num3 = (int)(this._codec.InputBuffer[this._codec.NextIn++] & 255);
                    if (((this.method << 8) + num3) % 31 != 0)
                    {
                        this.mode           = InflateManager.InflateManagerMode.BAD;
                        this._codec.Message = "incorrect header check";
                        this.marker         = 5;
                        continue;
                    }
                    this.mode = (((num3 & 32) != 0) ? InflateManager.InflateManagerMode.DICT4 : InflateManager.InflateManagerMode.BLOCKS);
                    continue;
                }

                case InflateManager.InflateManagerMode.DICT4:
                    if (this._codec.AvailableBytesIn == 0)
                    {
                        return(num2);
                    }
                    num2 = num;
                    this._codec.AvailableBytesIn--;
                    this._codec.TotalBytesIn += 1L;
                    this.expectedCheck        = (uint)((long)((long)this._codec.InputBuffer[this._codec.NextIn++] << 24) & (long)((ulong)-16777216));
                    this.mode = InflateManager.InflateManagerMode.DICT3;
                    continue;

                case InflateManager.InflateManagerMode.DICT3:
                    if (this._codec.AvailableBytesIn == 0)
                    {
                        return(num2);
                    }
                    num2 = num;
                    this._codec.AvailableBytesIn--;
                    this._codec.TotalBytesIn += 1L;
                    this.expectedCheck       += (uint)((int)this._codec.InputBuffer[this._codec.NextIn++] << 16 & 16711680);
                    this.mode = InflateManager.InflateManagerMode.DICT2;
                    continue;

                case InflateManager.InflateManagerMode.DICT2:
                    if (this._codec.AvailableBytesIn == 0)
                    {
                        return(num2);
                    }
                    num2 = num;
                    this._codec.AvailableBytesIn--;
                    this._codec.TotalBytesIn += 1L;
                    this.expectedCheck       += (uint)((int)this._codec.InputBuffer[this._codec.NextIn++] << 8 & 65280);
                    this.mode = InflateManager.InflateManagerMode.DICT1;
                    continue;

                case InflateManager.InflateManagerMode.DICT1:
                    goto IL_39F;

                case InflateManager.InflateManagerMode.DICT0:
                    goto IL_42B;

                case InflateManager.InflateManagerMode.BLOCKS:
                    num2 = this.blocks.Process(num2);
                    if (num2 == -3)
                    {
                        this.mode   = InflateManager.InflateManagerMode.BAD;
                        this.marker = 0;
                        continue;
                    }
                    if (num2 == 0)
                    {
                        num2 = num;
                    }
                    if (num2 != 1)
                    {
                        return(num2);
                    }
                    num2 = num;
                    this.computedCheck = this.blocks.Reset();
                    if (!this.HandleRfc1950HeaderBytes)
                    {
                        goto Block_16;
                    }
                    this.mode = InflateManager.InflateManagerMode.CHECK4;
                    continue;

                case InflateManager.InflateManagerMode.CHECK4:
                    if (this._codec.AvailableBytesIn == 0)
                    {
                        return(num2);
                    }
                    num2 = num;
                    this._codec.AvailableBytesIn--;
                    this._codec.TotalBytesIn += 1L;
                    this.expectedCheck        = (uint)((long)((long)this._codec.InputBuffer[this._codec.NextIn++] << 24) & (long)((ulong)-16777216));
                    this.mode = InflateManager.InflateManagerMode.CHECK3;
                    continue;

                case InflateManager.InflateManagerMode.CHECK3:
                    if (this._codec.AvailableBytesIn == 0)
                    {
                        return(num2);
                    }
                    num2 = num;
                    this._codec.AvailableBytesIn--;
                    this._codec.TotalBytesIn += 1L;
                    this.expectedCheck       += (uint)((int)this._codec.InputBuffer[this._codec.NextIn++] << 16 & 16711680);
                    this.mode = InflateManager.InflateManagerMode.CHECK2;
                    continue;

                case InflateManager.InflateManagerMode.CHECK2:
                    if (this._codec.AvailableBytesIn == 0)
                    {
                        return(num2);
                    }
                    num2 = num;
                    this._codec.AvailableBytesIn--;
                    this._codec.TotalBytesIn += 1L;
                    this.expectedCheck       += (uint)((int)this._codec.InputBuffer[this._codec.NextIn++] << 8 & 65280);
                    this.mode = InflateManager.InflateManagerMode.CHECK1;
                    continue;

                case InflateManager.InflateManagerMode.CHECK1:
                    if (this._codec.AvailableBytesIn == 0)
                    {
                        return(num2);
                    }
                    num2 = num;
                    this._codec.AvailableBytesIn--;
                    this._codec.TotalBytesIn += 1L;
                    this.expectedCheck       += (uint)(this._codec.InputBuffer[this._codec.NextIn++] & 255);
                    if (this.computedCheck != this.expectedCheck)
                    {
                        this.mode           = InflateManager.InflateManagerMode.BAD;
                        this._codec.Message = "incorrect data check";
                        this.marker         = 5;
                        continue;
                    }
                    goto IL_6E3;

                case InflateManager.InflateManagerMode.DONE:
                    return(1);

                case InflateManager.InflateManagerMode.BAD:
                    goto IL_6EF;
                }
                break;
            }
            throw new ZlibException("Stream error.");
IL_39F:
            if (this._codec.AvailableBytesIn == 0)
            {
                return(num2);
            }
            this._codec.AvailableBytesIn--;
            this._codec.TotalBytesIn += 1L;
            this.expectedCheck       += (uint)(this._codec.InputBuffer[this._codec.NextIn++] & 255);
            this._codec._Adler32      = this.expectedCheck;
            this.mode = InflateManager.InflateManagerMode.DICT0;
            return(2);

IL_42B:
            this.mode           = InflateManager.InflateManagerMode.BAD;
            this._codec.Message = "need dictionary";
            this.marker         = 0;
            return(-2);

Block_16:
            this.mode = InflateManager.InflateManagerMode.DONE;
            return(1);

IL_6E3:
            this.mode = InflateManager.InflateManagerMode.DONE;
            return(1);

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