public LzmaStream(LzmaEncoderProperties properties, bool isLZMA2, Stream presetDictionary, Stream outputStream)
        {
            this.outWindow         = new OutWindow();
            this.rangeDecoder      = new SharpCompress.Compressor.LZMA.RangeCoder.Decoder();
            this.position          = 0L;
            this.endReached        = false;
            this.inputPosition     = 0L;
            this.uncompressedChunk = false;
            this.needDictReset     = true;
            this.needProps         = true;
            this.props             = new byte[5];
            this.isLZMA2           = isLZMA2;
            this.availableBytes    = 0L;
            this.endReached        = true;
            if (isLZMA2)
            {
                throw new NotImplementedException();
            }
            this.encoder = new SharpCompress.Compressor.LZMA.Encoder();
            this.encoder.SetCoderProperties(properties.propIDs, properties.properties);
            MemoryStream outStream = new MemoryStream(5);

            this.encoder.WriteCoderProperties(outStream);
            this.props = outStream.ToArray();
            this.encoder.SetStreams(null, outputStream, -1L, -1L);
            if (presetDictionary != null)
            {
                this.encoder.Train(presetDictionary);
            }
        }
Exemple #2
0
 public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress)
 {
     if (this.m_OutWindow == null)
     {
         this.CreateDictionary();
     }
     this.m_OutWindow.Init(outStream);
     if (outSize > 0L)
     {
         this.m_OutWindow.SetLimit(outSize);
     }
     else
     {
         this.m_OutWindow.SetLimit(0x7fffffffffffffffL - this.m_OutWindow.Total);
     }
     SharpCompress.Compressor.LZMA.RangeCoder.Decoder rangeDecoder = new SharpCompress.Compressor.LZMA.RangeCoder.Decoder();
     rangeDecoder.Init(inStream);
     this.Code(this.m_DictionarySize, this.m_OutWindow, rangeDecoder);
     this.m_OutWindow.ReleaseStream();
     rangeDecoder.ReleaseStream();
     if (!(rangeDecoder.IsFinished && ((inSize <= 0L) || (rangeDecoder.Total == inSize))))
     {
         throw new DataErrorException();
     }
     if (this.m_OutWindow.HasPending)
     {
         throw new DataErrorException();
     }
     this.m_OutWindow = null;
 }
