unrar5: unpack wip

This commit is contained in:
coderb
2017-12-20 16:01:55 -05:00
parent 0219fc3ea9
commit 3e8f52689e
9 changed files with 45 additions and 57 deletions

View File

@@ -1,5 +1,4 @@
#if RARWIP
#if !Rar2017_64bit
#if !Rar2017_64bit
using nint = System.Int32;
using nuint = System.UInt32;
using size_t = System.UInt32;
@@ -158,4 +157,3 @@ public size_t GetBlockSize(size_t StartPos,size_t RequiredSize)
}
}
#endif

View File

@@ -1,5 +1,4 @@
#if RARWIP
#if !Rar2017_64bit
#if !Rar2017_64bit
using nint = System.Int32;
using nuint = System.UInt32;
using size_t = System.UInt32;
@@ -43,7 +42,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
// as of 12/2017 .NET limits array indexing to using a signed integer
// MaxWinSize causes unpack to use a fragmented window when the file
// window size exceeds MaxWinSize
MaxWinSize = ((uint)int.MaxValue) + 1;
// uggh, that's not how this variable is used, it's the size of the currently allocated window buffer
//x MaxWinSize = ((uint)int.MaxValue) + 1;
// may be long.MaxValue which could indicate unknown size (not present in header)
DestUnpSize = fileHeader.UncompressedSize;
@@ -63,7 +63,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
{
UnstoreFile();
} else {
DoUnpack(this.fileHeader.CompressionMethod, this.fileHeader.IsSolid);
DoUnpack(this.fileHeader.CompressionAlgorithm, this.fileHeader.IsSolid);
}
}
@@ -106,4 +106,3 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
}
}
#endif

View File

@@ -1,6 +1,4 @@
#if RARWIP
#if !RarV2017_RAR5ONLY
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -11,6 +9,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
{
internal partial class Unpack
{
#if !RarV2017_RAR5ONLY
const int STARTL1 =2;
static uint[] DecL1={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00,
@@ -439,7 +438,7 @@ void GetFlagsBuf()
ChSetC[NewFlagsPlace]=Flags;
}
#endif
void UnpInitData15(bool Solid)
{
if (!Solid)
@@ -457,33 +456,33 @@ void UnpInitData15(bool Solid)
ReadTop=0;
}
void InitHuff()
{
for (uint I=0;I<256;I++)
{
ChSet[I]=ChSetB[I]=I<<8;
ChSetA[I]=I;
ChSetC[I]=((~I+1) & 0xff)<<8;
ChSet[I]=ChSetB[I]=(ushort)(I<<8);
ChSetA[I]=(ushort)I;
ChSetC[I]=(ushort)(((~I+1) & 0xff)<<8);
}
memset(NToPl,0,sizeof(NToPl));
memset(NToPlB,0,sizeof(NToPlB));
memset(NToPlC,0,sizeof(NToPlC));
Utility.Memset(NToPl,0,NToPl.Length);
Utility.Memset(NToPlB,0,NToPlB.Length);
Utility.Memset(NToPlC,0,NToPlC.Length);
CorrHuff(ChSetB,NToPlB);
}
void CorrHuff(ushort *CharSet,byte *NumToPlace)
void CorrHuff(ushort[] CharSet,byte[] NumToPlace)
{
int I,J;
for (I=7;I>=0;I--)
for (J=0;J<32;J++,CharSet++)
*CharSet=(*CharSet & ~0xff) | I;
memset(NumToPlace,0,sizeof(NToPl));
for (J=0;J<32;J++)
CharSet[J]=(ushort)((CharSet[J] & ~0xff) | I);
Utility.Memset(NumToPlace,0,NToPl.Length);
for (I=6;I>=0;I--)
NumToPlace[I]=(7-I)*32;
NumToPlace[I]=(byte)((7-I)*32);
}
#if !RarV2017_RAR5ONLY
void CopyString15(uint Distance,uint Length)
{
@@ -504,8 +503,7 @@ uint DecodeNum(uint Num,uint StartPos,uint *DecTab,uint *PosTab)
Inp.faddbits(StartPos);
return(((Num-(I ? DecTab[I-1]:0))>>(16-StartPos))+PosTab[StartPos]);
}
#endif
}
}
#endif
#endif

View File

@@ -1,6 +1,4 @@
#if RARWIP
#if !RarV2017_RAR5ONLY
#if !Rar2017_64bit
#if !Rar2017_64bit
using nint = System.Int32;
using nuint = System.UInt32;
using size_t = System.UInt32;
@@ -17,13 +15,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef;
using static SharpCompress.Compressors.Rar.UnpackV2017.Unpack.Unpack20Local;
//using static SharpCompress.Compressors.Rar.UnpackV2017.Unpack.Unpack20Local;
namespace SharpCompress.Compressors.Rar.UnpackV2017
{
internal partial class Unpack
{
#if !RarV2017_RAR5ONLY
void CopyString20(uint Length,uint Distance)
{
LastDist=OldDist[OldDistPtr++ & 3]=Distance;
@@ -292,6 +291,7 @@ void ReadLastTables()
ReadTables20();
}
#endif
void UnpInitData20(bool Solid)
{
@@ -303,12 +303,15 @@ void UnpInitData20(bool Solid)
UnpCurChannel=0;
UnpChannels=1;
memset(AudV,0,sizeof(AudV));
//memset(AudV,0,sizeof(AudV));
AudV = new AudioVariables[4];
Utility.Memset(UnpOldTable20, 0, UnpOldTable20.Length);
memset(MD,0,sizeof(MD));
//memset(MD,0,sizeof(MD));
MD = new DecodeTable[4];
}
}
#if !RarV2017_RAR5ONLY
byte DecodeAudio(int Delta)
{
@@ -402,8 +405,7 @@ byte DecodeAudio(int Delta)
}
return (byte)Ch;
}
#endif
}
}
#endif
#endif

