unrar5: unpack wip

This commit is contained in:
coderb
2017-12-20 11:19:30 -05:00
parent 2d0319f779
commit 0d40883176
4 changed files with 32 additions and 20 deletions

View File

@@ -126,10 +126,10 @@ public void CopyString(uint Length,uint Distance,ref size_t UnpPtr,size_t MaxWin
}
public void CopyData(byte *Dest,size_t WinPos,size_t Size)
public void CopyData(byte[] Dest, size_t destOffset, size_t WinPos,size_t Size)
{
for (size_t I=0;I<Size;I++)
Dest[I]=this[WinPos+I];
Dest[destOffset+I]=this[WinPos+I];
}

View File

@@ -91,6 +91,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017
}
public int PpmEscChar { get => this.PPMEscChar; set => this.PPMEscChar = value; }
public static byte[] EnsureCapacity(byte[] array, int length) {
return array.Length < length ? new byte[length] : array;
}
}
}
#endif

View File

@@ -325,31 +325,35 @@ void UnpWriteBuf()
{
uint BlockEnd=(BlockStart+BlockLength)&MaxWinMask;
FilterSrcMemory.Alloc(BlockLength);
byte *Mem=&FilterSrcMemory[0];
//x FilterSrcMemory.Alloc(BlockLength);
FilterSrcMemory = EnsureCapacity(FilterSrcMemory, checked((int)BlockLength));
byte[] Mem= FilterSrcMemory;
if (BlockStart<BlockEnd || BlockEnd==0)
{
if (Fragmented)
FragWindow.CopyData(Mem,BlockStart,BlockLength);
FragWindow.CopyData(Mem,0,BlockStart,BlockLength);
else
memcpy(Mem,Window+BlockStart,BlockLength);
//x memcpy(Mem,Window+BlockStart,BlockLength);
Array.Copy(Window, BlockStart, Mem, 0, BlockLength);
}
else
{
size_t FirstPartLength=size_t(MaxWinSize-BlockStart);
size_t FirstPartLength=(size_t)(MaxWinSize-BlockStart);
if (Fragmented)
{
FragWindow.CopyData(Mem,BlockStart,FirstPartLength);
FragWindow.CopyData(Mem+FirstPartLength,0,BlockEnd);
FragWindow.CopyData(Mem,0,BlockStart,FirstPartLength);
FragWindow.CopyData(Mem,FirstPartLength,0,BlockEnd);
}
else
{
memcpy(Mem,Window+BlockStart,FirstPartLength);
memcpy(Mem+FirstPartLength,Window,BlockEnd);
//x memcpy(Mem,Window+BlockStart,FirstPartLength);
Array.Copy(Window, BlockStart, Mem, 0, FirstPartLength);
//x memcpy(Mem+FirstPartLength,Window,BlockEnd);
Array.Copy(Window, 0, Mem, FirstPartLength,BlockEnd);
}
}
byte *OutMem=ApplyFilter(Mem,BlockLength,flt);
byte[] OutMem=ApplyFilter(Mem,BlockLength,flt);
Filters[I].Type=FILTER_NONE;
@@ -388,8 +392,10 @@ void UnpWriteBuf()
}
// Remove processed filters from queue.
size_t EmptyCount=0;
for (size_t I=0;I<Filters.Count;I++)
// sharpcompress: size_t -> int
int EmptyCount=0;
// sharpcompress: size_t -> int
for (int I=0;I<Filters.Count;I++)
{
if (EmptyCount>0)
Filters[I-EmptyCount]=Filters[I];
@@ -419,9 +425,9 @@ void UnpWriteBuf()
}
byte* ApplyFilter(byte *Data,uint DataSize,UnpackFilter Flt)
byte[] ApplyFilter(byte[] Data,uint DataSize,UnpackFilter Flt)
{
byte *SrcData=Data;
byte[] SrcData=Data;
switch(Flt.Type)
{
case FILTER_E8:
@@ -484,8 +490,10 @@ byte* ApplyFilter(byte *Data,uint DataSize,UnpackFilter Flt)
// values here, since RAR5 uses only 5 bits to store channel.
uint Channels=Flt.Channels,SrcPos=0;
FilterDstMemory.Alloc(DataSize);
byte *DstData=&FilterDstMemory[0];
//x FilterDstMemory.Alloc(DataSize);
FilterDstMemory = EnsureCapacity(FilterDstMemory, checked((int)DataSize));
byte[] DstData=FilterDstMemory;
// Bytes from same channels are grouped to continual data blocks,
// so we need to place them back to their interleaving positions.

View File

@@ -271,8 +271,8 @@ internal partial class Unpack
byte *ReadBufMT;
#endif
readonly List<byte> FilterSrcMemory = new List<byte>();
readonly List<byte> FilterDstMemory = new List<byte>();
byte[] FilterSrcMemory = new byte[0];
byte[] FilterDstMemory = new byte[0];
// Filters code, one entry per filter.
readonly List<UnpackFilter> Filters = new List<UnpackFilter>();