Exemple #3
0
 public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress)
 {
     if (this.m_OutWindow == null)
     {
         this.CreateDictionary();
     }
     this.m_OutWindow.Init(outStream);
     if (outSize > 0L)
     {
         this.m_OutWindow.SetLimit(outSize);
     }
     else
     {
         this.m_OutWindow.SetLimit(0x7fffffffffffffffL - this.m_OutWindow.Total);
     }
     SharpCompress.Compressor.LZMA.RangeCoder.Decoder rangeDecoder = new SharpCompress.Compressor.LZMA.RangeCoder.Decoder();
     rangeDecoder.Init(inStream);
     this.Code(this.m_DictionarySize, this.m_OutWindow, rangeDecoder);
     this.m_OutWindow.ReleaseStream();
     rangeDecoder.ReleaseStream();
     if (!(rangeDecoder.IsFinished && ((inSize <= 0L) || (rangeDecoder.Total == inSize))))
     {
         throw new DataErrorException();
     }
     if (this.m_OutWindow.HasPending)
     {
         throw new DataErrorException();
     }
     this.m_OutWindow = null;
 }
        public void Code(System.IO.Stream inStream, System.IO.Stream outStream,
            Int64 inSize, Int64 outSize, ICodeProgress progress)
        {
            if (m_OutWindow == null)
                CreateDictionary();
            m_OutWindow.Init(outStream);
            if (outSize > 0)
                m_OutWindow.SetLimit(outSize);
            else
                m_OutWindow.SetLimit(Int64.MaxValue - m_OutWindow.Total);

            RangeCoder.Decoder rangeDecoder = new RangeCoder.Decoder();
            rangeDecoder.Init(inStream);

            Code(m_DictionarySize, m_OutWindow, rangeDecoder);

            m_OutWindow.ReleaseStream();
            rangeDecoder.ReleaseStream();

            if (!rangeDecoder.IsFinished || (inSize > 0 && rangeDecoder.Total != inSize))
                throw new DataErrorException();
            if (m_OutWindow.HasPending)
                throw new DataErrorException();
            m_OutWindow = null;
        }
 public uint Decode(Decoder rangeDecoder)
 {
     uint num = (rangeDecoder.Range >> 11) * this.Prob;
     if (rangeDecoder.Code < num)
     {
         rangeDecoder.Range = num;
         this.Prob += (uint) ((0x800 - this.Prob) >> 5);
         if (rangeDecoder.Range < 0x1000000)
         {
             rangeDecoder.Code = (rangeDecoder.Code << 8) | ((byte) rangeDecoder.Stream.ReadByte());
             rangeDecoder.Range = rangeDecoder.Range << 8;
             rangeDecoder.Total += 1L;
         }
         return 0;
     }
     rangeDecoder.Range -= num;
     rangeDecoder.Code -= num;
     this.Prob -= this.Prob >> 5;
     if (rangeDecoder.Range < 0x1000000)
     {
         rangeDecoder.Code = (rangeDecoder.Code << 8) | ((byte) rangeDecoder.Stream.ReadByte());
         rangeDecoder.Range = rangeDecoder.Range << 8;
         rangeDecoder.Total += 1L;
     }
     return 1;
 }
 public LzmaStream(LzmaEncoderProperties properties, bool isLZMA2, Stream presetDictionary, Stream outputStream)
 {
     this.outWindow = new OutWindow();
     this.rangeDecoder = new SharpCompress.Compressor.LZMA.RangeCoder.Decoder();
     this.position = 0L;
     this.endReached = false;
     this.inputPosition = 0L;
     this.uncompressedChunk = false;
     this.needDictReset = true;
     this.needProps = true;
     this.props = new byte[5];
     this.isLZMA2 = isLZMA2;
     this.availableBytes = 0L;
     this.endReached = true;
     if (isLZMA2)
     {
         throw new NotImplementedException();
     }
     this.encoder = new SharpCompress.Compressor.LZMA.Encoder();
     this.encoder.SetCoderProperties(properties.propIDs, properties.properties);
     MemoryStream outStream = new MemoryStream(5);
     this.encoder.WriteCoderProperties(outStream);
     this.props = outStream.ToArray();
     this.encoder.SetStreams(null, outputStream, -1L, -1L);
     if (presetDictionary != null)
     {
         this.encoder.Train(presetDictionary);
     }
 }
 public uint Decode(Decoder rangeDecoder)
 {
     uint index = 1;
     for (int i = this.NumBitLevels; i > 0; i--)
     {
         index = (index << 1) + this.Models[index].Decode(rangeDecoder);
     }
     return (index - (((uint) 1) << this.NumBitLevels));
 }
Exemple #8
0
                public byte DecodeNormal(SharpCompress.Compressor.LZMA.RangeCoder.Decoder rangeDecoder)
                {
                    uint index = 1;

                    do
                    {
                        index = (index << 1) | this.m_Decoders[index].Decode(rangeDecoder);
                    }while (index < 0x100);
                    return((byte)index);
                }
 public static uint ReverseDecode(BitDecoder[] Models, uint startIndex, Decoder rangeDecoder, int NumBitLevels)
 {
     uint num = 1;
     uint num2 = 0;
     for (int i = 0; i < NumBitLevels; i++)
     {
         uint num4 = Models[startIndex + num].Decode(rangeDecoder);
         num = num << 1;
         num += num4;
         num2 |= num4 << i;
     }
     return num2;
 }
 public uint ReverseDecode(Decoder rangeDecoder)
 {
     uint index = 1;
     uint num2 = 0;
     for (int i = 0; i < this.NumBitLevels; i++)
     {
         uint num4 = this.Models[index].Decode(rangeDecoder);
         index = index << 1;
         index += num4;
         num2 |= num4 << i;
     }
     return num2;
 }
