This commit is contained in:
niko
2026-06-04 11:42:34 +02:00
parent f39ba70a9f
commit e720b98cd1
7488 changed files with 2493818 additions and 0 deletions
@@ -0,0 +1,46 @@
using System;
using System.Security.Cryptography;
using ICSharpCode.SharpZipLib.Checksums;
namespace ICSharpCode.SharpZipLib.Encryption
{
// Token: 0x02000020 RID: 32
public abstract class PkzipClassic : SymmetricAlgorithm
{
// Token: 0x060000E0 RID: 224 RVA: 0x00007A8C File Offset: 0x00006A8C
public static byte[] GenerateKeys(byte[] seed)
{
if (seed == null)
{
throw new ArgumentNullException("seed");
}
if (seed.Length == 0)
{
throw new ArgumentException("Length is zero", "seed");
}
uint[] array = new uint[] { 305419896U, 591751049U, 878082192U };
for (int i = 0; i < seed.Length; i++)
{
array[0] = Crc32.ComputeCrc32(array[0], seed[i]);
array[1] = array[1] + (uint)((byte)array[0]);
array[1] = array[1] * 134775813U + 1U;
array[2] = Crc32.ComputeCrc32(array[2], (byte)(array[1] >> 24));
}
return new byte[]
{
(byte)(array[0] & 255U),
(byte)((array[0] >> 8) & 255U),
(byte)((array[0] >> 16) & 255U),
(byte)((array[0] >> 24) & 255U),
(byte)(array[1] & 255U),
(byte)((array[1] >> 8) & 255U),
(byte)((array[1] >> 16) & 255U),
(byte)((array[1] >> 24) & 255U),
(byte)(array[2] & 255U),
(byte)((array[2] >> 8) & 255U),
(byte)((array[2] >> 16) & 255U),
(byte)((array[2] >> 24) & 255U)
};
}
}
}
@@ -0,0 +1,53 @@
using System;
using ICSharpCode.SharpZipLib.Checksums;
namespace ICSharpCode.SharpZipLib.Encryption
{
// Token: 0x02000021 RID: 33
internal class PkzipClassicCryptoBase
{
// Token: 0x060000E2 RID: 226 RVA: 0x00007BE0 File Offset: 0x00006BE0
protected byte TransformByte()
{
uint num = (this.keys[2] & 65535U) | 2U;
return (byte)(num * (num ^ 1U) >> 8);
}
// Token: 0x060000E3 RID: 227 RVA: 0x00007C08 File Offset: 0x00006C08
protected void SetKeys(byte[] keyData)
{
if (keyData == null)
{
throw new ArgumentNullException("keyData");
}
if (keyData.Length != 12)
{
throw new InvalidOperationException("Key length is not valid");
}
this.keys = new uint[3];
this.keys[0] = (uint)(((int)keyData[3] << 24) | ((int)keyData[2] << 16) | ((int)keyData[1] << 8) | (int)keyData[0]);
this.keys[1] = (uint)(((int)keyData[7] << 24) | ((int)keyData[6] << 16) | ((int)keyData[5] << 8) | (int)keyData[4]);
this.keys[2] = (uint)(((int)keyData[11] << 24) | ((int)keyData[10] << 16) | ((int)keyData[9] << 8) | (int)keyData[8]);
}
// Token: 0x060000E4 RID: 228 RVA: 0x00007CA4 File Offset: 0x00006CA4
protected void UpdateKeys(byte ch)
{
this.keys[0] = Crc32.ComputeCrc32(this.keys[0], ch);
this.keys[1] = this.keys[1] + (uint)((byte)this.keys[0]);
this.keys[1] = this.keys[1] * 134775813U + 1U;
this.keys[2] = Crc32.ComputeCrc32(this.keys[2], (byte)(this.keys[1] >> 24));
}
// Token: 0x060000E5 RID: 229 RVA: 0x00007D1A File Offset: 0x00006D1A
protected void Reset()
{
this.keys[0] = 0U;
this.keys[1] = 0U;
this.keys[2] = 0U;
}
// Token: 0x04000089 RID: 137
private uint[] keys;
}
}
@@ -0,0 +1,81 @@
using System;
using System.Security.Cryptography;
namespace ICSharpCode.SharpZipLib.Encryption
{
// Token: 0x02000023 RID: 35
internal class PkzipClassicDecryptCryptoTransform : PkzipClassicCryptoBase, ICryptoTransform, IDisposable
{
// Token: 0x060000EF RID: 239 RVA: 0x00007DC4 File Offset: 0x00006DC4
internal PkzipClassicDecryptCryptoTransform(byte[] keyBlock)
{
base.SetKeys(keyBlock);
}
// Token: 0x060000F0 RID: 240 RVA: 0x00007DD4 File Offset: 0x00006DD4
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
byte[] array = new byte[inputCount];
this.TransformBlock(inputBuffer, inputOffset, inputCount, array, 0);
return array;
}
// Token: 0x060000F1 RID: 241 RVA: 0x00007DF8 File Offset: 0x00006DF8
public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
for (int i = inputOffset; i < inputOffset + inputCount; i++)
{
byte b = inputBuffer[i] ^ base.TransformByte();
outputBuffer[outputOffset++] = b;
base.UpdateKeys(b);
}
return inputCount;
}
// Token: 0x17000027 RID: 39
// (get) Token: 0x060000F2 RID: 242 RVA: 0x00007E32 File Offset: 0x00006E32
public bool CanReuseTransform
{
get
{
return true;
}
}
// Token: 0x17000028 RID: 40
// (get) Token: 0x060000F3 RID: 243 RVA: 0x00007E35 File Offset: 0x00006E35
public int InputBlockSize
{
get
{
return 1;
}
}
// Token: 0x17000029 RID: 41
// (get) Token: 0x060000F4 RID: 244 RVA: 0x00007E38 File Offset: 0x00006E38
public int OutputBlockSize
{
get
{
return 1;
}
}
// Token: 0x1700002A RID: 42
// (get) Token: 0x060000F5 RID: 245 RVA: 0x00007E3B File Offset: 0x00006E3B
public bool CanTransformMultipleBlocks
{
get
{
return true;
}
}
// Token: 0x060000F6 RID: 246 RVA: 0x00007E3E File Offset: 0x00006E3E
public void Dispose()
{
base.Reset();
}
}
}
@@ -0,0 +1,81 @@
using System;
using System.Security.Cryptography;
namespace ICSharpCode.SharpZipLib.Encryption
{
// Token: 0x02000022 RID: 34
internal class PkzipClassicEncryptCryptoTransform : PkzipClassicCryptoBase, ICryptoTransform, IDisposable
{
// Token: 0x060000E7 RID: 231 RVA: 0x00007D3F File Offset: 0x00006D3F
internal PkzipClassicEncryptCryptoTransform(byte[] keyBlock)
{
base.SetKeys(keyBlock);
}
// Token: 0x060000E8 RID: 232 RVA: 0x00007D50 File Offset: 0x00006D50
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
byte[] array = new byte[inputCount];
this.TransformBlock(inputBuffer, inputOffset, inputCount, array, 0);
return array;
}
// Token: 0x060000E9 RID: 233 RVA: 0x00007D74 File Offset: 0x00006D74
public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
for (int i = inputOffset; i < inputOffset + inputCount; i++)
{
byte b = inputBuffer[i];
outputBuffer[outputOffset++] = inputBuffer[i] ^ base.TransformByte();
base.UpdateKeys(b);
}
return inputCount;
}
// Token: 0x17000023 RID: 35
// (get) Token: 0x060000EA RID: 234 RVA: 0x00007DB0 File Offset: 0x00006DB0
public bool CanReuseTransform
{
get
{
return true;
}
}
// Token: 0x17000024 RID: 36
// (get) Token: 0x060000EB RID: 235 RVA: 0x00007DB3 File Offset: 0x00006DB3
public int InputBlockSize
{
get
{
return 1;
}
}
// Token: 0x17000025 RID: 37
// (get) Token: 0x060000EC RID: 236 RVA: 0x00007DB6 File Offset: 0x00006DB6
public int OutputBlockSize
{
get
{
return 1;
}
}
// Token: 0x17000026 RID: 38
// (get) Token: 0x060000ED RID: 237 RVA: 0x00007DB9 File Offset: 0x00006DB9
public bool CanTransformMultipleBlocks
{
get
{
return true;
}
}
// Token: 0x060000EE RID: 238 RVA: 0x00007DBC File Offset: 0x00006DBC
public void Dispose()
{
base.Reset();
}
}
}
@@ -0,0 +1,110 @@
using System;
using System.Security.Cryptography;
namespace ICSharpCode.SharpZipLib.Encryption
{
// Token: 0x02000024 RID: 36
public sealed class PkzipClassicManaged : PkzipClassic
{
// Token: 0x1700002B RID: 43
// (get) Token: 0x060000F7 RID: 247 RVA: 0x00007E46 File Offset: 0x00006E46
// (set) Token: 0x060000F8 RID: 248 RVA: 0x00007E49 File Offset: 0x00006E49
public override int BlockSize
{
get
{
return 8;
}
set
{
if (value != 8)
{
throw new CryptographicException("Block size is invalid");
}
}
}
// Token: 0x1700002C RID: 44
// (get) Token: 0x060000F9 RID: 249 RVA: 0x00007E5C File Offset: 0x00006E5C
public override KeySizes[] LegalKeySizes
{
get
{
return new KeySizes[]
{
new KeySizes(96, 96, 0)
};
}
}
// Token: 0x060000FA RID: 250 RVA: 0x00007E7E File Offset: 0x00006E7E
public override void GenerateIV()
{
}
// Token: 0x1700002D RID: 45
// (get) Token: 0x060000FB RID: 251 RVA: 0x00007E80 File Offset: 0x00006E80
public override KeySizes[] LegalBlockSizes
{
get
{
return new KeySizes[]
{
new KeySizes(8, 8, 0)
};
}
}
// Token: 0x1700002E RID: 46
// (get) Token: 0x060000FC RID: 252 RVA: 0x00007EA0 File Offset: 0x00006EA0
// (set) Token: 0x060000FD RID: 253 RVA: 0x00007EC0 File Offset: 0x00006EC0
public override byte[] Key
{
get
{
if (this.key_ == null)
{
this.GenerateKey();
}
return (byte[])this.key_.Clone();
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
if (value.Length != 12)
{
throw new CryptographicException("Key size is illegal");
}
this.key_ = (byte[])value.Clone();
}
}
// Token: 0x060000FE RID: 254 RVA: 0x00007EF4 File Offset: 0x00006EF4
public override void GenerateKey()
{
this.key_ = new byte[12];
Random random = new Random();
random.NextBytes(this.key_);
}
// Token: 0x060000FF RID: 255 RVA: 0x00007F20 File Offset: 0x00006F20
public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV)
{
this.key_ = rgbKey;
return new PkzipClassicEncryptCryptoTransform(this.Key);
}
// Token: 0x06000100 RID: 256 RVA: 0x00007F34 File Offset: 0x00006F34
public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV)
{
this.key_ = rgbKey;
return new PkzipClassicDecryptCryptoTransform(this.Key);
}
// Token: 0x0400008A RID: 138
private byte[] key_;
}
}
@@ -0,0 +1,109 @@
using System;
using System.IO;
using System.Security.Cryptography;
namespace ICSharpCode.SharpZipLib.Encryption
{
// Token: 0x02000025 RID: 37
internal class ZipAESStream : CryptoStream
{
// Token: 0x06000102 RID: 258 RVA: 0x00007F50 File Offset: 0x00006F50
public ZipAESStream(Stream stream, ZipAESTransform transform, CryptoStreamMode mode)
: base(stream, transform, mode)
{
this._stream = stream;
this._transform = transform;
this._slideBuffer = new byte[1024];
this._blockAndAuth = 26;
if (mode != CryptoStreamMode.Read)
{
throw new Exception("ZipAESStream only for read");
}
}
// Token: 0x06000103 RID: 259 RVA: 0x00007F90 File Offset: 0x00006F90
public override int Read(byte[] outBuffer, int offset, int count)
{
int i = 0;
while (i < count)
{
int num = this._slideBufFreePos - this._slideBufStartPos;
int num2 = this._blockAndAuth - num;
if (this._slideBuffer.Length - this._slideBufFreePos < num2)
{
int num3 = 0;
int j = this._slideBufStartPos;
while (j < this._slideBufFreePos)
{
this._slideBuffer[num3] = this._slideBuffer[j];
j++;
num3++;
}
this._slideBufFreePos -= this._slideBufStartPos;
this._slideBufStartPos = 0;
}
int num4 = this._stream.Read(this._slideBuffer, this._slideBufFreePos, num2);
this._slideBufFreePos += num4;
num = this._slideBufFreePos - this._slideBufStartPos;
if (num < this._blockAndAuth)
{
if (num > 10)
{
int num5 = num - 10;
this._transform.TransformBlock(this._slideBuffer, this._slideBufStartPos, num5, outBuffer, offset);
i += num5;
this._slideBufStartPos += num5;
}
else if (num < 10)
{
throw new Exception("Internal error missed auth code");
}
byte[] authCode = this._transform.GetAuthCode();
for (int k = 0; k < 10; k++)
{
if (authCode[k] != this._slideBuffer[this._slideBufStartPos + k])
{
throw new Exception("AES Authentication Code does not match. This is a super-CRC check on the data in the file after compression and encryption. \r\nThe file may be damaged.");
}
}
break;
}
this._transform.TransformBlock(this._slideBuffer, this._slideBufStartPos, 16, outBuffer, offset);
i += 16;
offset += 16;
this._slideBufStartPos += 16;
}
return i;
}
// Token: 0x06000104 RID: 260 RVA: 0x0000812A File Offset: 0x0000712A
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
// Token: 0x0400008B RID: 139
private const int AUTH_CODE_LENGTH = 10;
// Token: 0x0400008C RID: 140
private const int CRYPTO_BLOCK_SIZE = 16;
// Token: 0x0400008D RID: 141
private Stream _stream;
// Token: 0x0400008E RID: 142
private ZipAESTransform _transform;
// Token: 0x0400008F RID: 143
private byte[] _slideBuffer;
// Token: 0x04000090 RID: 144
private int _slideBufStartPos;
// Token: 0x04000091 RID: 145
private int _slideBufFreePos;
// Token: 0x04000092 RID: 146
private int _blockAndAuth;
}
}
@@ -0,0 +1,185 @@
using System;
using System.Security.Cryptography;
namespace ICSharpCode.SharpZipLib.Encryption
{
// Token: 0x02000026 RID: 38
internal class ZipAESTransform : ICryptoTransform, IDisposable
{
// Token: 0x06000105 RID: 261 RVA: 0x00008134 File Offset: 0x00007134
public ZipAESTransform(string key, byte[] saltBytes, int blockSize, bool writeMode)
{
if (blockSize != 16 && blockSize != 32)
{
throw new Exception("Invalid blocksize " + blockSize + ". Must be 16 or 32.");
}
if (saltBytes.Length != blockSize / 2)
{
throw new Exception(string.Concat(new object[]
{
"Invalid salt len. Must be ",
blockSize / 2,
" for blocksize ",
blockSize
}));
}
this._blockSize = blockSize;
this._encryptBuffer = new byte[this._blockSize];
this._encrPos = 16;
Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(key, saltBytes, 1000);
RijndaelManaged rijndaelManaged = new RijndaelManaged();
rijndaelManaged.Mode = CipherMode.ECB;
this._counterNonce = new byte[this._blockSize];
byte[] bytes = rfc2898DeriveBytes.GetBytes(this._blockSize);
byte[] bytes2 = rfc2898DeriveBytes.GetBytes(this._blockSize);
this._encryptor = rijndaelManaged.CreateEncryptor(bytes, bytes2);
this._pwdVerifier = rfc2898DeriveBytes.GetBytes(2);
this._hmacsha1 = new HMACSHA1(bytes2);
this._writeMode = writeMode;
}
// Token: 0x06000106 RID: 262 RVA: 0x00008248 File Offset: 0x00007248
public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
if (!this._writeMode)
{
this._hmacsha1.TransformBlock(inputBuffer, inputOffset, inputCount, inputBuffer, inputOffset);
}
for (int i = 0; i < inputCount; i++)
{
if (this._encrPos == 16)
{
int num = 0;
for (;;)
{
byte[] counterNonce = this._counterNonce;
int num2 = num;
if ((counterNonce[num2] += 1) != 0)
{
break;
}
num++;
}
this._encryptor.TransformBlock(this._counterNonce, 0, this._blockSize, this._encryptBuffer, 0);
this._encrPos = 0;
}
outputBuffer[i + outputOffset] = inputBuffer[i + inputOffset] ^ this._encryptBuffer[this._encrPos++];
}
if (this._writeMode)
{
this._hmacsha1.TransformBlock(outputBuffer, outputOffset, inputCount, outputBuffer, outputOffset);
}
return inputCount;
}
// Token: 0x1700002F RID: 47
// (get) Token: 0x06000107 RID: 263 RVA: 0x0000831C File Offset: 0x0000731C
public byte[] PwdVerifier
{
get
{
return this._pwdVerifier;
}
}
// Token: 0x06000108 RID: 264 RVA: 0x00008324 File Offset: 0x00007324
public byte[] GetAuthCode()
{
if (!this._finalised)
{
byte[] array = new byte[0];
this._hmacsha1.TransformFinalBlock(array, 0, 0);
this._finalised = true;
}
return this._hmacsha1.Hash;
}
// Token: 0x06000109 RID: 265 RVA: 0x00008361 File Offset: 0x00007361
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
throw new NotImplementedException("ZipAESTransform.TransformFinalBlock");
}
// Token: 0x17000030 RID: 48
// (get) Token: 0x0600010A RID: 266 RVA: 0x0000836D File Offset: 0x0000736D
public int InputBlockSize
{
get
{
return this._blockSize;
}
}
// Token: 0x17000031 RID: 49
// (get) Token: 0x0600010B RID: 267 RVA: 0x00008375 File Offset: 0x00007375
public int OutputBlockSize
{
get
{
return this._blockSize;
}
}
// Token: 0x17000032 RID: 50
// (get) Token: 0x0600010C RID: 268 RVA: 0x0000837D File Offset: 0x0000737D
public bool CanTransformMultipleBlocks
{
get
{
return true;
}
}
// Token: 0x17000033 RID: 51
// (get) Token: 0x0600010D RID: 269 RVA: 0x00008380 File Offset: 0x00007380
public bool CanReuseTransform
{
get
{
return true;
}
}
// Token: 0x0600010E RID: 270 RVA: 0x00008383 File Offset: 0x00007383
public void Dispose()
{
this._encryptor.Dispose();
}
// Token: 0x04000093 RID: 147
private const int PWD_VER_LENGTH = 2;
// Token: 0x04000094 RID: 148
private const int KEY_ROUNDS = 1000;
// Token: 0x04000095 RID: 149
private const int ENCRYPT_BLOCK = 16;
// Token: 0x04000096 RID: 150
private int _blockSize;
// Token: 0x04000097 RID: 151
private ICryptoTransform _encryptor;
// Token: 0x04000098 RID: 152
private readonly byte[] _counterNonce;
// Token: 0x04000099 RID: 153
private byte[] _encryptBuffer;
// Token: 0x0400009A RID: 154
private int _encrPos;
// Token: 0x0400009B RID: 155
private byte[] _pwdVerifier;
// Token: 0x0400009C RID: 156
private HMACSHA1 _hmacsha1;
// Token: 0x0400009D RID: 157
private bool _finalised;
// Token: 0x0400009E RID: 158
private bool _writeMode;
}
}