Port from HG

This commit is contained in:
Adam Hathcock
2013-04-28 11:25:37 +01:00
parent ff745d0076
commit 8340d1edd6
31 changed files with 5514 additions and 106 deletions

View File

@@ -11,7 +11,7 @@ namespace SharpCompress.Archive.SevenZip
{
public class SevenZipArchive : AbstractArchive<SevenZipArchiveEntry, SevenZipVolume>
{
private SevenZipHeaderFactory factory;
private ArchiveDatabase database;
#if !PORTABLE
/// <summary>
/// Constructor expects a filepath to an existing file.
@@ -130,19 +130,24 @@ namespace SharpCompress.Archive.SevenZip
{
var stream = volumes.Single().Stream;
LoadFactory(stream);
for (int i = 0; i < factory.Entries.Length; i++)
for (int i = 0; i < database.Files.Count; i++)
{
var file = factory.Entries[i];
yield return new SevenZipArchiveEntry(this, new SevenZipFilePart(factory, i, file, stream));
var file = database.Files[i];
if (!file.IsDir)
{
yield return new SevenZipArchiveEntry(this, new SevenZipFilePart(stream, database, i, file));
}
}
}
private void LoadFactory(Stream stream)
{
if (factory == null)
if (database == null)
{
stream.Position = 0;
factory = new SevenZipHeaderFactory(stream);
var reader = new ArchiveReader();
reader.Open(stream);
database = reader.ReadDatabase(null);
}
}
@@ -151,13 +156,20 @@ namespace SharpCompress.Archive.SevenZip
{
try
{
return SevenZipHeaderFactory.SignatureMatch(stream);
return SignatureMatch(stream);
}
catch
{
return false;
}
}
private static readonly byte[] SIGNATURE = new byte[] { (byte)'7', (byte)'z', 0xBC, 0xAF, 0x27, 0x1C };
private static bool SignatureMatch(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
byte[] signatureBytes = reader.ReadBytes(6);
return signatureBytes.BinaryEquals(SIGNATURE);
}
protected override IReader CreateReaderForSolidExtraction()
{
@@ -168,15 +180,16 @@ namespace SharpCompress.Archive.SevenZip
{
get
{
return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Header.Folder).Count() > 1;
return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1;
}
}
private class SevenZipReader : AbstractReader<SevenZipEntry, SevenZipVolume>
{
private readonly SevenZipArchive archive;
private Folder currentFolder;
private CFolder currentFolder;
private Stream currentStream;
private CFileItem currentItem;
internal SevenZipReader(SevenZipArchive archive)
: base(Options.KeepStreamsOpen, ArchiveType.SevenZip)
@@ -198,26 +211,28 @@ namespace SharpCompress.Archive.SevenZip
{
yield return dir;
}
foreach (var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Header.Folder))
foreach (var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder))
{
currentFolder = group.Key;
currentStream = currentFolder.GetStream();
foreach (var entry in group.OrderBy(x => x.FilePart.Header.FolderOffset))
{
if (currentStream.Position != (long)entry.FilePart.Header.FolderOffset)
{
throw new InvalidFormatException("Unexpected SevenZip folder offset");
}
currentFolder = group.Key;
if (group.Key == null)
{
currentStream = Stream.Null;
}
else
{
currentStream = archive.database.GetFolderStream(stream, currentFolder, null);
}
foreach (var entry in group)
{
currentItem = entry.FilePart.Header;
yield return entry;
}
}
}
}
protected override EntryStream GetEntryStream()
{
return new EntryStream(new ReadOnlySubStream(currentStream,
(long)
Entry.Parts.Cast<SevenZipFilePart>().Single().Header.UnpackedStream.UnpackedSize));
return new EntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
}
}
}

View File

