using System; using System.IO; using System.Security.Cryptography; namespace Mono.Security.Authenticode { // Token: 0x0200009F RID: 159 internal class AuthenticodeBase { // Token: 0x060008B2 RID: 2226 RVA: 0x00020E80 File Offset: 0x0001F080 public AuthenticodeBase() { this.fileblock = new byte[4096]; } // Token: 0x170000E7 RID: 231 // (get) Token: 0x060008B3 RID: 2227 RVA: 0x00020E98 File Offset: 0x0001F098 internal int PEOffset { get { if (this.blockNo < 1) { this.ReadFirstBlock(); } return this.peOffset; } } // Token: 0x170000E8 RID: 232 // (get) Token: 0x060008B4 RID: 2228 RVA: 0x00020EB4 File Offset: 0x0001F0B4 internal int CoffSymbolTableOffset { get { if (this.blockNo < 1) { this.ReadFirstBlock(); } return this.coffSymbolTableOffset; } } // Token: 0x170000E9 RID: 233 // (get) Token: 0x060008B5 RID: 2229 RVA: 0x00020ED0 File Offset: 0x0001F0D0 internal int SecurityOffset { get { if (this.blockNo < 1) { this.ReadFirstBlock(); } return this.dirSecurityOffset; } } // Token: 0x060008B6 RID: 2230 RVA: 0x00020EEC File Offset: 0x0001F0EC internal void Open(string filename) { if (this.fs != null) { this.Close(); } this.fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); } // Token: 0x060008B7 RID: 2231 RVA: 0x00020F1C File Offset: 0x0001F11C internal void Close() { if (this.fs != null) { this.fs.Close(); this.fs = null; this.blockNo = 0; } } // Token: 0x060008B8 RID: 2232 RVA: 0x00020F50 File Offset: 0x0001F150 internal bool ReadFirstBlock() { if (this.fs == null) { return false; } this.fs.Position = 0L; this.blockLength = this.fs.Read(this.fileblock, 0, this.fileblock.Length); this.blockNo = 1; if (this.blockLength < 64) { return false; } if (BitConverterLE.ToUInt16(this.fileblock, 0) != 23117) { return false; } this.peOffset = BitConverterLE.ToInt32(this.fileblock, 60); if (this.peOffset > this.fileblock.Length) { string text = string.Format(Locale.GetText("Header size too big (> {0} bytes)."), this.fileblock.Length); throw new NotSupportedException(text); } if ((long)this.peOffset > this.fs.Length) { return false; } if (BitConverterLE.ToUInt32(this.fileblock, this.peOffset) != 17744U) { return false; } this.dirSecurityOffset = BitConverterLE.ToInt32(this.fileblock, this.peOffset + 152); this.dirSecuritySize = BitConverterLE.ToInt32(this.fileblock, this.peOffset + 156); this.coffSymbolTableOffset = BitConverterLE.ToInt32(this.fileblock, this.peOffset + 12); return true; } // Token: 0x060008B9 RID: 2233 RVA: 0x0002109C File Offset: 0x0001F29C internal byte[] GetSecurityEntry() { if (this.blockNo < 1) { this.ReadFirstBlock(); } if (this.dirSecuritySize > 8) { byte[] array = new byte[this.dirSecuritySize - 8]; this.fs.Position = (long)(this.dirSecurityOffset + 8); this.fs.Read(array, 0, array.Length); return array; } return null; } // Token: 0x060008BA RID: 2234 RVA: 0x00021100 File Offset: 0x0001F300 internal byte[] GetHash(HashAlgorithm hash) { if (this.blockNo < 1) { this.ReadFirstBlock(); } this.fs.Position = (long)this.blockLength; int num = 0; long num2; if (this.dirSecurityOffset > 0) { if (this.dirSecurityOffset < this.blockLength) { this.blockLength = this.dirSecurityOffset; num2 = 0L; } else { num2 = (long)(this.dirSecurityOffset - this.blockLength); } } else if (this.coffSymbolTableOffset > 0) { this.fileblock[this.PEOffset + 12] = 0; this.fileblock[this.PEOffset + 13] = 0; this.fileblock[this.PEOffset + 14] = 0; this.fileblock[this.PEOffset + 15] = 0; this.fileblock[this.PEOffset + 16] = 0; this.fileblock[this.PEOffset + 17] = 0; this.fileblock[this.PEOffset + 18] = 0; this.fileblock[this.PEOffset + 19] = 0; if (this.coffSymbolTableOffset < this.blockLength) { this.blockLength = this.coffSymbolTableOffset; num2 = 0L; } else { num2 = (long)(this.coffSymbolTableOffset - this.blockLength); } } else { num = (int)(this.fs.Length & 7L); if (num > 0) { num = 8 - num; } num2 = this.fs.Length - (long)this.blockLength; } int num3 = this.peOffset + 88; hash.TransformBlock(this.fileblock, 0, num3, this.fileblock, 0); num3 += 4; hash.TransformBlock(this.fileblock, num3, 60, this.fileblock, num3); num3 += 68; if (num2 == 0L) { hash.TransformFinalBlock(this.fileblock, num3, this.blockLength - num3); } else { hash.TransformBlock(this.fileblock, num3, this.blockLength - num3, this.fileblock, num3); long num4 = num2 >> 12; int num5 = (int)(num2 - (num4 << 12)); if (num5 == 0) { num4 -= 1L; num5 = 4096; } for (;;) { long num6 = num4; num4 = num6 - 1L; if (num6 <= 0L) { break; } this.fs.Read(this.fileblock, 0, this.fileblock.Length); hash.TransformBlock(this.fileblock, 0, this.fileblock.Length, this.fileblock, 0); } if (this.fs.Read(this.fileblock, 0, num5) != num5) { return null; } if (num > 0) { hash.TransformBlock(this.fileblock, 0, num5, this.fileblock, 0); hash.TransformFinalBlock(new byte[num], 0, num); } else { hash.TransformFinalBlock(this.fileblock, 0, num5); } } return hash.Hash; } // Token: 0x060008BB RID: 2235 RVA: 0x000213C4 File Offset: 0x0001F5C4 protected byte[] HashFile(string fileName, string hashName) { byte[] array; try { this.Open(fileName); HashAlgorithm hashAlgorithm = HashAlgorithm.Create(hashName); byte[] hash = this.GetHash(hashAlgorithm); this.Close(); array = hash; } catch { array = null; } return array; } // Token: 0x040001C2 RID: 450 public const string spcIndirectDataContext = "1.3.6.1.4.1.311.2.1.4"; // Token: 0x040001C3 RID: 451 private byte[] fileblock; // Token: 0x040001C4 RID: 452 private FileStream fs; // Token: 0x040001C5 RID: 453 private int blockNo; // Token: 0x040001C6 RID: 454 private int blockLength; // Token: 0x040001C7 RID: 455 private int peOffset; // Token: 0x040001C8 RID: 456 private int dirSecurityOffset; // Token: 0x040001C9 RID: 457 private int dirSecuritySize; // Token: 0x040001CA RID: 458 private int coffSymbolTableOffset; } }