123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- #if !Rar2017_64bit
- using nint = System.Int32;
- using nuint = System.UInt32;
- using size_t = System.UInt32;
- #else
- using nint = System.Int64;
- using nuint = System.UInt64;
- using size_t = System.UInt64;
- #endif
- using int64 = System.Int64;
- using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef;
- namespace SharpCompress.Compressors.Rar.UnpackV2017
- {
- internal partial class Unpack
- {
- private void InsertOldDist(uint Distance)
- {
- OldDist[3]=OldDist[2];
- OldDist[2]=OldDist[1];
- OldDist[1]=OldDist[0];
- OldDist[0]=Distance;
- }
- private void CopyString(uint Length,uint Distance)
- {
- size_t SrcPtr=UnpPtr-Distance;
- if (SrcPtr<MaxWinSize-MAX_LZ_MATCH && UnpPtr<MaxWinSize-MAX_LZ_MATCH)
- {
-
-
-
- var Window = this.Window;
- while (Length-- > 0)
- {
- Window[UnpPtr++] = Window[SrcPtr++];
- }
- }
- else
- while (Length-- > 0)
- {
- Window[UnpPtr]=Window[SrcPtr++ & MaxWinMask];
-
-
- UnpPtr=(UnpPtr+1) & MaxWinMask;
- }
- }
- private uint DecodeNumber(BitInput Inp,DecodeTable Dec)
- {
-
- uint BitField=Inp.getbits() & 0xfffe;
- if (BitField<Dec.DecodeLen[Dec.QuickBits])
- {
- uint Code=BitField>>(int)(16-Dec.QuickBits);
- Inp.addbits(Dec.QuickLen[Code]);
- return Dec.QuickNum[Code];
- }
-
- uint Bits=15;
- for (uint I=Dec.QuickBits+1;I<15;I++)
- if (BitField<Dec.DecodeLen[I])
- {
- Bits=I;
- break;
- }
- Inp.addbits(Bits);
-
-
- uint Dist=BitField-Dec.DecodeLen[Bits-1];
-
-
- Dist>>=(int)(16-Bits);
-
-
-
- uint Pos=Dec.DecodePos[Bits]+Dist;
-
- if (Pos>=Dec.MaxNum)
- Pos=0;
-
-
- return Dec.DecodeNum[Pos];
- }
- private uint SlotToLength(BitInput Inp,uint Slot)
- {
- uint LBits,Length=2;
- if (Slot<8)
- {
- LBits=0;
- Length+=Slot;
- }
- else
- {
- LBits=Slot/4-1;
- Length+=(4 | (Slot & 3)) << (int)LBits;
- }
- if (LBits>0)
- {
- Length+=Inp.getbits()>>(int)(16-LBits);
- Inp.addbits(LBits);
- }
- return Length;
- }
- }
- }
|