@@ -0,0 +1,161 @@
using System;
using System.Collections.Generic;
using System.IO;
using SharpCompress.Compressor.LZMA;
using SharpCompress.Compressor.LZMA.Utilites;
namespace SharpCompress.Common.SevenZip
{
public class ArchiveDatabase
{
internal byte MajorVersion;
internal byte MinorVersion;
internal long StartPositionAfterHeader;
internal long DataStartPosition;
internal List<long> PackSizes = new List<long>();
internal List<uint?> PackCRCs = new List<uint?>();
internal List<CFolder> Folders = new List<CFolder>();
internal List<int> NumUnpackStreamsVector;
internal List<CFileItem> Files = new List<CFileItem>();
internal List<long> PackStreamStartPositions = new List<long>();
internal List<int> FolderStartFileIndex = new List<int>();
internal List<int> FileIndexToFolderIndexMap = new List<int>();
internal void Clear()
{
PackSizes.Clear();
PackCRCs.Clear();
Folders.Clear();
NumUnpackStreamsVector = null;
Files.Clear();
PackStreamStartPositions.Clear();
FolderStartFileIndex.Clear();
FileIndexToFolderIndexMap.Clear();
}
internal bool IsEmpty()
{
return PackSizes.Count == 0
&& PackCRCs.Count == 0
&& Folders.Count == 0
&& NumUnpackStreamsVector.Count == 0
&& Files.Count == 0;
}
private void FillStartPos()
{
PackStreamStartPositions.Clear();
long startPos = 0;
for(int i = 0; i < PackSizes.Count; i++)
{
PackStreamStartPositions.Add(startPos);
startPos += PackSizes[i];
}
}
private void FillFolderStartFileIndex()
{
FolderStartFileIndex.Clear();
FileIndexToFolderIndexMap.Clear();
int folderIndex = 0;
int indexInFolder = 0;
for(int i = 0; i < Files.Count; i++)
{
CFileItem file = Files[i];
bool emptyStream = !file.HasStream;
if(emptyStream && indexInFolder == 0)
{
FileIndexToFolderIndexMap.Add(-1);
continue;
}
if(indexInFolder == 0)
{
// v3.13 incorrectly worked with empty folders
// v4.07: Loop for skipping empty folders
for(; ; )
{
if(folderIndex >= Folders.Count)
throw new InvalidOperationException();
FolderStartFileIndex.Add(i); // check it
if(NumUnpackStreamsVector[folderIndex] != 0)
break;
folderIndex++;
}
}
FileIndexToFolderIndexMap.Add(folderIndex);
if(emptyStream)
continue;
indexInFolder++;
if(indexInFolder >= NumUnpackStreamsVector[folderIndex])
{
folderIndex++;
indexInFolder = 0;
}
}
}
public void Fill()
{
FillStartPos();
FillFolderStartFileIndex();
}
internal long GetFolderStreamPos(CFolder folder, int indexInFolder)
{
int index = folder.FirstPackStreamId + indexInFolder;
return DataStartPosition + PackStreamStartPositions[index];
}
internal long GetFolderFullPackSize(int folderIndex)
{
int packStreamIndex = Folders[folderIndex].FirstPackStreamId;
CFolder folder = Folders[folderIndex];
long size = 0;
for(int i = 0; i < folder.PackStreams.Count; i++)
size += PackSizes[packStreamIndex + i];
return size;
}
internal Stream GetFolderStream(Stream stream, CFolder folder, IPasswordProvider pw)
{
int packStreamIndex = folder.FirstPackStreamId;
long folderStartPackPos = GetFolderStreamPos(folder, 0);
List<long> packSizes = new List<long>();
for (int j = 0; j < folder.PackStreams.Count; j++)
packSizes.Add(PackSizes[packStreamIndex + j]);
return DecoderStreamHelper.CreateDecoderStream(stream, folderStartPackPos, packSizes.ToArray(), folder, pw);
}
private long GetFolderPackStreamSize(int folderIndex, int streamIndex)
{
return PackSizes[Folders[folderIndex].FirstPackStreamId + streamIndex];
}
private long GetFilePackSize(int fileIndex)
{
int folderIndex = FileIndexToFolderIndexMap[fileIndex];
if(folderIndex != -1)
if(FolderStartFileIndex[folderIndex] == fileIndex)
return GetFolderFullPackSize(folderIndex);
return 0;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
namespace SharpCompress.Common.SevenZip
{
internal class CBindPair
{
internal int InIndex;
internal int OutIndex;
}
}

View File

@@ -0,0 +1,10 @@
namespace SharpCompress.Common.SevenZip
{
internal class CCoderInfo
{
internal CMethodId MethodId;
internal byte[] Props;
internal int NumInStreams;
internal int NumOutStreams;
}
}

View File

@@ -0,0 +1,34 @@
using System;
namespace SharpCompress.Common.SevenZip
{
public class CFileItem
{
public long Size { get; internal set; }
public uint? Attrib { get; internal set; }
public uint? Crc { get; internal set; }
public string Name { get; internal set; }
public bool HasStream { get; internal set; }
public bool IsDir { get; internal set; }
public bool CrcDefined { get { return Crc != null; } }
public bool AttribDefined { get { return Attrib != null; } }
public void SetAttrib(uint attrib)
{
this.Attrib = attrib;
}
public DateTime? CTime { get; internal set; }
public DateTime? ATime { get; internal set; }
public DateTime? MTime { get; internal set; }
public long? StartPos { get; internal set; }
public bool IsAnti { get; internal set; }
internal CFileItem()
{
HasStream = true;
}
}
}

View File

@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using ManagedLzma.LZMA.Master.SevenZip;
using SharpCompress.Compressor.LZMA;
namespace SharpCompress.Common.SevenZip
{
internal class CFolder
{
internal List<CCoderInfo> Coders = new List<CCoderInfo>();
internal List<CBindPair> BindPairs = new List<CBindPair>();
internal List<int> PackStreams = new List<int>();
internal int FirstPackStreamId;
internal List<long> UnpackSizes = new List<long>();
internal uint? UnpackCRC;
internal bool UnpackCRCDefined { get { return UnpackCRC != null; } }
public long GetUnpackSize()
{
if(UnpackSizes.Count == 0)
return 0;
for(int i = UnpackSizes.Count - 1; i >= 0; i--)
if(FindBindPairForOutStream(i) < 0)
return UnpackSizes[i];
throw new Exception();
}
public int GetNumOutStreams()
{
int count = 0;
for(int i = 0; i < Coders.Count; i++)
count += Coders[i].NumOutStreams;
return count;
}
public int FindBindPairForInStream(int inStreamIndex)
{
for(int i = 0; i < BindPairs.Count; i++)
if(BindPairs[i].InIndex == inStreamIndex)
return i;
return -1;
}
public int FindBindPairForOutStream(int outStreamIndex)
{
for(int i = 0; i < BindPairs.Count; i++)
if(BindPairs[i].OutIndex == outStreamIndex)
return i;
return -1;
}
public int FindPackStreamArrayIndex(int inStreamIndex)
{
for(int i = 0; i < PackStreams.Count; i++)
if(PackStreams[i] == inStreamIndex)
return i;
return -1;
}
public bool IsEncrypted()
{
for(int i = Coders.Count - 1; i >= 0; i--)
if(Coders[i].MethodId == CMethodId.kAES)
return true;
return false;
}
public bool CheckStructure()
{
const int kNumCodersMax = 32; // don't change it
const int kMaskSize = 32; // it must be >= kNumCodersMax
const int kNumBindsMax = 32;
if(Coders.Count > kNumCodersMax || BindPairs.Count > kNumBindsMax)
return false;
{
var v = new BitVector(BindPairs.Count + PackStreams.Count);
for(int i = 0; i < BindPairs.Count; i++)
if(v.GetAndSet(BindPairs[i].InIndex))
return false;
for(int i = 0; i < PackStreams.Count; i++)
if(v.GetAndSet(PackStreams[i]))
return false;
}
{
var v = new BitVector(UnpackSizes.Count);
for(int i = 0; i < BindPairs.Count; i++)
if(v.GetAndSet(BindPairs[i].OutIndex))
return false;
}
uint[] mask = new uint[kMaskSize];
{
List<int> inStreamToCoder = new List<int>();
List<int> outStreamToCoder = new List<int>();
for(int i = 0; i < Coders.Count; i++)
{
CCoderInfo coder = Coders[i];
for(int j = 0; j < coder.NumInStreams; j++)
inStreamToCoder.Add(i);
for(int j = 0; j < coder.NumOutStreams; j++)
outStreamToCoder.Add(i);
}
for(int i = 0; i < BindPairs.Count; i++)
{
CBindPair bp = BindPairs[i];
mask[inStreamToCoder[bp.InIndex]] |= (1u << outStreamToCoder[bp.OutIndex]);
}
}
for(int i = 0; i < kMaskSize; i++)
for(int j = 0; j < kMaskSize; j++)
if(((1u << j) & mask[i]) != 0)
mask[i] |= mask[j];
for(int i = 0; i < kMaskSize; i++)
if(((1u << i) & mask[i]) != 0)
return false;
return true;
}
}
}

View File

@@ -0,0 +1,55 @@
namespace SharpCompress.Common.SevenZip
{
internal struct CMethodId
{
public const ulong kCopyId = 0;
public const ulong kLzmaId = 0x030101;
public const ulong kLzma2Id = 0x21;
public const ulong kAESId = 0x06F10701;
public static readonly CMethodId kCopy = new CMethodId(kCopyId);
public static readonly CMethodId kLzma = new CMethodId(kLzmaId);
public static readonly CMethodId kLzma2 = new CMethodId(kLzma2Id);
public static readonly CMethodId kAES = new CMethodId(kAESId);
public readonly ulong Id;
public CMethodId(ulong id)
{
this.Id = id;
}
public override int GetHashCode()
{
return Id.GetHashCode();
}
public override bool Equals(object obj)
{
return obj is CMethodId && (CMethodId)obj == this;
}
public bool Equals(CMethodId other)
{
return Id == other.Id;
}
public static bool operator ==(CMethodId left, CMethodId right)
{
return left.Id == right.Id;
}
public static bool operator !=(CMethodId left, CMethodId right)
{
return left.Id != right.Id;
}
public int GetLength()
{
int bytes = 0;
for(ulong value = Id; value != 0; value >>= 8)
bytes++;
return bytes;
}
}
}

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.IO;
using SharpCompress.Compressor.LZMA;
namespace SharpCompress.Common.SevenZip
{
internal struct CStreamSwitch: IDisposable
{
private ArchiveReader _archive;
private bool _needRemove;
private bool _active;
public void Dispose()
{
if(_active)
{
_active = false;
Log.WriteLine("[end of switch]");
}
if(_needRemove)
{
_needRemove = false;
_archive.DeleteByteStream();
}
}
public void Set(ArchiveReader archive, byte[] dataVector)
{
Dispose();
_archive = archive;
_archive.AddByteStream(dataVector, 0, dataVector.Length);
_needRemove = true;
_active = true;
}
public void Set(ArchiveReader archive, List<byte[]> dataVector)
{
Dispose();
_active = true;
byte external = archive.ReadByte();
if(external != 0)
{
int dataIndex = archive.ReadNum();
if(dataIndex < 0 || dataIndex >= dataVector.Count)
throw new InvalidOperationException();
Log.WriteLine("[switch to stream {0}]", dataIndex);
_archive = archive;
_archive.AddByteStream(dataVector[dataIndex], 0, dataVector[dataIndex].Length);
_needRemove = true;
_active = true;
}
else
{
Log.WriteLine("[inline data]");
}
}
}
}

View File

@@ -0,0 +1,168 @@
using System;
using System.IO;
using System.Text;
using SharpCompress.Compressor.LZMA;
namespace SharpCompress.Common.SevenZip
{
internal class DataReader
{
#region Static Methods
public static uint Get32(byte[] buffer, int offset)
{
return (uint)buffer[offset]
+ ((uint)buffer[offset + 1] << 8)
+ ((uint)buffer[offset + 2] << 16)
+ ((uint)buffer[offset + 3] << 24);
}
public static ulong Get64(byte[] buffer, int offset)
{
return (ulong)buffer[offset]
+ ((ulong)buffer[offset + 1] << 8)
+ ((ulong)buffer[offset + 2] << 16)
+ ((ulong)buffer[offset + 3] << 24)
+ ((ulong)buffer[offset + 4] << 32)
+ ((ulong)buffer[offset + 5] << 40)
+ ((ulong)buffer[offset + 6] << 48)
+ ((ulong)buffer[offset + 7] << 56);
}
#endregion
#region Variables
private byte[] _buffer;
private int _origin;
private int _offset;
private int _ending;
#endregion
#region Public Methods
public DataReader(byte[] buffer, int offset, int length)
{
_buffer = buffer;
_origin = offset;
_offset = offset;
_ending = offset + length;
}
public int Offset
{
get { return _offset; }
}
public Byte ReadByte()
{
if(_offset >= _ending)
throw new EndOfStreamException();
return _buffer[_offset++];
}
public void ReadBytes(byte[] buffer, int offset, int length)
{
if(length > _ending - _offset)
throw new EndOfStreamException();
while(length-- > 0)
buffer[offset++] = _buffer[_offset++];
}
public void SkipData(long size)
{
if(size > _ending - _offset)
throw new EndOfStreamException();
_offset += (int)size;
Log.WriteLine("SkipData {0}", size);
}
public void SkipData()
{
SkipData(checked((long)ReadNumber()));
}
public ulong ReadNumber()
{
if(_offset >= _ending)
throw new EndOfStreamException();
byte firstByte = _buffer[_offset++];
byte mask = 0x80;
ulong value = 0;
for(int i = 0; i < 8; i++)
{
if((firstByte & mask) == 0)
{
ulong highPart = firstByte & (mask - 1u);
value += highPart << (i * 8);
return value;
}
if(_offset >= _ending)
throw new EndOfStreamException();
value |= (ulong)_buffer[_offset++] << (8 * i);
mask >>= 1;
}
return value;
}
public int ReadNum()
{
ulong value = ReadNumber();
if(value > Int32.MaxValue)
throw new NotSupportedException();
return (int)value;
}
public uint ReadUInt32()
{
if(_offset + 4 > _ending)
throw new EndOfStreamException();
uint res = Get32(_buffer, _offset);
_offset += 4;
return res;
}
public ulong ReadUInt64()
{
if(_offset + 8 > _ending)
throw new EndOfStreamException();
ulong res = Get64(_buffer, _offset);
_offset += 8;
return res;
}
public string ReadString()
{
int ending = _offset;
for(; ; )
{
if(ending + 2 > _ending)
throw new EndOfStreamException();
if(_buffer[ending] == 0 && _buffer[ending + 1] == 0)
break;
ending += 2;
}
string str = Encoding.Unicode.GetString(_buffer, _offset, ending - _offset);
_offset = ending + 2;
return str;
}
#endregion
}
}

View File

@@ -22,7 +22,7 @@ namespace SharpCompress.Common.SevenZip
public override uint Crc
{
get { return (uint)FilePart.Header.FileCRC; }
get { return FilePart.Header.Crc ?? 0; }
}
public override string FilePath
@@ -67,7 +67,7 @@ namespace SharpCompress.Common.SevenZip
public override bool IsDirectory
{
get { return FilePart.Header.IsDirectory; }
get { return FilePart.Header.IsDir; }
}
public override bool IsSplit

View File

@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using SharpCompress.IO;
@@ -7,38 +8,56 @@ namespace SharpCompress.Common.SevenZip
internal class SevenZipFilePart : FilePart
{
private CompressionType? type;
private Stream stream;
private ArchiveDatabase database;
internal SevenZipFilePart(SevenZipHeaderFactory factory, int index, HeaderEntry fileEntry, Stream stream)
internal SevenZipFilePart(Stream stream, ArchiveDatabase database, int index, CFileItem fileEntry)
{
this.stream = stream;
this.database = database;
Index = index;
Header = fileEntry;
this.BaseStream = stream;
if (Header.HasStream)
{
Folder = database.Folders[database.FileIndexToFolderIndexMap[index]];
}
}
internal Stream BaseStream { get; private set; }
internal HeaderEntry Header { get; set; }
internal CFileItem Header { get; private set; }
internal CFolder Folder { get; private set; }
internal int Index { get; private set; }
internal override string FilePartName
{
get { return Header.Name; }
}
internal override Stream GetRawStream()
{
return null;
}
internal override Stream GetCompressedStream()
{
if (!Header.HasStream)
{
return null;
}
var stream = Header.Folder.GetStream();
if (Header.FolderOffset > 0)
{
stream.Skip((long)Header.FolderOffset);
}
return new ReadOnlySubStream(stream, (long)Header.Size);
}
var folderStream = database.GetFolderStream(stream, Folder, null);
internal override Stream GetRawStream()
{
return null;
int firstFileIndex = database.FolderStartFileIndex[database.Folders.IndexOf(Folder)];
int skipCount = Index - firstFileIndex;
long skipSize = 0;
for (int i = 0; i < skipCount; i++)
{
skipSize += database.Files[firstFileIndex + i].Size;
}
if (skipSize > 0)
{
folderStream.Skip(skipSize);
}
return new ReadOnlySubStream(folderStream, Header.Size);
}
public CompressionType CompressionType
@@ -47,10 +66,44 @@ namespace SharpCompress.Common.SevenZip
{
if (type == null)
{
this.type = Header.Folder.GetCompressions().First().CompressionType;
type = GetCompression();
}
return type.Value;
}
}
//copied from DecoderRegistry
const uint k_Copy = 0x0;
const uint k_Delta = 3;
const uint k_LZMA2 = 0x21;
const uint k_LZMA = 0x030101;
const uint k_PPMD = 0x030401;
const uint k_BCJ = 0x03030103;
const uint k_BCJ2 = 0x0303011B;
const uint k_Deflate = 0x040108;
const uint k_BZip2 = 0x040202;
internal CompressionType GetCompression()
{
var coder = Folder.Coders.First();
switch (coder.MethodId.Id)
{
case k_LZMA:
case k_LZMA2:
{
return CompressionType.LZMA;
}
case k_PPMD:
{
return CompressionType.PPMd;
}
case k_BZip2:
{
return CompressionType.BZip2;
}
default:
throw new NotImplementedException();
}
}
}
}

View File

@@ -0,0 +1,228 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using SharpCompress.Compressor.LZMA.Utilites;
namespace SharpCompress.Compressor.LZMA
{
internal class AesDecoderStream: DecoderStream2
{
#region Variables
private Stream mStream;
private ICryptoTransform mDecoder;
private byte[] mBuffer;
private long mWritten;
private long mLimit;
private int mOffset;
private int mEnding;
private int mUnderflow;
#endregion
#region Stream Methods
public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
{
mStream = input;
mLimit = limit;
if(((uint)input.Length & 15) != 0)
throw new NotSupportedException("AES decoder does not support padding.");
int numCyclesPower;
byte[] salt, seed;
Init(info, out numCyclesPower, out salt, out seed);
byte[] password = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
byte[] key = InitKey(numCyclesPower, salt, password);
using(var aes = Aes.Create())
{
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.None;
mDecoder = aes.CreateDecryptor(key, seed);
}
mBuffer = new byte[4 << 10];
}
protected override void Dispose(bool disposing)
{
try
{
if(disposing)
{
mStream.Dispose();
mDecoder.Dispose();
}
}
finally
{
base.Dispose(disposing);
}
}
public override long Position
{
get { return mWritten; }
}
public override long Length
{
get { return mLimit; }
}
public override int Read(byte[] buffer, int offset, int count)
{
if(count == 0 || mWritten == mLimit)
return 0;
if(mUnderflow > 0)
return HandleUnderflow(buffer, offset, count);
// Need at least 16 bytes to proceed.
if(mEnding - mOffset < 16)
{
Buffer.BlockCopy(mBuffer, mOffset, mBuffer, 0, mEnding - mOffset);
mEnding -= mOffset;
mOffset = 0;
do
{
int read = mStream.Read(mBuffer, mEnding, mBuffer.Length - mEnding);
if(read == 0)
{
// We are not done decoding and have less than 16 bytes.
throw new EndOfStreamException();
}
mEnding += read;
}
while(mEnding - mOffset < 16);
}
// We shouldn't return more data than we are limited to.
// Currently this is handled by forcing an underflow if
// the stream length is not a multiple of the block size.
if(count > mLimit - mWritten)
count = (int)(mLimit - mWritten);
// We cannot transform less than 16 bytes into the target buffer,
// but we also cannot return zero, so we need to handle this.
// We transform the data locally and use our own buffer as cache.
if(count < 16)
return HandleUnderflow(buffer, offset, count);
if(count > mEnding - mOffset)
count = mEnding - mOffset;
// Otherwise we transform directly into the target buffer.
int processed = mDecoder.TransformBlock(mBuffer, mOffset, count & ~15, buffer, offset);
mOffset += processed;
mWritten += processed;
return processed;
}
#endregion
#region Private Methods
private void Init(byte[] info, out int numCyclesPower, out byte[] salt, out byte[] iv)
{
byte bt = info[0];
numCyclesPower = bt & 0x3F;
if((bt & 0xC0) == 0)
{
salt = new byte[0];
iv = new byte[0];
return;
}
int saltSize = (bt >> 7) & 1;
int ivSize = (bt >> 6) & 1;
if(info.Length == 1)
throw new InvalidOperationException();
byte bt2 = info[1];
saltSize += (bt2 >> 4);
ivSize += (bt2 & 15);
if(info.Length < 2 + saltSize + ivSize)
throw new InvalidOperationException();
salt = new byte[saltSize];
for(int i = 0; i < saltSize; i++)
salt[i] = info[i + 2];
iv = new byte[16];
for(int i = 0; i < ivSize; i++)
iv[i] = info[i + saltSize + 2];
if(numCyclesPower > 24)
throw new NotSupportedException();
}
private byte[] InitKey(int mNumCyclesPower, byte[] salt, byte[] pass)
{
if(mNumCyclesPower == 0x3F)
{
var key = new byte[32];
int pos;
for(pos = 0; pos < salt.Length; pos++)
key[pos] = salt[pos];
for(int i = 0; i < pass.Length && pos < 32; i++)
key[pos++] = pass[i];
return key;
}
else
{
using(var sha = System.Security.Cryptography.SHA256.Create())
{
byte[] counter = new byte[8];
long numRounds = 1L << mNumCyclesPower;
for(long round = 0; round < numRounds; round++)
{
sha.TransformBlock(salt, 0, salt.Length, null, 0);
sha.TransformBlock(pass, 0, pass.Length, null, 0);
sha.TransformBlock(counter, 0, 8, null, 0);
// This mirrors the counter so we don't have to convert long to byte[] each round.
// (It also ensures the counter is little endian, which BitConverter does not.)
for(int i = 0; i < 8; i++)
if(++counter[i] != 0)
break;
}
sha.TransformFinalBlock(counter, 0, 0);
return sha.Hash;
}
}
}
private int HandleUnderflow(byte[] buffer, int offset, int count)
{
// If this is zero we were called to create a new underflow buffer.
// Just transform as much as possible so we can feed from it as long as possible.
if(mUnderflow == 0)
{
int blockSize = (mEnding - mOffset) & ~15;
mUnderflow = mDecoder.TransformBlock(mBuffer, mOffset, blockSize, mBuffer, mOffset);
}
if(count > mUnderflow)
count = mUnderflow;
Buffer.BlockCopy(mBuffer, mOffset, buffer, offset, count);
mWritten += count;
mOffset += count;
mUnderflow -= count;
return count;
}
#endregion
}
}

View File

@@ -0,0 +1,226 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace SharpCompress.Compressor.LZMA
{
class Bcj2DecoderStream: DecoderStream2
{
const int kNumTopBits = 24;
const uint kTopValue = (1 << kNumTopBits);
private class RangeDecoder
{
internal Stream mStream;
internal uint Range;
internal uint Code;
public RangeDecoder(Stream stream)
{
mStream = stream;
Range = 0xFFFFFFFF;
for(int i = 0; i < 5; i++)
Code = (Code << 8) | ReadByte();
}
public byte ReadByte()
{
int bt = mStream.ReadByte();
if(bt < 0)
throw new EndOfStreamException();
return (byte)bt;
}
public void Dispose()
{
mStream.Dispose();
}
}
private class StatusDecoder
{
private const int numMoveBits = 5;
private const int kNumBitModelTotalBits = 11;
private const uint kBitModelTotal = 1u << kNumBitModelTotalBits;
private uint Prob;
public StatusDecoder()
{
Prob = kBitModelTotal / 2;
}
private void UpdateModel(uint symbol)
{
/*
Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;
Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);
*/
if(symbol == 0)
Prob += (kBitModelTotal - Prob) >> numMoveBits;
else
Prob -= (Prob) >> numMoveBits;
}
public uint Decode(RangeDecoder decoder)
{
uint newBound = (decoder.Range >> kNumBitModelTotalBits) * Prob;
if(decoder.Code < newBound)
{
decoder.Range = newBound;
Prob += (kBitModelTotal - Prob) >> numMoveBits;
if(decoder.Range < kTopValue)
{
decoder.Code = (decoder.Code << 8) | decoder.ReadByte();
decoder.Range <<= 8;
}
return 0;
}
else
{
decoder.Range -= newBound;
decoder.Code -= newBound;
Prob -= Prob >> numMoveBits;
if(decoder.Range < kTopValue)
{
decoder.Code = (decoder.Code << 8) | decoder.ReadByte();
decoder.Range <<= 8;
}
return 1;
}
}
}
private Stream mMainStream;
private Stream mCallStream;
private Stream mJumpStream;
private RangeDecoder mRangeDecoder;
private StatusDecoder[] mStatusDecoder;
private long mWritten;
private long mLimit;
private IEnumerator<byte> mIter;
private bool mFinished;
public Bcj2DecoderStream(Stream[] streams, byte[] info, long limit)
{
if(info != null && info.Length > 0)
throw new NotSupportedException();
if(streams.Length != 4)
throw new NotSupportedException();
mLimit = limit;
mMainStream = streams[0];
mCallStream = streams[1];
mJumpStream = streams[2];
mRangeDecoder = new RangeDecoder(streams[3]);
mStatusDecoder = new StatusDecoder[256 + 2];
for(int i = 0; i < mStatusDecoder.Length; i++)
mStatusDecoder[i] = new StatusDecoder();
mIter = Run().GetEnumerator();
}
private static bool IsJcc(byte b0, byte b1)
{
return b0 == 0x0F
&& (b1 & 0xF0) == 0x80;
}
private static bool IsJ(byte b0, byte b1)
{
return (b1 & 0xFE) == 0xE8
|| IsJcc(b0, b1);
}
private static int GetIndex(byte b0, byte b1)
{
if(b1 == 0xE8)
return b0;
else if(b1 == 0xE9)
return 256;
else
return 257;
}
public override int Read(byte[] buffer, int offset, int count)
{
if(count == 0 || mFinished)
return 0;
for(int i = 0; i < count; i++)
{
if(!mIter.MoveNext())
{
mFinished = true;
return i;
}
buffer[offset + i] = mIter.Current;
}
return count;
}
public IEnumerable<byte> Run()
{
const uint kBurstSize = (1u << 18);
byte prevByte = 0;
uint processedBytes = 0;
for(; ; )
{
byte b = 0;
uint i;
for(i = 0; i < kBurstSize; i++)
{
int tmp = mMainStream.ReadByte();
if(tmp < 0)
yield break;
b = (byte)tmp;
mWritten++; yield return b;
if(IsJ(prevByte, b))
break;
prevByte = b;
}
processedBytes += i;
if(i == kBurstSize)
continue;
if(mStatusDecoder[GetIndex(prevByte, b)].Decode(mRangeDecoder) == 1)
{
Stream s = (b == 0xE8) ? mCallStream : mJumpStream;
uint src = 0;
for(i = 0; i < 4; i++)
{
int b0 = s.ReadByte();
if(b0 < 0)
throw new EndOfStreamException();
src <<= 8;
src |= (uint)b0;
}
uint dest = src - (uint)(mWritten + 4);
mWritten++; yield return (byte)dest;
mWritten++; yield return (byte)(dest >> 8);
mWritten++; yield return (byte)(dest >> 16);
mWritten++; yield return (byte)(dest >> 24);
prevByte = (byte)(dest >> 24);
processedBytes += 4;
}
else
{
prevByte = b;
}
}
}
}
}

View File

@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SharpCompress.Compressor.LZMA
{
public class BitVector
{
private uint[] mBits;
private int mLength;
public BitVector(int length)
{
mLength = length;
mBits = new uint[(length + 31) >> 5];
}
public BitVector(int length, bool initValue)
{
mLength = length;
mBits = new uint[(length + 31) >> 5];
if(initValue)
for(int i = 0; i < mBits.Length; i++)
mBits[i] = ~0u;
}
public BitVector(List<bool> bits)
: this(bits.Count)
{
for(int i = 0; i < bits.Count; i++)
if(bits[i])
SetBit(i);
}
public bool[] ToArray()
{
bool[] bits = new bool[mLength];
for(int i = 0; i < bits.Length; i++)
bits[i] = this[i];
return bits;
}
public int Length
{
get { return mLength; }
}
public bool this[int index]
{
get
{
if(index < 0 || index >= mLength)
throw new ArgumentOutOfRangeException("index");
return (mBits[index >> 5] & (1u << (index & 31))) != 0;
}
}
public void SetBit(int index)
{
if(index < 0 || index >= mLength)
throw new ArgumentOutOfRangeException("index");
mBits[index >> 5] |= 1u << (index & 31);
}
internal bool GetAndSet(int index)
{
if(index < 0 || index >= mLength)
throw new ArgumentOutOfRangeException("index");
uint bits = mBits[index >> 5];
uint mask = 1u << (index & 31);
mBits[index >> 5] |= mask;
return (bits & mask) != 0;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder(mLength);
for(int i = 0; i < mLength; i++)
sb.Append(this[i] ? 'x' : '.');
return sb.ToString();
}
}
}

View File

@@ -1,53 +1,111 @@
namespace SharpCompress.Compressor.LZMA
using System;
using System.IO;
namespace ManagedLzma.LZMA.Master.SevenZip
{
internal class CRC
internal static class CRC
{
public static readonly uint[] Table;
public const uint kInitCRC = 0xFFFFFFFF;
private static uint[] kTable = new uint[4 * 256];
static CRC()
{
Table = new uint[256];
const uint kPoly = 0xEDB88320;
for (uint i = 0; i < 256; i++)
const uint kCrcPoly = 0xEDB88320;
for(uint i = 0; i < 256; i++)
{
uint r = i;
for (int j = 0; j < 8; j++)
if ((r & 1) != 0)
r = (r >> 1) ^ kPoly;
else
r >>= 1;
Table[i] = r;
for(int j = 0; j < 8; j++)
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
kTable[i] = r;
}
for(uint i = 256; i < kTable.Length; i++)
{
uint r = kTable[i - 256];
kTable[i] = kTable[r & 0xFF] ^ (r >> 8);
}
}
uint _value = 0xFFFFFFFF;
public void Init() { _value = 0xFFFFFFFF; }
public void UpdateByte(byte b)
public static uint From(Stream stream, long length)
{
_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);
uint crc = kInitCRC;
byte[] buffer = new byte[Math.Min(length, 4 << 10)];
while(length > 0)
{
int delta = stream.Read(buffer, 0, (int)Math.Min(length, buffer.Length));
if(delta == 0)
throw new EndOfStreamException();
crc = Update(crc, buffer, 0, delta);
length -= delta;
}
return Finish(crc);
}
public void Update(byte[] data, uint offset, uint size)
public static uint Finish(uint crc)
{
for (uint i = 0; i < size; i++)
_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);
return ~crc;
}
public uint GetDigest() { return _value ^ 0xFFFFFFFF; }
static uint CalculateDigest(byte[] data, uint offset, uint size)
public static uint Update(uint crc, byte bt)
{
CRC crc = new CRC();
// crc.Init();
crc.Update(data, offset, size);
return crc.GetDigest();
return kTable[(crc & 0xFF) ^ bt] ^ (crc >> 8);
}
static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)
public static uint Update(uint crc, uint value)
{
return (CalculateDigest(data, offset, size) == digest);
crc ^= value;
return kTable[0x300 + (crc & 0xFF)]
^ kTable[0x200 + ((crc >> 8) & 0xFF)]
^ kTable[0x100 + ((crc >> 16) & 0xFF)]
^ kTable[0x000 + (crc >> 24)];
}
public static uint Update(uint crc, ulong value)
{
return Update(Update(crc, (uint)value), (uint)(value >> 32));
}
public static uint Update(uint crc, long value)
{
return Update(crc, (ulong)value);
}
public static uint Update(uint crc, byte[] buffer, int offset, int length)
{
for(int i = 0; i < length; i++)
crc = Update(crc, buffer[offset + i]);
return crc;
}
#if !SILVERLIGHT && !PORTABLE
public static unsafe uint Update(uint crc, byte* buffer, int length)
{
while(length > 0 && ((int)buffer & 3) != 0)
{
crc = Update(crc, *buffer);
buffer++;
length--;
}
while(length >= 4)
{
crc = Update(crc, *(uint*)buffer);
buffer += 4;
length -= 4;
}
while(length > 0)
{
crc = Update(crc, *buffer);
length--;
}
return crc;
}
#endif
}
}