Exemple #11
0
 public LzmaStream(byte[] properties, Stream inputStream, long inputSize, long outputSize, Stream presetDictionary, bool isLZMA2)
 {
     this.outWindow         = new OutWindow();
     this.rangeDecoder      = new SharpCompress.Compressor.LZMA.RangeCoder.Decoder();
     this.position          = 0L;
     this.endReached        = false;
     this.inputPosition     = 0L;
     this.uncompressedChunk = false;
     this.needDictReset     = true;
     this.needProps         = true;
     this.props             = new byte[5];
     this.inputStream       = inputStream;
     this.inputSize         = inputSize;
     this.outputSize        = outputSize;
     this.isLZMA2           = isLZMA2;
     if (!isLZMA2)
     {
         this.dictionarySize = BitConverter.ToInt32(properties, 1);
         this.outWindow.Create(this.dictionarySize);
         if (presetDictionary != null)
         {
             this.outWindow.Train(presetDictionary);
         }
         this.rangeDecoder.Init(inputStream);
         this.decoder = new SharpCompress.Compressor.LZMA.Decoder();
         this.decoder.SetDecoderProperties(properties);
         this.props             = properties;
         this.availableBytes    = (outputSize < 0L) ? 0x7fffffffffffffffL : outputSize;
         this.rangeDecoderLimit = inputSize;
     }
     else
     {
         this.dictionarySize = 2 | (properties[0] & 1);
         this.dictionarySize = this.dictionarySize << ((properties[0] >> 1) + 11);
         this.outWindow.Create(this.dictionarySize);
         if (presetDictionary != null)
         {
             this.outWindow.Train(presetDictionary);
             this.needDictReset = false;
         }
         this.props          = new byte[1];
         this.availableBytes = 0L;
     }
 }
Exemple #12
0
            public uint Decode(SharpCompress.Compressor.LZMA.RangeCoder.Decoder rangeDecoder, uint posState)
            {
                if (this.m_Choice.Decode(rangeDecoder) == 0)
                {
                    return(this.m_LowCoder[posState].Decode(rangeDecoder));
                }
                uint num = 8;

                if (this.m_Choice2.Decode(rangeDecoder) == 0)
                {
                    num += this.m_MidCoder[posState].Decode(rangeDecoder);
                }
                else
                {
                    num += 8;
                    num += this.m_HighCoder.Decode(rangeDecoder);
                }
                return(num);
            }
Exemple #13
0
                public byte DecodeWithMatchByte(SharpCompress.Compressor.LZMA.RangeCoder.Decoder rangeDecoder, byte matchByte)
                {
                    uint index = 1;

                    do
                    {
                        uint num2 = (uint)((matchByte >> 7) & 1);
                        matchByte = (byte)(matchByte << 1);
                        uint num3 = this.m_Decoders[(int)((IntPtr)(((1 + num2) << 8) + index))].Decode(rangeDecoder);
                        index = (index << 1) | num3;
                        if (num2 != num3)
                        {
                            while (index < 0x100)
                            {
                                index = (index << 1) | this.m_Decoders[index].Decode(rangeDecoder);
                            }
                            break;
                        }
                    }while (index < 0x100);
                    return((byte)index);
                }
