Exemplo n.º 1
0
 static InflaterHuffmanTree()
 {
     try
     {
         byte[] codeLengths = new byte[0x120];
         int num = 0;
         while (num < 0x90)
         {
             codeLengths[num++] = 8;
         }
         while (num < 0x100)
         {
             codeLengths[num++] = 9;
         }
         while (num < 280)
         {
             codeLengths[num++] = 7;
         }
         while (num < 0x120)
         {
             codeLengths[num++] = 8;
         }
         DefLitLenTree = new InflaterHuffmanTree(codeLengths);
         codeLengths = new byte[0x20];
         num = 0;
         while (num < 0x20)
         {
             codeLengths[num++] = 5;
         }
         DefDistTree = new InflaterHuffmanTree(codeLengths);
     }
     catch (Exception)
     {
         throw new SharpZipBaseException("InflaterHuffmanTree: static tree length illegal");
     }
 }
Exemplo n.º 2
0
        private bool Decode()
        {
            int num2;
            int num3;
            switch (mode)
            {
                case 0:
                    return DecodeHeader();

                case 1:
                    return DecodeDict();

                case 2:
                    if (!isLastBlock)
                    {
                        int num = input.PeekBits(3);
                        if (num < 0)
                        {
                            return false;
                        }
                        input.DropBits(3);
                        if ((num & 1) != 0)
                        {
                            isLastBlock = true;
                        }
                        switch ((num >> 1))
                        {
                            case 0:
                                input.SkipToByteBoundary();
                                mode = 3;
                                goto Label_0134;

                            case 1:
                                litlenTree = InflaterHuffmanTree.DefLitLenTree;
                                distTree = InflaterHuffmanTree.DefDistTree;
                                mode = 7;
                                goto Label_0134;

                            case 2:
                                dynHeader = new InflaterDynHeader();
                                mode = 6;
                                goto Label_0134;
                        }
                        throw new SharpZipBaseException("Unknown block type " + num);
                    }
                    if (!noHeader)
                    {
                        input.SkipToByteBoundary();
                        neededBits = 0x20;
                        mode = DECODE_CHKSUM;
                        return true;
                    }
                    mode = FINISHED;
                    return false;

                case 3:
                    uncomprLen = input.PeekBits(0x10);
                    if (uncomprLen >= 0)
                    {
                        input.DropBits(0x10);
                        mode = 4;
                        goto Label_0167;
                    }
                    return false;

                case 4:
                    goto Label_0167;

                case 5:
                    goto Label_01A9;

                case 6:
                    if (dynHeader.Decode(input))
                    {
                        litlenTree = dynHeader.BuildLitLenTree();
                        distTree = dynHeader.BuildDistTree();
                        mode = 7;
                        goto Label_022D;
                    }
                    return false;

                case 7:
                case 8:
                case 9:
                case 10:
                    goto Label_022D;

                case DECODE_CHKSUM:
                    return DecodeChksum();

                case FINISHED:
                    return false;

                default:
                    throw new SharpZipBaseException("Inflater.Decode unknown mode");
            }
        Label_0134:
            return true;
        Label_0167:
            num2 = input.PeekBits(0x10);
            if (num2 < 0)
            {
                return false;
            }
            input.DropBits(0x10);
            if (num2 != (uncomprLen ^ 0xffff))
            {
                throw new SharpZipBaseException("broken uncompressed block");
            }
            mode = 5;
        Label_01A9:
            num3 = outputWindow.CopyStored(input, uncomprLen);
            uncomprLen -= num3;
            if (uncomprLen == 0)
            {
                mode = 2;
                return true;
            }
            return !input.IsNeedingInput;
        Label_022D:
            return DecodeHuffman();
        }
Exemplo n.º 3
0
 public void Reset()
 {
     mode = noHeader ? 2 : 0;
     totalIn = 0L;
     totalOut = 0L;
     input.Reset();
     outputWindow.Reset();
     dynHeader = null;
     litlenTree = null;
     distTree = null;
     isLastBlock = false;
     adler.Reset();
 }