View File

@@ -0,0 +1,53 @@
namespace SharpCompress.Compressor.LZMA
{
internal class CRC
{
public static readonly uint[] Table;
static CRC()
{
Table = new uint[256];
const uint kPoly = 0xEDB88320;
for (uint i = 0; i < 256; i++)
{
uint r = i;
for (int j = 0; j < 8; j++)
if ((r & 1) != 0)
r = (r >> 1) ^ kPoly;
else
r >>= 1;
Table[i] = r;
}
}
uint _value = 0xFFFFFFFF;
public void Init() { _value = 0xFFFFFFFF; }
public void UpdateByte(byte b)
{
_value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8);
}
public void Update(byte[] data, uint offset, uint size)
{
for (uint i = 0; i < size; i++)
_value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8);
}
public uint GetDigest() { return _value ^ 0xFFFFFFFF; }
static uint CalculateDigest(byte[] data, uint offset, uint size)
{
CRC crc = new CRC();
// crc.Init();
crc.Update(data, offset, size);
return crc.GetDigest();
}
static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)
{
return (CalculateDigest(data, offset, size) == digest);
}
}
}

View File

@@ -0,0 +1,173 @@
using System;
using System.IO;
using SharpCompress.Common.SevenZip;
using SharpCompress.Compressor.LZMA.Utilites;
namespace SharpCompress.Compressor.LZMA
{
abstract class DecoderStream2: Stream
{
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite
{
get { return false; }
}
public override void Flush()
{
throw new NotImplementedException();
}
public override long Length
{
get { throw new NotImplementedException(); }
}
public override long Position
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
}
static class DecoderStreamHelper
{
private static int FindCoderIndexForOutStreamIndex(CFolder folderInfo, int outStreamIndex)
{
for(int coderIndex = 0; coderIndex < folderInfo.Coders.Count; coderIndex++)
{
var coderInfo = folderInfo.Coders[coderIndex];
outStreamIndex -= coderInfo.NumOutStreams;
if(outStreamIndex < 0)
return coderIndex;
}
throw new InvalidOperationException("Could not link output stream to coder.");
}
private static void FindPrimaryOutStreamIndex(CFolder folderInfo, out int primaryCoderIndex, out int primaryOutStreamIndex)
{
bool foundPrimaryOutStream = false;
primaryCoderIndex = -1;
primaryOutStreamIndex = -1;
for(int outStreamIndex = 0, coderIndex = 0;
coderIndex < folderInfo.Coders.Count;
coderIndex++)
{
for(int coderOutStreamIndex = 0;
coderOutStreamIndex < folderInfo.Coders[coderIndex].NumOutStreams;
coderOutStreamIndex++, outStreamIndex++)
{
if(folderInfo.FindBindPairForOutStream(outStreamIndex) < 0)
{
if(foundPrimaryOutStream)
throw new NotSupportedException("Multiple output streams.");
foundPrimaryOutStream = true;
primaryCoderIndex = coderIndex;
primaryOutStreamIndex = outStreamIndex;
}
}
}
if(!foundPrimaryOutStream)
throw new NotSupportedException("No output stream.");
}
private static Stream CreateDecoderStream(Stream[] packStreams, long[] packSizes, Stream[] outStreams, CFolder folderInfo, int coderIndex, IPasswordProvider pass)
{
var coderInfo = folderInfo.Coders[coderIndex];
if(coderInfo.NumOutStreams != 1)
throw new NotSupportedException("Multiple output streams are not supported.");
int inStreamId = 0;
for(int i = 0; i < coderIndex; i++)
inStreamId += folderInfo.Coders[i].NumInStreams;
int outStreamId = 0;
for(int i = 0; i < coderIndex; i++)
outStreamId += folderInfo.Coders[i].NumOutStreams;
Stream[] inStreams = new Stream[coderInfo.NumInStreams];
for(int i = 0; i < inStreams.Length; i++, inStreamId++)
{
int bindPairIndex = folderInfo.FindBindPairForInStream(inStreamId);
if(bindPairIndex >= 0)
{
int pairedOutIndex = folderInfo.BindPairs[bindPairIndex].OutIndex;
if(outStreams[pairedOutIndex] != null)
throw new NotSupportedException("Overlapping stream bindings are not supported.");
int otherCoderIndex = FindCoderIndexForOutStreamIndex(folderInfo, pairedOutIndex);
inStreams[i] = CreateDecoderStream(packStreams, packSizes, outStreams, folderInfo, otherCoderIndex, pass);
//inStreamSizes[i] = folderInfo.UnpackSizes[pairedOutIndex];
if(outStreams[pairedOutIndex] != null)
throw new NotSupportedException("Overlapping stream bindings are not supported.");
outStreams[pairedOutIndex] = inStreams[i];
}
else
{
int index = folderInfo.FindPackStreamArrayIndex(inStreamId);
if(index < 0)
throw new NotSupportedException("Could not find input stream binding.");
inStreams[i] = packStreams[index];
//inStreamSizes[i] = packSizes[index];
}
}
long unpackSize = folderInfo.UnpackSizes[outStreamId];
return DecoderRegistry.CreateDecoderStream(coderInfo.MethodId, inStreams, coderInfo.Props, pass, unpackSize);
}
internal static Stream CreateDecoderStream(Stream inStream, long startPos, long[] packSizes, CFolder folderInfo, IPasswordProvider pass)
{
if(!folderInfo.CheckStructure())
throw new NotSupportedException("Unsupported stream binding structure.");
// We have multiple views into the same stream which will be used by several threads - need to sync those.
object sync = new object();
Stream[] inStreams = new Stream[folderInfo.PackStreams.Count];
for(int j = 0; j < folderInfo.PackStreams.Count; j++)
{
inStreams[j] = new SyncStreamView(sync, inStream, startPos, packSizes[j]);
startPos += packSizes[j];
}
Stream[] outStreams = new Stream[folderInfo.UnpackSizes.Count];
int primaryCoderIndex, primaryOutStreamIndex;
FindPrimaryOutStreamIndex(folderInfo, out primaryCoderIndex, out primaryOutStreamIndex);
return CreateDecoderStream(inStreams, packSizes, outStreams, folderInfo, primaryCoderIndex, pass);
}
}
}