Exemple #14
0
 public PpmdStream(PpmdProperties properties, Stream stream, bool compress)
 {
     this.properties = properties;
     this.stream = stream;
     this.compress = compress;
     if (properties.Version == PpmdVersion.I1)
     {
         this.model = new Model();
         if (compress)
         {
             this.model.EncodeStart(properties);
         }
         else
         {
             this.model.DecodeStart(stream, properties);
         }
     }
     if (properties.Version == PpmdVersion.H)
     {
         this.modelH = new ModelPPM();
         if (compress)
         {
             throw new NotImplementedException();
         }
         this.modelH.decodeInit(stream, properties.ModelOrder, properties.AllocatorSize);
     }
     if (properties.Version == PpmdVersion.H7z)
     {
         this.modelH = new ModelPPM();
         if (compress)
         {
             throw new NotImplementedException();
         }
         this.modelH.decodeInit(null, properties.ModelOrder, properties.AllocatorSize);
         this.decoder = new Decoder();
         this.decoder.Init(stream);
     }
 }
Exemple #15
0
        public int decodeChar(SharpCompress.Compressor.LZMA.RangeCoder.Decoder decoder)
        {
            SharpCompress.Compressor.PPMd.H.State state;
            int  num;
            int  threshold;
            int  num3;
            byte symbol;

            if (this.minContext.NumStats != 1)
            {
                state         = this.tempState1.Initialize(this.Heap);
                state.Address = this.minContext.FreqData.GetStats();
                if ((threshold = (int)decoder.GetThreshold((uint)this.minContext.FreqData.SummFreq)) < (num3 = state.Freq))
                {
                    decoder.Decode(0, (uint)state.Freq);
                    symbol = (byte)state.Symbol;
                    this.minContext.update1_0(this, state.Address);
                    this.nextContext();
                    return(symbol);
                }
                this.prevSuccess = 0;
                num = this.minContext.NumStats - 1;
                do
                {
                    state.IncrementAddress();
                    if ((num3 += state.Freq) > threshold)
                    {
                        decoder.Decode((uint)(num3 - state.Freq), (uint)state.Freq);
                        symbol = (byte)state.Symbol;
                        this.minContext.update1(this, state.Address);
                        this.nextContext();
                        return(symbol);
                    }
                }while (--num > 0);
                if (threshold >= this.minContext.FreqData.SummFreq)
                {
                    return(-2);
                }
                this.hiBitsFlag = this.HB2Flag[this.foundState.Symbol];
                decoder.Decode((uint)num3, (uint)(this.minContext.FreqData.SummFreq - num3));
                for (num = 0; num < 0x100; num++)
                {
                    this.charMask[num] = -1;
                }
                this.charMask[state.Symbol] = 0;
                num = this.minContext.NumStats - 1;
                do
                {
                    state.DecrementAddress();
                    this.charMask[state.Symbol] = 0;
                }while (--num > 0);
            }
            else
            {
                SharpCompress.Compressor.PPMd.H.State rs = this.tempState1.Initialize(this.Heap);
                rs.Address      = this.minContext.getOneState().Address;
                this.hiBitsFlag = this.getHB2Flag()[this.foundState.Symbol];
                int index = rs.Freq - 1;
                int num6  = this.minContext.getArrayIndex(this, rs);
                int summ  = this.binSumm[index][num6];
                if (decoder.DecodeBit((uint)summ, 14) == 0)
                {
                    this.binSumm[index][num6] = ((summ + INTERVAL) - this.minContext.getMean(summ, 7, 2)) & 0xffff;
                    this.foundState.Address   = rs.Address;
                    symbol = (byte)rs.Symbol;
                    rs.IncrementFreq((rs.Freq < 0x80) ? 1 : 0);
                    this.prevSuccess = 1;
                    this.incRunLength(1);
                    this.nextContext();
                    return(symbol);
                }
                summ = (summ - this.minContext.getMean(summ, 7, 2)) & 0xffff;
                this.binSumm[index][num6] = summ;
                this.initEsc = PPMContext.ExpEscape[Utility.URShift(summ, 10)];
                for (num = 0; num < 0x100; num++)
                {
                    this.charMask[num] = -1;
                }
                this.charMask[rs.Symbol] = 0;
                this.prevSuccess         = 0;
            }
            while (true)
            {
                int num8;
                state = this.tempState1.Initialize(this.Heap);
                int numStats = this.minContext.NumStats;
                do
                {
                    this.orderFall++;
                    this.minContext.Address = this.minContext.getSuffix();
                    if ((this.minContext.Address <= this.subAlloc.PText) || (this.minContext.Address > this.subAlloc.HeapEnd))
                    {
                        return(-1);
                    }
                }while (this.minContext.NumStats == numStats);
                num3          = 0;
                state.Address = this.minContext.FreqData.GetStats();
                num           = 0;
                int num9 = this.minContext.NumStats - numStats;
                do
                {
                    int num11 = this.charMask[state.Symbol];
                    num3 += state.Freq & num11;
                    this.minContext.ps[num] = state.Address;
                    state.IncrementAddress();
                    num -= num11;
                }while (num != num9);
                SEE2Context context = this.minContext.makeEscFreq(this, numStats, out num8);
                num8     += num3;
                threshold = (int)decoder.GetThreshold((uint)num8);
                if (threshold < num3)
                {
                    SharpCompress.Compressor.PPMd.H.State state3 = this.tempState2.Initialize(this.Heap);
                    num3           = 0;
                    num            = 0;
                    state3.Address = this.minContext.ps[num];
                    while ((num3 += state3.Freq) <= threshold)
                    {
                        num++;
                        state3.Address = this.minContext.ps[num];
                    }
                    state.Address = state3.Address;
                    decoder.Decode((uint)(num3 - state.Freq), (uint)state.Freq);
                    context.update();
                    symbol = (byte)state.Symbol;
                    this.minContext.update2(this, state.Address);
                    this.updateModel();
                    return(symbol);
                }
                if (threshold >= num8)
                {
                    return(-2);
                }
                decoder.Decode((uint)num3, (uint)(num8 - num3));
                context.Summ += num8;
                do
                {
                    state.Address = this.minContext.ps[--num];
                    this.charMask[state.Symbol] = 0;
                }while (num != 0);
            }
        }