Exemplo n.º 4
0
        private bool DecodeHuffman()
        {
            int freeSpace = outputWindow.GetFreeSpace();
            while (freeSpace >= 0x102)
            {
                int num2;
                switch (mode)
                {
                    case 7:
                        goto Label_0051;

                    case 8:
                        goto Label_00C5;

                    case 9:
                        goto Label_0114;

                    case DECODE_HUFFMAN_DISTBITS:
                        goto Label_0154;

                    default:
                        throw new SharpZipBaseException("Inflater unknown mode");
                }
            Label_0037:
                outputWindow.Write(num2);
                if (--freeSpace < 0x102)
                {
                    return true;
                }
            Label_0051:
                if (((num2 = litlenTree.GetSymbol(input)) & -256) == 0)
                {
                    goto Label_0037;
                }
                if (num2 < 0x101)
                {
                    if (num2 < 0)
                    {
                        return false;
                    }
                    distTree = null;
                    litlenTree = null;
                    mode = 2;
                    return true;
                }
                try
                {
                    repLength = CPLENS[num2 - 0x101];
                    neededBits = CPLEXT[num2 - 0x101];
                }
                catch (Exception)
                {
                    throw new SharpZipBaseException("Illegal rep length code");
                }
            Label_00C5:
                if (neededBits > 0)
                {
                    mode = 8;
                    int num3 = input.PeekBits(neededBits);
                    if (num3 < 0)
                    {
                        return false;
                    }
                    input.DropBits(neededBits);
                    repLength += num3;
                }
                mode = 9;
            Label_0114:
                num2 = distTree.GetSymbol(input);
                if (num2 < 0)
                {
                    return false;
                }
                try
                {
                    repDist = CPDIST[num2];
                    neededBits = CPDEXT[num2];
                }
                catch (Exception)
                {
                    throw new SharpZipBaseException("Illegal rep dist code");
                }
            Label_0154:
                if (neededBits > 0)
                {
                    mode = DECODE_HUFFMAN_DISTBITS;
                    int num4 = input.PeekBits(neededBits);
                    if (num4 < 0)
                    {
                        return false;
                    }
                    input.DropBits(neededBits);
                    repDist += num4;
                }
                outputWindow.Repeat(repLength, repDist);
                freeSpace -= repLength;
                mode = 7;
            }
            return true;
        }
Exemplo n.º 5
0
        public bool Decode(StreamManipulator input)
        {
            int num2;
            int num3;
        Label_0000:
            switch (this._mode)
            {
                case 0:
                    this._lnum = input.PeekBits(Reps);
                    if (this._lnum >= 0)
                    {
                        this._lnum += 0x101;
                        input.DropBits(Reps);
                        this._mode = 1;
                        break;
                    }
                    return false;

                case 1:
                    break;

                case 2:
                    goto Label_00B9;

                case 3:
                    goto Label_013B;

                case Lens:
                    goto Label_01A8;

                case Reps:
                    goto Label_01EE;

                default:
                    goto Label_0000;
            }
        _dnum = input.PeekBits(Reps);
            if (_dnum < 0)
            {
                return false;
            }
            _dnum++;
            input.DropBits(Reps);
            this._num = _lnum + _dnum;
            _litdistLens = new byte[this._num];
            _mode = 2;
        Label_00B9:
            this._blnum = input.PeekBits(4);
            if (this._blnum < 0)
            {
                return false;
            }
            _blnum += Lens;
            input.DropBits(Lens);
            _blLens = new byte[0x13];
            this._ptr = 0;
            this._mode = 3;
        Label_013B:
            while (this._ptr < this._blnum)
            {
                int num = input.PeekBits(3);
                if (num < 0)
                {
                    return false;
                }
                input.DropBits(3);
                this._blLens[BlOrder[this._ptr]] = (byte)num;
                this._ptr++;
            }
            this._blTree = new InflaterHuffmanTree(this._blLens);
            this._blLens = null;
            this._ptr = 0;
            this._mode = Lens;
        Label_01A8:
            while (((num2 = this._blTree.GetSymbol(input)) & -16) == 0)
            {
                this._litdistLens[this._ptr++] = this._lastLen = (byte)num2;
                if (this._ptr == this._num)
                {
                    return true;
                }
            }
            if (num2 < 0)
            {
                return false;
            }
            if (num2 >= 0x11)
            {
                this._lastLen = 0;
            }
            else if (_ptr == 0)
            {
                throw new SharpZipBaseException();
            }
            _repSymbol = num2 - 0x10;
            _mode = Reps;
        Label_01EE:
            num3 = RepBits[_repSymbol];
            int num4 = input.PeekBits(num3);
            if (num4 < 0)
            {
                return false;
            }
            input.DropBits(num3);
            num4 += RepMin[_repSymbol];
            if ((_ptr + num4) > this._num)
            {
                throw new SharpZipBaseException();
            }
            while (num4-- > 0)
            {
                _litdistLens[_ptr++] = _lastLen;
            }
            if (this._ptr == this._num)
            {
                return true;
            }
            this._mode = Lens;
            goto Label_0000;
        }