View File

@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
namespace SharpCompress.Compressor.LZMA
{
internal static class Log
{
private static Stack<string> _indent = new Stack<string>();
private static bool _needsIndent = true;
static Log()
{
_indent.Push("");
}
public static void PushIndent(string indent = " ")
{
_indent.Push(_indent.Peek() + indent);
}
public static void PopIndent()
{
if(_indent.Count == 1)
throw new InvalidOperationException();
_indent.Pop();
}
private static void EnsureIndent()
{
if(_needsIndent)
{
_needsIndent = false;
#if !SILVERLIGHT && !PORTABLE
System.Diagnostics.Debug.Write(_indent.Peek());
#endif
}
}
public static void Write(object value)
{
EnsureIndent();
#if !SILVERLIGHT && !PORTABLE
System.Diagnostics.Debug.Write(value);
#endif
}
public static void Write(string text)
{
EnsureIndent();
#if !SILVERLIGHT && !PORTABLE
System.Diagnostics.Debug.Write(text);
#endif
}
public static void Write(string format, params object[] args)
{
EnsureIndent();
#if !SILVERLIGHT && !PORTABLE
System.Diagnostics.Debug.Write(string.Format(format, args));
#endif
}
public static void WriteLine()
{
System.Diagnostics.Debug.WriteLine("");
_needsIndent = true;
}
public static void WriteLine(object value)
{
EnsureIndent();
System.Diagnostics.Debug.WriteLine(value);
_needsIndent = true;
}
public static void WriteLine(string text)
{
EnsureIndent();
System.Diagnostics.Debug.WriteLine(text);
_needsIndent = true;
}
public static void WriteLine(string format, params object[] args)
{
EnsureIndent();
System.Diagnostics.Debug.WriteLine(string.Format(format, args));
_needsIndent = true;
}
}
}

