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
        public bool Decode(StreamManipulator input)
        {
            int num2;
            int num3;
            bool flag2;
            goto Label_034E;
        Label_007E:
            this.dnum = input.PeekBits(5);
            if (this.dnum < 0)
            {
                return false;
            }
            this.dnum++;
            input.DropBits(5);
            this.num = this.lnum + this.dnum;
            this.litdistLens = new byte[this.num];
            this.mode = 2;
        Label_00E9:
            this.blnum = input.PeekBits(4);
            if (this.blnum < 0)
            {
                return false;
            }
            this.blnum += 4;
            input.DropBits(4);
            this.blLens = new byte[0x13];
            this.ptr = 0;
            this.mode = 3;
        Label_0191:
            while (this.ptr < this.blnum)
            {
                int num = input.PeekBits(3);
                if (num < 0)
                {
                    return false;
                }
                input.DropBits(3);
                this.blLens[BL_ORDER[this.ptr]] = (byte) num;
                this.ptr++;
            }
            this.blTree = new InflaterHuffmanTree(this.blLens);
            this.blLens = null;
            this.ptr = 0;
            this.mode = 4;
        Label_0219:
            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 (this.ptr == 0)
            {
                throw new SharpZipBaseException();
            }
            this.repSymbol = num2 - 0x10;
            this.mode = 5;
        Label_028E:
            num3 = repBits[this.repSymbol];
            int num4 = input.PeekBits(num3);
            if (num4 < 0)
            {
                return false;
            }
            input.DropBits(num3);
            num4 += repMin[this.repSymbol];
            if ((this.ptr + num4) > this.num)
            {
                throw new SharpZipBaseException();
            }
            while (num4-- > 0)
            {
                this.litdistLens[this.ptr++] = this.lastLen;
            }
            if (this.ptr == this.num)
            {
                return true;
            }
            this.mode = 4;
        Label_034E:
            flag2 = true;
            switch (this.mode)
            {
                case 0:
                    this.lnum = input.PeekBits(5);
                    if (this.lnum >= 0)
                    {
                        this.lnum += 0x101;
                        input.DropBits(5);
                        this.mode = 1;
                        goto Label_007E;
                    }
                    return false;

                case 1:
                    goto Label_007E;

                case 2:
                    goto Label_00E9;

                case 3:
                    goto Label_0191;

                case 4:
                    goto Label_0219;

                case 5:
                    goto Label_028E;
            }
            goto Label_034E;
        }
Exemplo n.º 3
0
 public void Reset()
 {
     this.mode = this.noHeader ? 2 : 0;
     this.totalIn = 0L;
     this.totalOut = 0L;
     this.input.Reset();
     this.outputWindow.Reset();
     this.dynHeader = null;
     this.litlenTree = null;
     this.distTree = null;
     this.isLastBlock = false;
     this.adler.Reset();
 }
Exemplo n.º 4
0
        private bool Decode()
        {
            int num2;
            int num3;
            switch (this.mode)
            {
                case 0:
                    return this.DecodeHeader();

                case 1:
                    return this.DecodeDict();

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

                            case 1:
                                this.litlenTree = InflaterHuffmanTree.defLitLenTree;
                                this.distTree = InflaterHuffmanTree.defDistTree;
                                this.mode = 7;
                                break;

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

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

                case 4:
                    goto Label_01C8;

                case 5:
                    goto Label_0225;

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

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

                case 11:
                    return this.DecodeChksum();

                case 12:
                    return false;

                default:
                    throw new SharpZipBaseException("Inflater.Decode unknown mode");
            }
            return true;
        Label_01C8:
            num2 = this.input.PeekBits(0x10);
            if (num2 < 0)
            {
                return false;
            }
            this.input.DropBits(0x10);
            if (num2 != (this.uncomprLen ^ 0xffff))
            {
                throw new SharpZipBaseException("broken uncompressed block");
            }
            this.mode = 5;
        Label_0225:
            num3 = this.outputWindow.CopyStored(this.input, this.uncomprLen);
            this.uncomprLen -= num3;
            if (this.uncomprLen == 0)
            {
                this.mode = 2;
                return true;
            }
            return !this.input.IsNeedingInput;
        Label_02C2:
            return this.DecodeHuffman();
        }
Exemplo n.º 5
0
        private bool DecodeHuffman()
        {
            int freeSpace = this.outputWindow.GetFreeSpace();
            while (freeSpace >= 0x102)
            {
                int num2;
                int num3;
                switch (this.mode)
                {
                    case 7:
                        goto Label_0067;

                    case 8:
                        goto Label_0107;

                    case 9:
                        goto Label_0173;

                    case 10:
                        goto Label_01C8;

                    default:
                        throw new SharpZipBaseException("Inflater unknown mode");
                }
            Label_003B:
                this.outputWindow.Write(num2);
                if (--freeSpace < 0x102)
                {
                    return true;
                }
            Label_0067:
                if (((num2 = this.litlenTree.GetSymbol(this.input)) & -256) == 0)
                {
                    goto Label_003B;
                }
                if (num2 < 0x101)
                {
                    if (num2 < 0)
                    {
                        return false;
                    }
                    this.distTree = null;
                    this.litlenTree = null;
                    this.mode = 2;
                    return true;
                }
                try
                {
                    this.repLength = CPLENS[num2 - 0x101];
                    this.neededBits = CPLEXT[num2 - 0x101];
                }
                catch (Exception)
                {
                    throw new SharpZipBaseException("Illegal rep length code");
                }
            Label_0107:
                if (this.neededBits > 0)
                {
                    this.mode = 8;
                    num3 = this.input.PeekBits(this.neededBits);
                    if (num3 < 0)
                    {
                        return false;
                    }
                    this.input.DropBits(this.neededBits);
                    this.repLength += num3;
                }
                this.mode = 9;
            Label_0173:
                num2 = this.distTree.GetSymbol(this.input);
                if (num2 < 0)
                {
                    return false;
                }
                try
                {
                    this.repDist = CPDIST[num2];
                    this.neededBits = CPDEXT[num2];
                }
                catch (Exception)
                {
                    throw new SharpZipBaseException("Illegal rep dist code");
                }
            Label_01C8:
                if (this.neededBits > 0)
                {
                    this.mode = 10;
                    num3 = this.input.PeekBits(this.neededBits);
                    if (num3 < 0)
                    {
                        return false;
                    }
                    this.input.DropBits(this.neededBits);
                    this.repDist += num3;
                }
                this.outputWindow.Repeat(this.repLength, this.repDist);
                freeSpace -= this.repLength;
                this.mode = 7;
            }
            return true;
        }