Files
Dec2017-Script-Dump/ICSharpCode.SharpZipLib/Zip/Compression/Streams/DeflaterOutputStream.cs
T
2026-06-04 11:42:34 +02:00

350 lines
9.1 KiB
C#

using System;
using System.IO;
using System.Security.Cryptography;
using ICSharpCode.SharpZipLib.Encryption;
namespace ICSharpCode.SharpZipLib.Zip.Compression.Streams
{
// Token: 0x0200002B RID: 43
public class DeflaterOutputStream : Stream
{
// Token: 0x06000130 RID: 304 RVA: 0x00008B1C File Offset: 0x00007B1C
public DeflaterOutputStream(Stream baseOutputStream)
: this(baseOutputStream, new Deflater(), 512)
{
}
// Token: 0x06000131 RID: 305 RVA: 0x00008B2F File Offset: 0x00007B2F
public DeflaterOutputStream(Stream baseOutputStream, Deflater deflater)
: this(baseOutputStream, deflater, 512)
{
}
// Token: 0x06000132 RID: 306 RVA: 0x00008B40 File Offset: 0x00007B40
public DeflaterOutputStream(Stream baseOutputStream, Deflater deflater, int bufferSize)
{
if (baseOutputStream == null)
{
throw new ArgumentNullException("baseOutputStream");
}
if (!baseOutputStream.CanWrite)
{
throw new ArgumentException("Must support writing", "baseOutputStream");
}
if (deflater == null)
{
throw new ArgumentNullException("deflater");
}
if (bufferSize < 512)
{
throw new ArgumentOutOfRangeException("bufferSize");
}
this.baseOutputStream_ = baseOutputStream;
this.buffer_ = new byte[bufferSize];
this.deflater_ = deflater;
}
// Token: 0x06000133 RID: 307 RVA: 0x00008BBC File Offset: 0x00007BBC
public virtual void Finish()
{
this.deflater_.Finish();
while (!this.deflater_.IsFinished)
{
int num = this.deflater_.Deflate(this.buffer_, 0, this.buffer_.Length);
if (num <= 0)
{
break;
}
if (this.cryptoTransform_ != null)
{
this.EncryptBlock(this.buffer_, 0, num);
}
this.baseOutputStream_.Write(this.buffer_, 0, num);
}
if (!this.deflater_.IsFinished)
{
throw new SharpZipBaseException("Can't deflate all input?");
}
this.baseOutputStream_.Flush();
if (this.cryptoTransform_ != null)
{
if (this.cryptoTransform_ is ZipAESTransform)
{
this.AESAuthCode = ((ZipAESTransform)this.cryptoTransform_).GetAuthCode();
}
this.cryptoTransform_.Dispose();
this.cryptoTransform_ = null;
}
}
// Token: 0x1700003B RID: 59
// (get) Token: 0x06000134 RID: 308 RVA: 0x00008C8B File Offset: 0x00007C8B
// (set) Token: 0x06000135 RID: 309 RVA: 0x00008C93 File Offset: 0x00007C93
public bool IsStreamOwner
{
get
{
return this.isStreamOwner_;
}
set
{
this.isStreamOwner_ = value;
}
}
// Token: 0x1700003C RID: 60
// (get) Token: 0x06000136 RID: 310 RVA: 0x00008C9C File Offset: 0x00007C9C
public bool CanPatchEntries
{
get
{
return this.baseOutputStream_.CanSeek;
}
}
// Token: 0x1700003D RID: 61
// (get) Token: 0x06000137 RID: 311 RVA: 0x00008CA9 File Offset: 0x00007CA9
// (set) Token: 0x06000138 RID: 312 RVA: 0x00008CB1 File Offset: 0x00007CB1
public string Password
{
get
{
return this.password;
}
set
{
if (value != null && value.Length == 0)
{
this.password = null;
return;
}
this.password = value;
}
}
// Token: 0x06000139 RID: 313 RVA: 0x00008CCD File Offset: 0x00007CCD
protected void EncryptBlock(byte[] buffer, int offset, int length)
{
this.cryptoTransform_.TransformBlock(buffer, 0, length, buffer, 0);
}
// Token: 0x0600013A RID: 314 RVA: 0x00008CE0 File Offset: 0x00007CE0
protected void InitializePassword(string password)
{
PkzipClassicManaged pkzipClassicManaged = new PkzipClassicManaged();
byte[] array = PkzipClassic.GenerateKeys(ZipConstants.ConvertToArray(password));
this.cryptoTransform_ = pkzipClassicManaged.CreateEncryptor(array, null);
}
// Token: 0x0600013B RID: 315 RVA: 0x00008D10 File Offset: 0x00007D10
protected void InitializeAESPassword(ZipEntry entry, string rawPassword, out byte[] salt, out byte[] pwdVerifier)
{
salt = new byte[entry.AESSaltLen];
if (DeflaterOutputStream._aesRnd == null)
{
DeflaterOutputStream._aesRnd = new RNGCryptoServiceProvider();
}
DeflaterOutputStream._aesRnd.GetBytes(salt);
int num = entry.AESKeySize / 8;
this.cryptoTransform_ = new ZipAESTransform(rawPassword, salt, num, true);
pwdVerifier = ((ZipAESTransform)this.cryptoTransform_).PwdVerifier;
}
// Token: 0x0600013C RID: 316 RVA: 0x00008D74 File Offset: 0x00007D74
protected void Deflate()
{
while (!this.deflater_.IsNeedingInput)
{
int num = this.deflater_.Deflate(this.buffer_, 0, this.buffer_.Length);
if (num <= 0)
{
break;
}
if (this.cryptoTransform_ != null)
{
this.EncryptBlock(this.buffer_, 0, num);
}
this.baseOutputStream_.Write(this.buffer_, 0, num);
}
if (!this.deflater_.IsNeedingInput)
{
throw new SharpZipBaseException("DeflaterOutputStream can't deflate all input?");
}
}
// Token: 0x1700003E RID: 62
// (get) Token: 0x0600013D RID: 317 RVA: 0x00008DF0 File Offset: 0x00007DF0
public override bool CanRead
{
get
{
return false;
}
}
// Token: 0x1700003F RID: 63
// (get) Token: 0x0600013E RID: 318 RVA: 0x00008DF3 File Offset: 0x00007DF3
public override bool CanSeek
{
get
{
return false;
}
}
// Token: 0x17000040 RID: 64
// (get) Token: 0x0600013F RID: 319 RVA: 0x00008DF6 File Offset: 0x00007DF6
public override bool CanWrite
{
get
{
return this.baseOutputStream_.CanWrite;
}
}
// Token: 0x17000041 RID: 65
// (get) Token: 0x06000140 RID: 320 RVA: 0x00008E03 File Offset: 0x00007E03
public override long Length
{
get
{
return this.baseOutputStream_.Length;
}
}
// Token: 0x17000042 RID: 66
// (get) Token: 0x06000141 RID: 321 RVA: 0x00008E10 File Offset: 0x00007E10
// (set) Token: 0x06000142 RID: 322 RVA: 0x00008E1D File Offset: 0x00007E1D
public override long Position
{
get
{
return this.baseOutputStream_.Position;
}
set
{
throw new NotSupportedException("Position property not supported");
}
}
// Token: 0x06000143 RID: 323 RVA: 0x00008E29 File Offset: 0x00007E29
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException("DeflaterOutputStream Seek not supported");
}
// Token: 0x06000144 RID: 324 RVA: 0x00008E35 File Offset: 0x00007E35
public override void SetLength(long value)
{
throw new NotSupportedException("DeflaterOutputStream SetLength not supported");
}
// Token: 0x06000145 RID: 325 RVA: 0x00008E41 File Offset: 0x00007E41
public override int ReadByte()
{
throw new NotSupportedException("DeflaterOutputStream ReadByte not supported");
}
// Token: 0x06000146 RID: 326 RVA: 0x00008E4D File Offset: 0x00007E4D
public override int Read(byte[] buffer, int offset, int count)
{
throw new NotSupportedException("DeflaterOutputStream Read not supported");
}
// Token: 0x06000147 RID: 327 RVA: 0x00008E59 File Offset: 0x00007E59
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
throw new NotSupportedException("DeflaterOutputStream BeginRead not currently supported");
}
// Token: 0x06000148 RID: 328 RVA: 0x00008E65 File Offset: 0x00007E65
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
throw new NotSupportedException("BeginWrite is not supported");
}
// Token: 0x06000149 RID: 329 RVA: 0x00008E71 File Offset: 0x00007E71
public override void Flush()
{
this.deflater_.Flush();
this.Deflate();
this.baseOutputStream_.Flush();
}
// Token: 0x0600014A RID: 330 RVA: 0x00008E90 File Offset: 0x00007E90
public override void Close()
{
if (!this.isClosed_)
{
this.isClosed_ = true;
try
{
this.Finish();
if (this.cryptoTransform_ != null)
{
this.GetAuthCodeIfAES();
this.cryptoTransform_.Dispose();
this.cryptoTransform_ = null;
}
}
finally
{
if (this.isStreamOwner_)
{
this.baseOutputStream_.Close();
}
}
}
}
// Token: 0x0600014B RID: 331 RVA: 0x00008EF8 File Offset: 0x00007EF8
private void GetAuthCodeIfAES()
{
if (this.cryptoTransform_ is ZipAESTransform)
{
this.AESAuthCode = ((ZipAESTransform)this.cryptoTransform_).GetAuthCode();
}
}
// Token: 0x0600014C RID: 332 RVA: 0x00008F20 File Offset: 0x00007F20
public override void WriteByte(byte value)
{
this.Write(new byte[] { value }, 0, 1);
}
// Token: 0x0600014D RID: 333 RVA: 0x00008F41 File Offset: 0x00007F41
public override void Write(byte[] buffer, int offset, int count)
{
this.deflater_.SetInput(buffer, offset, count);
this.Deflate();
}
// Token: 0x040000AD RID: 173
private string password;
// Token: 0x040000AE RID: 174
private ICryptoTransform cryptoTransform_;
// Token: 0x040000AF RID: 175
protected byte[] AESAuthCode;
// Token: 0x040000B0 RID: 176
private byte[] buffer_;
// Token: 0x040000B1 RID: 177
protected Deflater deflater_;
// Token: 0x040000B2 RID: 178
protected Stream baseOutputStream_;
// Token: 0x040000B3 RID: 179
private bool isClosed_;
// Token: 0x040000B4 RID: 180
private bool isStreamOwner_ = true;
// Token: 0x040000B5 RID: 181
private static RNGCryptoServiceProvider _aesRnd;
}
}