View File

@@ -0,0 +1,52 @@
using System;
using System.IO;
using System.Linq;
using SharpCompress.Common.SevenZip;
using SharpCompress.Compressor.BZip2;
using SharpCompress.Compressor.Filters;
using SharpCompress.Compressor.LZMA.Utilites;
using SharpCompress.Compressor.PPMd;
namespace SharpCompress.Compressor.LZMA
{
internal static class DecoderRegistry
{
const uint k_Copy = 0x0;
const uint k_Delta = 3;
const uint k_LZMA2 = 0x21;
const uint k_LZMA = 0x030101;
const uint k_PPMD = 0x030401;
const uint k_BCJ = 0x03030103;
const uint k_BCJ2 = 0x0303011B;
const uint k_Deflate = 0x040108;
const uint k_BZip2 = 0x040202;
internal static Stream CreateDecoderStream(CMethodId id, Stream[] inStreams, byte[] info, IPasswordProvider pass, long limit)
{
switch(id.Id)
{
case k_Copy:
if(info != null)
throw new NotSupportedException();
return inStreams.Single();
case k_LZMA:
case k_LZMA2:
return new LzmaStream(info, inStreams.Single(), -1, limit);
#if !SILVERLIGHT && !PORTABLE
case CMethodId.kAESId:
return new AesDecoderStream(inStreams.Single(), info, pass, limit);
#endif
case k_BCJ:
return new BCJFilter(false, inStreams.Single());
case k_BCJ2:
return new Bcj2DecoderStream(inStreams, info, limit);
case k_BZip2:
return new BZip2Stream(inStreams.Single(), CompressionMode.Decompress, true);
case k_PPMD:
return new PpmdStream(new PpmdProperties(info), inStreams.Single(), false );
default:
throw new NotSupportedException();
}
}
}
}

