コード例 #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");
     }
 }
コード例 #2
0
ファイル: InflaterDynHeader.cs プロジェクト: ouyh18/LteTools
        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[BL_ORDER[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;
        }
コード例 #3
0
ファイル: Inflater.cs プロジェクト: ouyh18/LteTools
        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;
        }
コード例 #4
0
ファイル: Inflater.cs プロジェクト: ouyh18/LteTools
        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();
        }
コード例 #5
0
ファイル: Inflater.cs プロジェクト: ouyh18/LteTools
 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();
 }