View File

@@ -1,6 +1,4 @@
#if RARWIP
#if !RarV2017_RAR5ONLY
#if !Rar2017_64bit
#if !Rar2017_64bit
using nint = System.Int32;
using nuint = System.UInt32;
using size_t = System.UInt32;
@@ -18,12 +16,14 @@ using System.Text;
using System.Threading.Tasks;
using static SharpCompress.Compressors.Rar.UnpackV2017.PackDef;
using static SharpCompress.Compressors.Rar.UnpackV2017.UnpackGlobal;
using static SharpCompress.Compressors.Rar.UnpackV2017.Unpack.Unpack30Local;
//using static SharpCompress.Compressors.Rar.UnpackV2017.Unpack.Unpack30Local;
namespace SharpCompress.Compressors.Rar.UnpackV2017
{
internal partial class Unpack
{
#if !RarV2017_RAR5ONLY
// We use it instead of direct PPM.DecodeChar call to be sure that
// we reset PPM structures in case of corrupt data. It is important,
// because these structures can be invalid after PPM.DecodeChar returned -1.
@@ -761,6 +761,7 @@ bool ReadTables30()
return true;
}
#endif
void UnpInitData30(bool Solid)
{
@@ -794,7 +795,6 @@ void InitFilters30(bool Solid)
PrgStack.Clear();
}
}
}
#endif
#endif

View File

@@ -1,5 +1,4 @@
#if RARWIP
#if !Rar2017_64bit
#if !Rar2017_64bit
using nint = System.Int32;
using nuint = System.UInt32;
using size_t = System.UInt32;
@@ -724,4 +723,3 @@ void InitFilters()
}
}
#endif

View File

@@ -1,5 +1,4 @@
#if RARWIP
#if !Rar2017_64bit
#if !Rar2017_64bit
using nint = System.Int32;
using nuint = System.UInt32;
using size_t = System.UInt32;
@@ -44,13 +43,11 @@ public Unpack(/* ComprDataIO *DataIO */)
// It prevents crash if first DoUnpack call is later made with wrong
// (true) 'Solid' value.
UnpInitData(false);
#if !RarV2017_RAR5ONLY
#if !RarV2017_SFX_MODULE
// RAR 1.5 decompression initialization
UnpInitData15(false);
InitHuff();
#endif
#endif
}
// later: may need Dispose() if we support thread pool
@@ -191,6 +188,9 @@ void DoUnpack(uint Method,bool Solid)
#endif
Unpack5(Solid);
break;
#if !Rar2017_NOSTRICT
default: throw new InvalidFormatException("unknown compression method " + Method);
#endif
}
}
@@ -222,12 +222,10 @@ void UnpInitData(bool Solid)
//memset(&BlockHeader,0,sizeof(BlockHeader));
BlockHeader = new UnpackBlockHeader();
BlockHeader.BlockSize=-1; // '-1' means not defined yet.
#if !RarV2017_RAR5ONLY
#if !RarV2017_SFX_MODULE
UnpInitData20(Solid);
#endif
UnpInitData30(Solid);
#endif
UnpInitData50(Solid);
}
@@ -379,4 +377,3 @@ void MakeDecodeTables(byte[] LengthTable, int offset, DecodeTable Dec,uint Size)
}
}
#endif

View File

@@ -1,5 +1,4 @@
#if RARWIP
#if !Rar2017_64bit
#if !Rar2017_64bit
using nint = System.Int32;
using nuint = System.UInt32;
using size_t = System.UInt32;
@@ -175,4 +174,3 @@ uint SlotToLength(BitInput Inp,uint Slot)
}
}
#endif

View File

@@ -1,5 +1,4 @@
#if RARWIP
#if !Rar2017_64bit
#if !Rar2017_64bit
using nint = System.Int32;
using nuint = System.UInt32;
using size_t = System.UInt32;
@@ -341,7 +340,7 @@ internal partial class Unpack
/***************************** Unpack v 2.0 *********************************/
//void Unpack20(bool Solid);
readonly DecodeTable[] MD = new DecodeTable[4]; // Decode multimedia data, up to 4 channels.
DecodeTable[] MD = new DecodeTable[4]; // Decode multimedia data, up to 4 channels.
readonly byte[] UnpOldTable20 = new byte[MC20*4];
bool UnpAudioBlock;
@@ -442,4 +441,3 @@ internal partial class Unpack
}
}
#endif