View File

@@ -0,0 +1,197 @@
using System;
using System.IO;
namespace SharpCompress.Compressor.LZMA.Utilites
{
class CrcBuilderStream: Stream
{
private long mProcessed;
private Stream mTarget;
private uint mCRC;
private bool mFinished;
public CrcBuilderStream(Stream target)
{
mTarget = target;
mCRC = ManagedLzma.LZMA.Master.SevenZip.CRC.kInitCRC;
}
public long Processed
{
get { return mProcessed; }
}
public uint Finish()
{
if(!mFinished)
{
mFinished = true;
mCRC = ManagedLzma.LZMA.Master.SevenZip.CRC.Finish(mCRC);
}
return mCRC;
}
public override bool CanRead
{
get { return false; }
}
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite
{
get { return true; }
}
public override void Flush()
{
}
public override long Length
{
get { throw new NotSupportedException(); }
}
public override long Position
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public override int Read(byte[] buffer, int offset, int count)
{
throw new InvalidOperationException();
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override void SetLength(long value)
{
throw new NotSupportedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
if(mFinished)
throw new InvalidOperationException("CRC calculation has been finished.");
mProcessed += count;
mCRC = ManagedLzma.LZMA.Master.SevenZip.CRC.Update(mCRC, buffer, offset, count);
mTarget.Write(buffer, offset, count);
}
}
class ReadingCrcBuilderStream: Stream
{
private long mProcessed;
private Stream mSource;
private uint mCRC;
private bool mFinished;
public ReadingCrcBuilderStream(Stream source)
{
mSource = source;
mCRC = ManagedLzma.LZMA.Master.SevenZip.CRC.kInitCRC;
}
protected override void Dispose(bool disposing)
{
try
{
if(disposing)
mSource.Dispose();
}
finally
{
base.Dispose(disposing);
}
}
public long Processed
{
get { return mProcessed; }
}
public uint Finish()
{
if(!mFinished)
{
mFinished = true;
mCRC = ManagedLzma.LZMA.Master.SevenZip.CRC.Finish(mCRC);
}
return mCRC;
}
public override bool CanRead
{
get { return mSource.CanRead; }
}
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite
{
get { return false; }
}
public override void Flush()
{
throw new NotImplementedException();
}
public override long Length
{
get { throw new NotImplementedException(); }
}
public override long Position
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public override int Read(byte[] buffer, int offset, int count)
{
if(count > 0 && !mFinished)
{
int read = mSource.Read(buffer, offset, count);
if(read > 0)
{
mProcessed += read;
mCRC = ManagedLzma.LZMA.Master.SevenZip.CRC.Update(mCRC, buffer, offset, read);
return read;
}
Finish();
}
return 0;
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,114 @@
using System;
using System.IO;
namespace SharpCompress.Compressor.LZMA.Utilites
{
class CrcCheckStream: Stream
{
private readonly uint mExpectedCRC;
private uint mCurrentCRC;
private bool mClosed;
private long[] mBytes = new long[256];
private long mLength;
public CrcCheckStream(uint crc)
{
mExpectedCRC = crc;
mCurrentCRC = ManagedLzma.LZMA.Master.SevenZip.CRC.kInitCRC;
}
protected override void Dispose(bool disposing)
{
if (mCurrentCRC != mExpectedCRC)
throw new InvalidOperationException();
try
{
if(disposing && !mClosed)
{
mClosed = true;
mCurrentCRC = ManagedLzma.LZMA.Master.SevenZip.CRC.Finish(mCurrentCRC);
#if DEBUG
if(mCurrentCRC == mExpectedCRC)
System.Diagnostics.Debug.WriteLine("CRC ok: " + mExpectedCRC.ToString("x8"));
else
{
System.Diagnostics.Debugger.Break();
System.Diagnostics.Debug.WriteLine("bad CRC");
}
double lengthInv = 1.0 / mLength;
double entropy = 0;
for(int i = 0; i < 256; i++)
{
if(mBytes[i] != 0)
{
double p = lengthInv * mBytes[i];
entropy -= p * Math.Log(p, 256);
}
}
System.Diagnostics.Debug.WriteLine("entropy: " + (int)(entropy * 100) + "%");
#endif
}
}
finally
{
base.Dispose(disposing);
}
}
public override bool CanRead
{
get { return false; }
}
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite
{
get { return true; }
}
public override void Flush()
{
}
public override long Length
{
get { throw new NotSupportedException(); }
}
public override long Position
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public override int Read(byte[] buffer, int offset, int count)
{
throw new InvalidOperationException();
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override void SetLength(long value)
{
throw new NotSupportedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
mLength += count;
for(int i = 0; i < count; i++)
mBytes[buffer[offset + i]]++;
mCurrentCRC = ManagedLzma.LZMA.Master.SevenZip.CRC.Update(mCurrentCRC, buffer, offset, count);
}
}
}

View File

@@ -0,0 +1,7 @@
namespace SharpCompress.Compressor.LZMA.Utilites
{
public interface IPasswordProvider
{
string CryptoGetTextPassword();
}
}

View File

@@ -0,0 +1,108 @@
using System;
using System.IO;
namespace SharpCompress.Compressor.LZMA.Utilites
{
/// <summary>
/// Allows reading the same stream from multiple threads by synchronizing read access.
/// </summary>
class SyncStreamView: Stream
{
private object mSync;
private Stream mStream;
private long mOrigin;
private long mEnding;
private long mOffset;
public SyncStreamView(object sync, Stream stream, long origin, long length)
{
mSync = sync;
mStream = stream;
mOrigin = origin;
mEnding = checked(origin + length);
mOffset = 0;
}
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return true; }
}
public override bool CanWrite
{
get { return false; }
}
public override void Flush()
{
throw new InvalidOperationException();
}
public override long Length
{
get { return mEnding - mOrigin; }
}
public override long Position
{
get { return mOffset; }
set
{
if(value < 0 || value > Length)
throw new ArgumentOutOfRangeException("value");
mOffset = value;
}
}
public override int Read(byte[] buffer, int offset, int count)
{
long remaining = mEnding - mOrigin - mOffset;
if(count > remaining)
count = (int)remaining;
if(count == 0)
return 0;
int delta;
lock(mSync)
{
mStream.Position = mOrigin + mOffset;
delta = mStream.Read(buffer, offset, count);
}
mOffset += delta;
return delta;
}
public override long Seek(long offset, SeekOrigin origin)
{
switch(origin)
{
case SeekOrigin.Begin:
return Position = offset;
case SeekOrigin.Current:
return Position += offset;
case SeekOrigin.End:
return Position = Length + offset;
default:
throw new ArgumentOutOfRangeException("origin");
}
}
public override void SetLength(long value)
{
throw new InvalidOperationException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new InvalidOperationException();
}
}
}

View File

@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace master._7zip.Utilities
{
/// <remarks>
/// This stream is a length-constrained wrapper around a cached stream so it does not dispose the inner stream.
/// </remarks>
internal class UnpackSubStream: Stream
{
private Stream mSource;
private long mLength;
private long mOffset;
internal UnpackSubStream(Stream source, long length)
{
mSource = source;
mLength = length;
}
public override bool CanRead
{
get { return mSource.CanRead; }
}
public override bool CanSeek
{
get { return false; }
}
public override bool CanWrite
{
get { return false; }
}
public override void Flush()
{
throw new NotSupportedException();
}
public override long Length
{
get { return mLength; }
}
public override long Position
{
get { return mOffset; }
set { throw new NotSupportedException(); }
}
public override int Read(byte[] buffer, int offset, int count)
{
if(buffer == null)
throw new ArgumentNullException("buffer");
if(offset < 0 || offset > buffer.Length)
throw new ArgumentOutOfRangeException("offset");
if(count < 0 || count > buffer.Length - offset)
throw new ArgumentOutOfRangeException("count");
if(count > mLength - mOffset)
count = (int)(mLength - mOffset);
if(count == 0)
return 0;
int processed = mSource.Read(buffer, offset, count);
if(processed == 0)
throw new EndOfStreamException("Decoded stream ended prematurely, unpacked data is corrupt.");
mOffset += processed;
return processed;
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override void SetLength(long value)
{
throw new NotSupportedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
}
}

View File

@@ -0,0 +1,80 @@
using System;
using System.Diagnostics;
using System.IO;
namespace SharpCompress.Compressor.LZMA.Utilites
{
internal enum BlockType: byte
{
#region Constants
End = 0,
Header = 1,
ArchiveProperties = 2,
AdditionalStreamsInfo = 3,
MainStreamsInfo = 4,
FilesInfo = 5,
PackInfo = 6,
UnpackInfo = 7,
SubStreamsInfo = 8,
Size = 9,
CRC = 10,
Folder = 11,
CodersUnpackSize = 12,
NumUnpackStream = 13,
EmptyStream = 14,
EmptyFile = 15,
Anti = 16,
Name = 17,
CTime = 18,
ATime = 19,
MTime = 20,
WinAttributes = 21,
Comment = 22,
EncodedHeader = 23,
StartPos = 24,
Dummy = 25,
#endregion
}
internal static class Utils
{
[Conditional("DEBUG")]
public static void Assert(bool expression)
{
if(!expression)
{
if(Debugger.IsAttached)
Debugger.Break();
throw new Exception("Assertion failed.");
}
}
public static void ReadExact(this Stream stream, byte[] buffer, int offset, int length)
{
if(stream == null)
throw new ArgumentNullException("stream");
if(buffer == null)
throw new ArgumentNullException("buffer");
if(offset < 0 || offset > buffer.Length)
throw new ArgumentOutOfRangeException("offset");
if(length < 0 || length > buffer.Length - offset)
throw new ArgumentOutOfRangeException("length");
while(length > 0)
{
int fetched = stream.Read(buffer, offset, length);
if(fetched <= 0)
throw new EndOfStreamException();
offset += fetched;
length -= fetched;
}
}
}
}

View File

@@ -127,15 +127,18 @@
<Compile Include="Common\Rar\RarEntry.cs" />
<Compile Include="Common\Rar\RarFilePart.cs" />
<Compile Include="Common\Rar\RarVolume.cs" />
<Compile Include="Common\SevenZip\FileEntry.cs" />
<Compile Include="Common\SevenZip\Folder.cs" />
<Compile Include="Common\SevenZip\HeaderBuffer.cs" />
<Compile Include="Common\SevenZip\HeaderProperty.cs" />
<Compile Include="Common\SevenZip\ArchiveDatabase.cs" />
<Compile Include="Common\SevenZip\ArchiveReader.cs" />
<Compile Include="Common\SevenZip\CBindPair.cs" />
<Compile Include="Common\SevenZip\CCoderInfo.cs" />
<Compile Include="Common\SevenZip\CFileItem.cs" />
<Compile Include="Common\SevenZip\CFolder.cs" />
<Compile Include="Common\SevenZip\CMethodId.cs" />
<Compile Include="Common\SevenZip\CStreamSwitch.cs" />
<Compile Include="Common\SevenZip\DataReader.cs" />
<Compile Include="Common\SevenZip\SevenZipEntry.cs" />
<Compile Include="Common\SevenZip\SevenZipFilePart.cs" />
<Compile Include="Common\SevenZip\SevenZipHeaderFactory.cs" />
<Compile Include="Common\SevenZip\SevenZipVolume.cs" />
<Compile Include="Common\SevenZip\StreamsInfo.cs" />
<Compile Include="Common\Tar\Headers\TarHeader.cs" />
<Compile Include="Common\Tar\TarEntry.cs" />
<Compile Include="Common\Tar\TarFilePart.cs" />
@@ -189,8 +192,14 @@
<Compile Include="Compressor\Filters\BCJ2Filter.cs" />
<Compile Include="Compressor\Filters\BCJFilter.cs" />
<Compile Include="Compressor\Filters\Filter.cs" />
<Compile Include="Compressor\LZMA\AesDecoderStream.cs" />
<Compile Include="Compressor\LZMA\Bcj2DecoderStream.cs" />
<Compile Include="Compressor\LZMA\BitVector.cs" />
<Compile Include="Compressor\LZMA\CRC.cs" />
<Compile Include="Compressor\LZMA\CRC2.cs" />
<Compile Include="Compressor\LZMA\DecoderStream.cs" />
<Compile Include="Compressor\LZMA\ICoder.cs" />
<Compile Include="Compressor\LZMA\Log.cs" />
<Compile Include="Compressor\LZMA\LzmaEncoderProperties.cs" />
<Compile Include="Compressor\LZMA\LzmaStream.cs" />
<Compile Include="Compressor\LZMA\LZ\LzBinTree.cs" />
@@ -202,6 +211,13 @@
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoder.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBit.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBitTree.cs" />
<Compile Include="Compressor\LZMA\Registry.cs" />
<Compile Include="Compressor\LZMA\Utilites\CrcBuilderStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\CrcCheckStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\IPasswordProvider.cs" />
<Compile Include="Compressor\LZMA\Utilites\SyncStreamView.cs" />
<Compile Include="Compressor\LZMA\Utilites\UnpackSubStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\Utils.cs" />
<Compile Include="Compressor\PPMd\I1\Allocator.cs" />
<Compile Include="Compressor\PPMd\I1\Coder.cs" />
<Compile Include="Compressor\PPMd\I1\MemoryNode.cs" />

View File

@@ -142,15 +142,18 @@
<Compile Include="Common\Rar\RarEntry.cs" />
<Compile Include="Common\Rar\RarFilePart.cs" />
<Compile Include="Common\Rar\RarVolume.cs" />
<Compile Include="Common\SevenZip\FileEntry.cs" />
<Compile Include="Common\SevenZip\Folder.cs" />
<Compile Include="Common\SevenZip\HeaderBuffer.cs" />
<Compile Include="Common\SevenZip\HeaderProperty.cs" />
<Compile Include="Common\SevenZip\ArchiveDatabase.cs" />
<Compile Include="Common\SevenZip\ArchiveReader.cs" />
<Compile Include="Common\SevenZip\CBindPair.cs" />
<Compile Include="Common\SevenZip\CCoderInfo.cs" />
<Compile Include="Common\SevenZip\CFileItem.cs" />
<Compile Include="Common\SevenZip\CFolder.cs" />
<Compile Include="Common\SevenZip\CMethodId.cs" />
<Compile Include="Common\SevenZip\CStreamSwitch.cs" />
<Compile Include="Common\SevenZip\DataReader.cs" />
<Compile Include="Common\SevenZip\SevenZipEntry.cs" />
<Compile Include="Common\SevenZip\SevenZipFilePart.cs" />
<Compile Include="Common\SevenZip\SevenZipHeaderFactory.cs" />
<Compile Include="Common\SevenZip\SevenZipVolume.cs" />
<Compile Include="Common\SevenZip\StreamsInfo.cs" />
<Compile Include="Common\Tar\Headers\TarHeader.cs" />
<Compile Include="Common\Tar\TarEntry.cs" />
<Compile Include="Common\Tar\TarFilePart.cs" />
@@ -204,8 +207,13 @@
<Compile Include="Compressor\Filters\BCJ2Filter.cs" />
<Compile Include="Compressor\Filters\BCJFilter.cs" />
<Compile Include="Compressor\Filters\Filter.cs" />
<Compile Include="Compressor\LZMA\Bcj2DecoderStream.cs" />
<Compile Include="Compressor\LZMA\BitVector.cs" />
<Compile Include="Compressor\LZMA\CRC.cs" />
<Compile Include="Compressor\LZMA\CRC2.cs" />
<Compile Include="Compressor\LZMA\DecoderStream.cs" />
<Compile Include="Compressor\LZMA\ICoder.cs" />
<Compile Include="Compressor\LZMA\Log.cs" />
<Compile Include="Compressor\LZMA\LzmaEncoderProperties.cs" />
<Compile Include="Compressor\LZMA\LzmaStream.cs" />
<Compile Include="Compressor\LZMA\LZ\LzBinTree.cs" />
@@ -217,6 +225,13 @@
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoder.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBit.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBitTree.cs" />
<Compile Include="Compressor\LZMA\Registry.cs" />
<Compile Include="Compressor\LZMA\Utilites\CrcBuilderStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\CrcCheckStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\IPasswordProvider.cs" />
<Compile Include="Compressor\LZMA\Utilites\SyncStreamView.cs" />
<Compile Include="Compressor\LZMA\Utilites\UnpackSubStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\Utils.cs" />
<Compile Include="Compressor\PPMd\H\FreqData.cs" />
<Compile Include="Compressor\PPMd\H\ModelPPM.cs" />
<Compile Include="Compressor\PPMd\H\Pointer.cs" />

View File

@@ -114,15 +114,18 @@
<Compile Include="Common\Rar\RarEntry.cs" />
<Compile Include="Common\Rar\RarFilePart.cs" />
<Compile Include="Common\Rar\RarVolume.cs" />
<Compile Include="Common\SevenZip\FileEntry.cs" />
<Compile Include="Common\SevenZip\Folder.cs" />
<Compile Include="Common\SevenZip\HeaderBuffer.cs" />
<Compile Include="Common\SevenZip\HeaderProperty.cs" />
<Compile Include="Common\SevenZip\ArchiveDatabase.cs" />
<Compile Include="Common\SevenZip\ArchiveReader.cs" />
<Compile Include="Common\SevenZip\CBindPair.cs" />
<Compile Include="Common\SevenZip\CCoderInfo.cs" />
<Compile Include="Common\SevenZip\CFileItem.cs" />
<Compile Include="Common\SevenZip\CFolder.cs" />
<Compile Include="Common\SevenZip\CMethodId.cs" />
<Compile Include="Common\SevenZip\CStreamSwitch.cs" />
<Compile Include="Common\SevenZip\DataReader.cs" />
<Compile Include="Common\SevenZip\SevenZipEntry.cs" />
<Compile Include="Common\SevenZip\SevenZipFilePart.cs" />
<Compile Include="Common\SevenZip\SevenZipHeaderFactory.cs" />
<Compile Include="Common\SevenZip\SevenZipVolume.cs" />
<Compile Include="Common\SevenZip\StreamsInfo.cs" />
<Compile Include="Common\Tar\Headers\TarHeader.cs" />
<Compile Include="Common\Tar\TarEntry.cs" />
<Compile Include="Common\Tar\TarFilePart.cs" />
@@ -173,8 +176,13 @@
<Compile Include="Compressor\Filters\BCJ2Filter.cs" />
<Compile Include="Compressor\Filters\BCJFilter.cs" />
<Compile Include="Compressor\Filters\Filter.cs" />
<Compile Include="Compressor\LZMA\Bcj2DecoderStream.cs" />
<Compile Include="Compressor\LZMA\BitVector.cs" />
<Compile Include="Compressor\LZMA\CRC.cs" />
<Compile Include="Compressor\LZMA\CRC2.cs" />
<Compile Include="Compressor\LZMA\DecoderStream.cs" />
<Compile Include="Compressor\LZMA\ICoder.cs" />
<Compile Include="Compressor\LZMA\Log.cs" />
<Compile Include="Compressor\LZMA\LzmaEncoderProperties.cs" />
<Compile Include="Compressor\LZMA\LzmaStream.cs" />
<Compile Include="Compressor\LZMA\LZ\LzBinTree.cs" />
@@ -186,6 +194,13 @@
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoder.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBit.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBitTree.cs" />
<Compile Include="Compressor\LZMA\Registry.cs" />
<Compile Include="Compressor\LZMA\Utilites\CrcBuilderStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\CrcCheckStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\IPasswordProvider.cs" />
<Compile Include="Compressor\LZMA\Utilites\SyncStreamView.cs" />
<Compile Include="Compressor\LZMA\Utilites\UnpackSubStream.cs" />
<Compile Include="Compressor\LZMA\Utilites\Utils.cs" />
<Compile Include="Compressor\PPMd\H\FreqData.cs" />
<Compile Include="Compressor\PPMd\H\ModelPPM.cs" />
<Compile Include="Compressor\PPMd\H\Pointer.cs" />

View File

@@ -50,7 +50,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;DISABLE_TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -116,13 +116,6 @@
<Compile Include="Common\IncompleteArchiveException.cs" />
<Compile Include="Common\MultiVolumeExtractionException.cs" />
<Compile Include="Common\PasswordProtectedException.cs" />
<Compile Include="Common\SevenZip\FileEntry.cs" />
<Compile Include="Common\SevenZip\Folder.cs" />
<Compile Include="Common\SevenZip\HeaderBuffer.cs" />
<Compile Include="Common\SevenZip\HeaderProperty.cs" />
<Compile Include="Common\SevenZip\SevenZipEntry.cs" />
<Compile Include="Common\SevenZip\SevenZipFilePart.cs" />
<Compile Include="Common\SevenZip\SevenZipHeaderFactory.cs" />
<Compile Include="Common\CryptographicException.cs" />
<Compile Include="Common\FlagUtility.cs" />
<Compile Include="Common\GZip\GZipEntry.cs" />
@@ -133,7 +126,14 @@
<Compile Include="Common\Entry.cs" />
<Compile Include="Common\IEntry.cs" />
<Compile Include="Common\IVolume.cs" />
<Compile Include="Common\SevenZip\StreamsInfo.cs" />
<Compile Include="Common\SevenZip\CBindPair.cs" />
<Compile Include="Common\SevenZip\CCoderInfo.cs" />
<Compile Include="Common\SevenZip\CFileItem.cs" />
<Compile Include="Common\SevenZip\CFolder.cs" />
<Compile Include="Common\SevenZip\CStreamSwitch.cs" />
<Compile Include="Common\SevenZip\DataReader.cs" />
<Compile Include="Common\SevenZip\SevenZipEntry.cs" />
<Compile Include="Common\SevenZip\SevenZipFilePart.cs" />
<Compile Include="Common\SevenZip\SevenZipVolume.cs" />
<Compile Include="Common\Tar\Headers\TarHeader.cs" />
<Compile Include="Common\Tar\TarReadOnlySubStream.cs" />
@@ -169,9 +169,48 @@
<Compile Include="Compressor\Filters\BCJ2Filter.cs" />
<Compile Include="Compressor\Filters\BCJFilter.cs" />
<Compile Include="Compressor\Filters\Filter.cs" />
<Compile Include="Compressor\LZMA\BitVector.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\CRC2.cs" />
<Compile Include="Compressor\LZMA\CRC.cs" />
<Compile Include="Common\SevenZip\ArchiveDatabase.cs" />
<Compile Include="Common\SevenZip\ArchiveReader.cs" />
<Compile Include="Common\SevenZip\CMethodId.cs" />
<Compile Include="Compressor\LZMA\AesDecoderStream.cs" />
<Compile Include="Compressor\LZMA\Bcj2DecoderStream.cs" />
<Compile Include="Compressor\LZMA\DecoderStream.cs" />
<Compile Include="Compressor\LZMA\Registry.cs" />
<Compile Include="Compressor\LZMA\ICoder.cs" />
<Compile Include="Compressor\LZMA\Log.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\LzmaBase.cs" />
<Compile Include="Compressor\LZMA\LzmaDecoder.cs" />
<Compile Include="Compressor\LZMA\LzmaEncoder.cs" />
<Compile Include="Compressor\LZMA\LzmaEncoderProperties.cs" />
<Compile Include="Compressor\LZMA\LzmaStream.cs" />
<Compile Include="Compressor\LZMA\LZ\LzBinTree.cs" />
<Compile Include="Compressor\LZMA\LZ\LzInWindow.cs" />
<Compile Include="Compressor\LZMA\LZ\LzOutWindow.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoder.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBit.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBitTree.cs" />
<Compile Include="Compressor\LZMA\Utilites\CrcBuilderStream.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\CrcCheckStream.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\IPasswordProvider.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\SyncStreamView.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\LZMA\Utilites\Utils.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Compressor\PPMd\H\FreqData.cs" />
<Compile Include="Compressor\PPMd\H\ModelPPM.cs" />
<Compile Include="Compressor\PPMd\H\Pointer.cs" />
@@ -218,16 +257,6 @@
<Compile Include="Compressor\Deflate\ZlibCodec.cs" />
<Compile Include="Compressor\Deflate\ZlibConstants.cs" />
<Compile Include="Compressor\Deflate\ZlibStream.cs" />
<Compile Include="Compressor\LZMA\ICoder.cs" />
<Compile Include="Compressor\LZMA\LZ\LzBinTree.cs" />
<Compile Include="Compressor\LZMA\LZ\LzInWindow.cs" />
<Compile Include="Compressor\LZMA\LzmaBase.cs" />
<Compile Include="Compressor\LZMA\LzmaDecoder.cs" />
<Compile Include="Compressor\LZMA\LzmaEncoder.cs" />
<Compile Include="Compressor\LZMA\LZ\LzOutWindow.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoder.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBit.cs" />
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBitTree.cs" />
<Compile Include="Common\Rar\Headers\FileNameDecoder.cs" />
<Compile Include="Common\InvalidFormatException.cs" />
<Compile Include="IO\ReadOnlySubStream.cs" />
@@ -342,6 +371,7 @@
<ItemGroup>
<None Include="SharpCompress.pfx" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.