scripts
This commit is contained in:
@@ -0,0 +1,477 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using ICSharpCode.SharpZipLib.Checksums;
|
||||
using ICSharpCode.SharpZipLib.Encryption;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
|
||||
|
||||
namespace ICSharpCode.SharpZipLib.Zip
|
||||
{
|
||||
// Token: 0x0200007D RID: 125
|
||||
public class ZipInputStream : InflaterInputStream
|
||||
{
|
||||
// Token: 0x060004CD RID: 1229 RVA: 0x00017412 File Offset: 0x00016412
|
||||
public ZipInputStream(Stream baseInputStream)
|
||||
: base(baseInputStream, new Inflater(true))
|
||||
{
|
||||
this.internalReader = new ZipInputStream.ReadDataHandler(this.ReadingNotAvailable);
|
||||
}
|
||||
|
||||
// Token: 0x060004CE RID: 1230 RVA: 0x0001743E File Offset: 0x0001643E
|
||||
public ZipInputStream(Stream baseInputStream, int bufferSize)
|
||||
: base(baseInputStream, new Inflater(true), bufferSize)
|
||||
{
|
||||
this.internalReader = new ZipInputStream.ReadDataHandler(this.ReadingNotAvailable);
|
||||
}
|
||||
|
||||
// Token: 0x1700011C RID: 284
|
||||
// (get) Token: 0x060004CF RID: 1231 RVA: 0x0001746B File Offset: 0x0001646B
|
||||
// (set) Token: 0x060004D0 RID: 1232 RVA: 0x00017473 File Offset: 0x00016473
|
||||
public string Password
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.password;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.password = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700011D RID: 285
|
||||
// (get) Token: 0x060004D1 RID: 1233 RVA: 0x0001747C File Offset: 0x0001647C
|
||||
public bool CanDecompressEntry
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.entry != null && this.entry.CanDecompress;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060004D2 RID: 1234 RVA: 0x00017494 File Offset: 0x00016494
|
||||
public ZipEntry GetNextEntry()
|
||||
{
|
||||
if (this.crc == null)
|
||||
{
|
||||
throw new InvalidOperationException("Closed.");
|
||||
}
|
||||
if (this.entry != null)
|
||||
{
|
||||
this.CloseEntry();
|
||||
}
|
||||
int num = this.inputBuffer.ReadLeInt();
|
||||
if (num == 33639248 || num == 101010256 || num == 84233040 || num == 117853008 || num == 101075792)
|
||||
{
|
||||
this.Close();
|
||||
return null;
|
||||
}
|
||||
if (num == 808471376 || num == 134695760)
|
||||
{
|
||||
num = this.inputBuffer.ReadLeInt();
|
||||
}
|
||||
if (num != 67324752)
|
||||
{
|
||||
throw new ZipException("Wrong Local header signature: 0x" + string.Format("{0:X}", num));
|
||||
}
|
||||
short num2 = (short)this.inputBuffer.ReadLeShort();
|
||||
this.flags = this.inputBuffer.ReadLeShort();
|
||||
this.method = this.inputBuffer.ReadLeShort();
|
||||
uint num3 = (uint)this.inputBuffer.ReadLeInt();
|
||||
int num4 = this.inputBuffer.ReadLeInt();
|
||||
this.csize = (long)this.inputBuffer.ReadLeInt();
|
||||
this.size = (long)this.inputBuffer.ReadLeInt();
|
||||
int num5 = this.inputBuffer.ReadLeShort();
|
||||
int num6 = this.inputBuffer.ReadLeShort();
|
||||
bool flag = (this.flags & 1) == 1;
|
||||
byte[] array = new byte[num5];
|
||||
this.inputBuffer.ReadRawBuffer(array);
|
||||
string text = ZipConstants.ConvertToStringExt(this.flags, array);
|
||||
this.entry = new ZipEntry(text, (int)num2);
|
||||
this.entry.Flags = this.flags;
|
||||
this.entry.CompressionMethod = (CompressionMethod)this.method;
|
||||
if ((this.flags & 8) == 0)
|
||||
{
|
||||
this.entry.Crc = (long)num4 & (long)((ulong)(-1));
|
||||
this.entry.Size = this.size & (long)((ulong)(-1));
|
||||
this.entry.CompressedSize = this.csize & (long)((ulong)(-1));
|
||||
this.entry.CryptoCheckValue = (byte)((num4 >> 24) & 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (num4 != 0)
|
||||
{
|
||||
this.entry.Crc = (long)num4 & (long)((ulong)(-1));
|
||||
}
|
||||
if (this.size != 0L)
|
||||
{
|
||||
this.entry.Size = this.size & (long)((ulong)(-1));
|
||||
}
|
||||
if (this.csize != 0L)
|
||||
{
|
||||
this.entry.CompressedSize = this.csize & (long)((ulong)(-1));
|
||||
}
|
||||
this.entry.CryptoCheckValue = (byte)((num3 >> 8) & 255U);
|
||||
}
|
||||
this.entry.DosTime = (long)((ulong)num3);
|
||||
if (num6 > 0)
|
||||
{
|
||||
byte[] array2 = new byte[num6];
|
||||
this.inputBuffer.ReadRawBuffer(array2);
|
||||
this.entry.ExtraData = array2;
|
||||
}
|
||||
this.entry.ProcessExtraData(true);
|
||||
if (this.entry.CompressedSize >= 0L)
|
||||
{
|
||||
this.csize = this.entry.CompressedSize;
|
||||
}
|
||||
if (this.entry.Size >= 0L)
|
||||
{
|
||||
this.size = this.entry.Size;
|
||||
}
|
||||
if (this.method == 0 && ((!flag && this.csize != this.size) || (flag && this.csize - 12L != this.size)))
|
||||
{
|
||||
throw new ZipException("Stored, but compressed != uncompressed");
|
||||
}
|
||||
if (this.entry.IsCompressionMethodSupported())
|
||||
{
|
||||
this.internalReader = new ZipInputStream.ReadDataHandler(this.InitialRead);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.internalReader = new ZipInputStream.ReadDataHandler(this.ReadingNotSupported);
|
||||
}
|
||||
return this.entry;
|
||||
}
|
||||
|
||||
// Token: 0x060004D3 RID: 1235 RVA: 0x000177E0 File Offset: 0x000167E0
|
||||
private void ReadDataDescriptor()
|
||||
{
|
||||
if (this.inputBuffer.ReadLeInt() != 134695760)
|
||||
{
|
||||
throw new ZipException("Data descriptor signature not found");
|
||||
}
|
||||
this.entry.Crc = (long)this.inputBuffer.ReadLeInt() & (long)((ulong)(-1));
|
||||
if (this.entry.LocalHeaderRequiresZip64)
|
||||
{
|
||||
this.csize = this.inputBuffer.ReadLeLong();
|
||||
this.size = this.inputBuffer.ReadLeLong();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.csize = (long)this.inputBuffer.ReadLeInt();
|
||||
this.size = (long)this.inputBuffer.ReadLeInt();
|
||||
}
|
||||
this.entry.CompressedSize = this.csize;
|
||||
this.entry.Size = this.size;
|
||||
}
|
||||
|
||||
// Token: 0x060004D4 RID: 1236 RVA: 0x0001789C File Offset: 0x0001689C
|
||||
private void CompleteCloseEntry(bool testCrc)
|
||||
{
|
||||
base.StopDecrypting();
|
||||
if ((this.flags & 8) != 0)
|
||||
{
|
||||
this.ReadDataDescriptor();
|
||||
}
|
||||
this.size = 0L;
|
||||
if (testCrc && (this.crc.Value & (long)((ulong)(-1))) != this.entry.Crc && this.entry.Crc != -1L)
|
||||
{
|
||||
throw new ZipException("CRC mismatch");
|
||||
}
|
||||
this.crc.Reset();
|
||||
if (this.method == 8)
|
||||
{
|
||||
this.inf.Reset();
|
||||
}
|
||||
this.entry = null;
|
||||
}
|
||||
|
||||
// Token: 0x060004D5 RID: 1237 RVA: 0x00017928 File Offset: 0x00016928
|
||||
public void CloseEntry()
|
||||
{
|
||||
if (this.crc == null)
|
||||
{
|
||||
throw new InvalidOperationException("Closed");
|
||||
}
|
||||
if (this.entry == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (this.method == 8)
|
||||
{
|
||||
if ((this.flags & 8) != 0)
|
||||
{
|
||||
byte[] array = new byte[4096];
|
||||
while (this.Read(array, 0, array.Length) > 0)
|
||||
{
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.csize -= this.inf.TotalIn;
|
||||
this.inputBuffer.Available += this.inf.RemainingInput;
|
||||
}
|
||||
if ((long)this.inputBuffer.Available > this.csize && this.csize >= 0L)
|
||||
{
|
||||
this.inputBuffer.Available = (int)((long)this.inputBuffer.Available - this.csize);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.csize -= (long)this.inputBuffer.Available;
|
||||
this.inputBuffer.Available = 0;
|
||||
while (this.csize != 0L)
|
||||
{
|
||||
long num = base.Skip(this.csize);
|
||||
if (num <= 0L)
|
||||
{
|
||||
throw new ZipException("Zip archive ends early.");
|
||||
}
|
||||
this.csize -= num;
|
||||
}
|
||||
}
|
||||
this.CompleteCloseEntry(false);
|
||||
}
|
||||
|
||||
// Token: 0x1700011E RID: 286
|
||||
// (get) Token: 0x060004D6 RID: 1238 RVA: 0x00017A55 File Offset: 0x00016A55
|
||||
public override int Available
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.entry == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x1700011F RID: 287
|
||||
// (get) Token: 0x060004D7 RID: 1239 RVA: 0x00017A62 File Offset: 0x00016A62
|
||||
public override long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.entry == null)
|
||||
{
|
||||
throw new InvalidOperationException("No current entry");
|
||||
}
|
||||
if (this.entry.Size >= 0L)
|
||||
{
|
||||
return this.entry.Size;
|
||||
}
|
||||
throw new ZipException("Length not available for the current entry");
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x060004D8 RID: 1240 RVA: 0x00017A9C File Offset: 0x00016A9C
|
||||
public override int ReadByte()
|
||||
{
|
||||
byte[] array = new byte[1];
|
||||
if (this.Read(array, 0, 1) <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return (int)(array[0] & byte.MaxValue);
|
||||
}
|
||||
|
||||
// Token: 0x060004D9 RID: 1241 RVA: 0x00017AC7 File Offset: 0x00016AC7
|
||||
private int ReadingNotAvailable(byte[] destination, int offset, int count)
|
||||
{
|
||||
throw new InvalidOperationException("Unable to read from this stream");
|
||||
}
|
||||
|
||||
// Token: 0x060004DA RID: 1242 RVA: 0x00017AD3 File Offset: 0x00016AD3
|
||||
private int ReadingNotSupported(byte[] destination, int offset, int count)
|
||||
{
|
||||
throw new ZipException("The compression method for this entry is not supported");
|
||||
}
|
||||
|
||||
// Token: 0x060004DB RID: 1243 RVA: 0x00017AE0 File Offset: 0x00016AE0
|
||||
private int InitialRead(byte[] destination, int offset, int count)
|
||||
{
|
||||
if (!this.CanDecompressEntry)
|
||||
{
|
||||
throw new ZipException("Library cannot extract this entry. Version required is (" + this.entry.Version.ToString() + ")");
|
||||
}
|
||||
if (this.entry.IsCrypted)
|
||||
{
|
||||
if (this.password == null)
|
||||
{
|
||||
throw new ZipException("No password set.");
|
||||
}
|
||||
PkzipClassicManaged pkzipClassicManaged = new PkzipClassicManaged();
|
||||
byte[] array = PkzipClassic.GenerateKeys(ZipConstants.ConvertToArray(this.password));
|
||||
this.inputBuffer.CryptoTransform = pkzipClassicManaged.CreateDecryptor(array, null);
|
||||
byte[] array2 = new byte[12];
|
||||
this.inputBuffer.ReadClearTextBuffer(array2, 0, 12);
|
||||
if (array2[11] != this.entry.CryptoCheckValue)
|
||||
{
|
||||
throw new ZipException("Invalid password");
|
||||
}
|
||||
if (this.csize >= 12L)
|
||||
{
|
||||
this.csize -= 12L;
|
||||
}
|
||||
else if ((this.entry.Flags & 8) == 0)
|
||||
{
|
||||
throw new ZipException(string.Format("Entry compressed size {0} too small for encryption", this.csize));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.inputBuffer.CryptoTransform = null;
|
||||
}
|
||||
if (this.csize > 0L || (this.flags & 8) != 0)
|
||||
{
|
||||
if (this.method == 8 && this.inputBuffer.Available > 0)
|
||||
{
|
||||
this.inputBuffer.SetInflaterInput(this.inf);
|
||||
}
|
||||
this.internalReader = new ZipInputStream.ReadDataHandler(this.BodyRead);
|
||||
return this.BodyRead(destination, offset, count);
|
||||
}
|
||||
this.internalReader = new ZipInputStream.ReadDataHandler(this.ReadingNotAvailable);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Token: 0x060004DC RID: 1244 RVA: 0x00017C5C File Offset: 0x00016C5C
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("buffer");
|
||||
}
|
||||
if (offset < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("offset", "Cannot be negative");
|
||||
}
|
||||
if (count < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("count", "Cannot be negative");
|
||||
}
|
||||
if (buffer.Length - offset < count)
|
||||
{
|
||||
throw new ArgumentException("Invalid offset/count combination");
|
||||
}
|
||||
return this.internalReader(buffer, offset, count);
|
||||
}
|
||||
|
||||
// Token: 0x060004DD RID: 1245 RVA: 0x00017CC0 File Offset: 0x00016CC0
|
||||
private int BodyRead(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (this.crc == null)
|
||||
{
|
||||
throw new InvalidOperationException("Closed");
|
||||
}
|
||||
if (this.entry == null || count <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (offset + count > buffer.Length)
|
||||
{
|
||||
throw new ArgumentException("Offset + count exceeds buffer size");
|
||||
}
|
||||
bool flag = false;
|
||||
int num = this.method;
|
||||
if (num != 0)
|
||||
{
|
||||
if (num == 8)
|
||||
{
|
||||
count = base.Read(buffer, offset, count);
|
||||
if (count <= 0)
|
||||
{
|
||||
if (!this.inf.IsFinished)
|
||||
{
|
||||
throw new ZipException("Inflater not finished!");
|
||||
}
|
||||
this.inputBuffer.Available = this.inf.RemainingInput;
|
||||
if ((this.flags & 8) == 0 && ((this.inf.TotalIn != this.csize && this.csize != (long)((ulong)(-1)) && this.csize != -1L) || this.inf.TotalOut != this.size))
|
||||
{
|
||||
throw new ZipException(string.Concat(new object[]
|
||||
{
|
||||
"Size mismatch: ",
|
||||
this.csize,
|
||||
";",
|
||||
this.size,
|
||||
" <-> ",
|
||||
this.inf.TotalIn,
|
||||
";",
|
||||
this.inf.TotalOut
|
||||
}));
|
||||
}
|
||||
this.inf.Reset();
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((long)count > this.csize && this.csize >= 0L)
|
||||
{
|
||||
count = (int)this.csize;
|
||||
}
|
||||
if (count > 0)
|
||||
{
|
||||
count = this.inputBuffer.ReadClearTextBuffer(buffer, offset, count);
|
||||
if (count > 0)
|
||||
{
|
||||
this.csize -= (long)count;
|
||||
this.size -= (long)count;
|
||||
}
|
||||
}
|
||||
if (this.csize == 0L)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
else if (count < 0)
|
||||
{
|
||||
throw new ZipException("EOF in stored block");
|
||||
}
|
||||
}
|
||||
if (count > 0)
|
||||
{
|
||||
this.crc.Update(buffer, offset, count);
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
this.CompleteCloseEntry(true);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Token: 0x060004DE RID: 1246 RVA: 0x00017EB0 File Offset: 0x00016EB0
|
||||
public override void Close()
|
||||
{
|
||||
this.internalReader = new ZipInputStream.ReadDataHandler(this.ReadingNotAvailable);
|
||||
this.crc = null;
|
||||
this.entry = null;
|
||||
base.Close();
|
||||
}
|
||||
|
||||
// Token: 0x04000316 RID: 790
|
||||
private ZipInputStream.ReadDataHandler internalReader;
|
||||
|
||||
// Token: 0x04000317 RID: 791
|
||||
private Crc32 crc = new Crc32();
|
||||
|
||||
// Token: 0x04000318 RID: 792
|
||||
private ZipEntry entry;
|
||||
|
||||
// Token: 0x04000319 RID: 793
|
||||
private long size;
|
||||
|
||||
// Token: 0x0400031A RID: 794
|
||||
private int method;
|
||||
|
||||
// Token: 0x0400031B RID: 795
|
||||
private int flags;
|
||||
|
||||
// Token: 0x0400031C RID: 796
|
||||
private string password;
|
||||
|
||||
// Token: 0x0200007E RID: 126
|
||||
// (Invoke) Token: 0x060004E0 RID: 1248
|
||||
private delegate int ReadDataHandler(byte[] b, int offset, int length);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user