Exemple #16
0
 public byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)
 {
     return(m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder));
 }
Exemple #17
0
 public byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)
 {
     return(m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte));
 }
Exemple #18
0
        internal bool Code(int dictionarySize, OutWindow outWindow, SharpCompress.Compressor.LZMA.RangeCoder.Decoder rangeDecoder)
        {
            int num = Math.Max(dictionarySize, 1);

            outWindow.CopyPending();
            while (outWindow.HasSpace)
            {
                uint posState = ((uint)outWindow.Total) & this.m_PosStateMask;
                if (this.m_IsMatchDecoders[(this.state.Index << 4) + posState].Decode(rangeDecoder) == 0)
                {
                    byte num3;
                    byte @byte = outWindow.GetByte(0);
                    if (!this.state.IsCharState())
                    {
                        num3 = this.m_LiteralDecoder.DecodeWithMatchByte(rangeDecoder, (uint)outWindow.Total, @byte, outWindow.GetByte((int)this.rep0));
                    }
                    else
                    {
                        num3 = this.m_LiteralDecoder.DecodeNormal(rangeDecoder, (uint)outWindow.Total, @byte);
                    }
                    outWindow.PutByte(num3);
                    this.state.UpdateChar();
                }
                else
                {
                    uint num5;
                    if (this.m_IsRepDecoders[this.state.Index].Decode(rangeDecoder) == 1)
                    {
                        if (this.m_IsRepG0Decoders[this.state.Index].Decode(rangeDecoder) == 0)
                        {
                            if (this.m_IsRep0LongDecoders[(this.state.Index << 4) + posState].Decode(rangeDecoder) == 0)
                            {
                                this.state.UpdateShortRep();
                                outWindow.PutByte(outWindow.GetByte((int)this.rep0));
                                continue;
                            }
                        }
                        else
                        {
                            uint num6;
                            if (this.m_IsRepG1Decoders[this.state.Index].Decode(rangeDecoder) == 0)
                            {
                                num6 = this.rep1;
                            }
                            else
                            {
                                if (this.m_IsRepG2Decoders[this.state.Index].Decode(rangeDecoder) == 0)
                                {
                                    num6 = this.rep2;
                                }
                                else
                                {
                                    num6      = this.rep3;
                                    this.rep3 = this.rep2;
                                }
                                this.rep2 = this.rep1;
                            }
                            this.rep1 = this.rep0;
                            this.rep0 = num6;
                        }
                        num5 = this.m_RepLenDecoder.Decode(rangeDecoder, posState) + 2;
                        this.state.UpdateRep();
                    }
                    else
                    {
                        this.rep3 = this.rep2;
                        this.rep2 = this.rep1;
                        this.rep1 = this.rep0;
                        num5      = 2 + this.m_LenDecoder.Decode(rangeDecoder, posState);
                        this.state.UpdateMatch();
                        uint num7 = this.m_PosSlotDecoder[Base.GetLenToPosState(num5)].Decode(rangeDecoder);
                        if (num7 >= 4)
                        {
                            int numBitLevels = ((int)(num7 >> 1)) - 1;
                            this.rep0 = (uint)((2 | (num7 & 1)) << (numBitLevels & 0x1f));
                            if (num7 < 14)
                            {
                                this.rep0 += BitTreeDecoder.ReverseDecode(this.m_PosDecoders, (this.rep0 - num7) - 1, rangeDecoder, numBitLevels);
                            }
                            else
                            {
                                this.rep0 += rangeDecoder.DecodeDirectBits(numBitLevels - 4) << 4;
                                this.rep0 += this.m_PosAlignDecoder.ReverseDecode(rangeDecoder);
                            }
                        }
                        else
                        {
                            this.rep0 = num7;
                        }
                    }
                    if ((this.rep0 >= outWindow.Total) || (this.rep0 >= num))
                    {
                        if (this.rep0 != uint.MaxValue)
                        {
                            throw new DataErrorException();
                        }
                        return(true);
                    }
                    outWindow.CopyBlock((int)this.rep0, (int)num5);
                }
            }
            return(false);
        }
