From 0d408831769bbdc463e908f837a3029086a0283f Mon Sep 17 00:00:00 2001 From: coderb Date: Wed, 20 Dec 2017 11:19:30 -0500 Subject: [PATCH] unrar5: unpack wip --- .../FragmentedWindow.unpack50frag_cpp.cs | 4 +- .../Compressors/Rar/UnpackV2017/Unpack.cs | 4 ++ .../Rar/UnpackV2017/Unpack.unpack50_cpp.cs | 40 +++++++++++-------- .../Compressors/Rar/UnpackV2017/unpack_hpp.cs | 4 +- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs index 32ebd57b..ca1b78df 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs @@ -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 this.PPMEscChar; set => this.PPMEscChar = value; } + + public static byte[] EnsureCapacity(byte[] array, int length) { + return array.Length < length ? new byte[length] : array; + } } } #endif \ No newline at end of file diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs index 57dfa466..73fb3722 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack50_cpp.cs @@ -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 int + int EmptyCount=0; + // sharpcompress: size_t -> int + for (int I=0;I0) 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. diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs index 893c6d2f..0c4cc62f 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/unpack_hpp.cs @@ -271,8 +271,8 @@ internal partial class Unpack byte *ReadBufMT; #endif - readonly List FilterSrcMemory = new List(); - readonly List FilterDstMemory = new List(); + byte[] FilterSrcMemory = new byte[0]; + byte[] FilterDstMemory = new byte[0]; // Filters code, one entry per filter. readonly List Filters = new List();