Exemple #19
0
 public byte DecodeWithMatchByte(SharpCompress.Compressor.LZMA.RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)
 {
     return(this.m_Coders[this.GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte));
 }
Exemple #20
0
 public byte DecodeNormal(SharpCompress.Compressor.LZMA.RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)
 {
     return(this.m_Coders[this.GetState(pos, prevByte)].DecodeNormal(rangeDecoder));
 }
Exemple #21
0
        internal bool Code(int dictionarySize, LZ.OutWindow outWindow, RangeCoder.Decoder rangeDecoder)
        {
            int dictionarySizeCheck = Math.Max(dictionarySize, 1);

            outWindow.CopyPending();

            while (outWindow.HasSpace)
            {
                uint posState = (uint)outWindow.Total & m_PosStateMask;
                if (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(rangeDecoder) == 0)
                {
                    byte b;
                    byte prevByte = outWindow.GetByte(0);
                    if (!state.IsCharState())
                    {
                        b = m_LiteralDecoder.DecodeWithMatchByte(rangeDecoder,
                                                                 (uint)outWindow.Total, prevByte, outWindow.GetByte((int)rep0));
                    }
                    else
                    {
                        b = m_LiteralDecoder.DecodeNormal(rangeDecoder, (uint)outWindow.Total, prevByte);
                    }
                    outWindow.PutByte(b);
                    state.UpdateChar();
                }
                else
                {
                    uint len;
                    if (m_IsRepDecoders[state.Index].Decode(rangeDecoder) == 1)
                    {
                        if (m_IsRepG0Decoders[state.Index].Decode(rangeDecoder) == 0)
                        {
                            if (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(rangeDecoder) == 0)
                            {
                                state.UpdateShortRep();
                                outWindow.PutByte(outWindow.GetByte((int)rep0));
                                continue;
                            }
                        }
                        else
                        {
                            UInt32 distance;
                            if (m_IsRepG1Decoders[state.Index].Decode(rangeDecoder) == 0)
                            {
                                distance = rep1;
                            }
                            else
                            {
                                if (m_IsRepG2Decoders[state.Index].Decode(rangeDecoder) == 0)
                                {
                                    distance = rep2;
                                }
                                else
                                {
                                    distance = rep3;
                                    rep3     = rep2;
                                }
                                rep2 = rep1;
                            }
                            rep1 = rep0;
                            rep0 = distance;
                        }
                        len = m_RepLenDecoder.Decode(rangeDecoder, posState) + Base.kMatchMinLen;
                        state.UpdateRep();
                    }
                    else
                    {
                        rep3 = rep2;
                        rep2 = rep1;
                        rep1 = rep0;
                        len  = Base.kMatchMinLen + m_LenDecoder.Decode(rangeDecoder, posState);
                        state.UpdateMatch();
                        uint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(rangeDecoder);
                        if (posSlot >= Base.kStartPosModelIndex)
                        {
                            int numDirectBits = (int)((posSlot >> 1) - 1);
                            rep0 = ((2 | (posSlot & 1)) << numDirectBits);
                            if (posSlot < Base.kEndPosModelIndex)
                            {
                                rep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,
                                                                     rep0 - posSlot - 1, rangeDecoder, numDirectBits);
                            }
                            else
                            {
                                rep0 += (rangeDecoder.DecodeDirectBits(
                                             numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);
                                rep0 += m_PosAlignDecoder.ReverseDecode(rangeDecoder);
                            }
                        }
                        else
                        {
                            rep0 = posSlot;
                        }
                    }
                    if (rep0 >= outWindow.Total || rep0 >= dictionarySizeCheck)
                    {
                        if (rep0 == 0xFFFFFFFF)
                        {
                            return(true);
                        }
                        throw new DataErrorException();
                    }
                    outWindow.CopyBlock((int)rep0, (int)len);
                }
            }
            return(false);
        }
Exemple #22
0
 public LzmaStream(byte[] properties, Stream inputStream, long inputSize, long outputSize, Stream presetDictionary, bool isLZMA2)
 {
     this.outWindow = new OutWindow();
     this.rangeDecoder = new SharpCompress.Compressor.LZMA.RangeCoder.Decoder();
     this.position = 0L;
     this.endReached = false;
     this.inputPosition = 0L;
     this.uncompressedChunk = false;
     this.needDictReset = true;
     this.needProps = true;
     this.props = new byte[5];
     this.inputStream = inputStream;
     this.inputSize = inputSize;
     this.outputSize = outputSize;
     this.isLZMA2 = isLZMA2;
     if (!isLZMA2)
     {
         this.dictionarySize = BitConverter.ToInt32(properties, 1);
         this.outWindow.Create(this.dictionarySize);
         if (presetDictionary != null)
         {
             this.outWindow.Train(presetDictionary);
         }
         this.rangeDecoder.Init(inputStream);
         this.decoder = new SharpCompress.Compressor.LZMA.Decoder();
         this.decoder.SetDecoderProperties(properties);
         this.props = properties;
         this.availableBytes = (outputSize < 0L) ? 0x7fffffffffffffffL : outputSize;
         this.rangeDecoderLimit = inputSize;
     }
     else
     {
         this.dictionarySize = 2 | (properties[0] & 1);
         this.dictionarySize = this.dictionarySize << ((properties[0] >> 1) + 11);
         this.outWindow.Create(this.dictionarySize);
         if (presetDictionary != null)
         {
             this.outWindow.Train(presetDictionary);
             this.needDictReset = false;
         }
         this.props = new byte[1];
         this.availableBytes = 0L;
     }
 }