// Token: 0x06000277 RID: 631 RVA: 0x0000BA70 File Offset: 0x0000AA70 private Bytes GetStream(System.IO.Stream fromDocumentStream, int did, Dictionary <int, byte[]> dir, ushort sectorSize, int[] sat, ushort shortSectorSize, int[] ssat, uint minStandardStreamSize) { Bytes bytes = new Bytes(); int num = BitConverter.ToInt32(Ole2Document.MidByteArray(dir[did], 120, 4), 0); Bytes bytes2 = null; if (did == 0 || (long)num >= (long)((ulong)minStandardStreamSize)) { byte[] array = new byte[fromDocumentStream.Length]; fromDocumentStream.Position = 0L; fromDocumentStream.Read(array, 0, array.Length); bytes2 = new Bytes(array); } ushort num2; int[] array2; string arg; Bytes bytes3; if (did == 0) { num2 = sectorSize; array2 = sat; arg = string.Empty; bytes3 = bytes2; } else if ((long)num < (long)((ulong)minStandardStreamSize)) { num2 = shortSectorSize; array2 = ssat; arg = "Short "; bytes3 = this.GetStream(fromDocumentStream, 0, dir, sectorSize, sat, shortSectorSize, ssat, minStandardStreamSize); } else { num2 = sectorSize; array2 = sat; arg = string.Empty; bytes3 = bytes2; } for (int i = BitConverter.ToInt32(Ole2Document.MidByteArray(dir[did], 116, 4), 0); i > -2; i = array2[i]) { Bytes bytes4; if (did > 0 && (long)num < (long)((ulong)minStandardStreamSize)) { bytes4 = Ole2Document.GetShortSectorBytes(bytes3, (int)num2, i); } else { bytes4 = Ole2Document.GetSectorBytes(bytes3, (int)num2, i); } if (bytes4.Length == 0) { throw new Exception(string.Format("{0}Sector not found [SID{1}]", arg, i)); } bytes.Append(bytes4); } return(bytes.Get(num)); }
// Token: 0x06000276 RID: 630 RVA: 0x0000B40C File Offset: 0x0000A40C public void Load(System.IO.Stream stream) { if (stream.Length == 0L) { throw new Exception("No data (or zero-length) found!"); } if (stream.Length < 512L) { throw new Exception(string.Format("File length {0} < 512 bytes", stream.Length)); } byte[] array = new byte[512]; stream.Read(array, 0, 512); bool flag = false; if (array[28] == 254 && array[29] == 255) { flag = true; } if (!flag) { throw new NotSupportedException("File is not Little-Endian"); } this._isLittleEndian = flag; ushort num = BitConverter.ToUInt16(Ole2Document.MidByteArray(array, 30, 2), 0); if (num < 7 || num > 32) { throw new Exception(string.Format("Invalid Sector Size [{0}] (should be 7 <= sectorSize <= 32", num)); } this._sectorSize = num; ushort num2 = BitConverter.ToUInt16(Ole2Document.MidByteArray(array, 32, 2), 0); if (num2 > num) { throw new Exception(string.Format("Invalid Short Sector Size [{0}] (should be < sectorSize; {1})", num2, num)); } this._shortSectorSize = num2; uint num3 = BitConverter.ToUInt32(Ole2Document.MidByteArray(array, 44, 4), 0); if (num3 < 0U) { throw new Exception(string.Format("Invalid SAT Sector Count [{0}] (should be > 0)", num3)); } int num4 = BitConverter.ToInt32(Ole2Document.MidByteArray(array, 48, 4), 0); if (num4 < 0) { throw new Exception(string.Format("Invalid Directory SID0 [{0}] (should be > 0)", num4)); } uint num5 = BitConverter.ToUInt32(Ole2Document.MidByteArray(array, 56, 4), 0); if (num5 < Math.Pow(2.0, (double)num) || num5 % Math.Pow(2.0, (double)num) > 0.0) { throw new Exception(string.Format("Invalid MinStdStreamSize [{0}] (should be multiple of (2^SectorSize)", num5)); } this._standardStreamMinBytes = num5; int num6 = BitConverter.ToInt32(Ole2Document.MidByteArray(array, 60, 4), 0); uint num7 = BitConverter.ToUInt32(Ole2Document.MidByteArray(array, 64, 4), 0); if (num6 < 0 && num6 != -2) { throw new Exception(string.Format("Invalid SSAT SID0 [{0}] (must be >=0 or -2", num6)); } if (num7 > 0U && num6 < 0) { throw new Exception(string.Format("Invalid SSAT SID0 [{0}] (must be >=0 when SSAT Sector Count > 0)", num6)); } if (num7 < 0U) { throw new Exception(string.Format("Invalid SSAT Sector Count [{0}] (must be >= 0)", num7)); } int num8 = BitConverter.ToInt32(Ole2Document.MidByteArray(array, 68, 4), 0); if (num8 < 1 && num8 != -2) { throw new Exception(string.Format("Invalid MSAT SID0 [{0}]", num8)); } uint num9 = BitConverter.ToUInt32(Ole2Document.MidByteArray(array, 72, 4), 0); if (num9 < 0U) { throw new Exception(string.Format("Invalid MSAT Sector Count [{0}]", num9)); } if (num9 == 0U && num8 != -2) { throw new Exception(string.Format("Invalid MSAT SID0 [{0}] (should be -2)", num8)); } int i = 0; int j = (int)Math.Pow(2.0, (double)num) / 4 - 1; int[] array2 = new int[108L + (long)j * (long)((ulong)num9) + 1L]; for (int k = 0; k < 109; k++) { array2[k] = BitConverter.ToInt32(Ole2Document.MidByteArray(array, 76 + k * 4, 4), 0); } int num10 = num8; while ((long)i < (long)((ulong)num9)) { Bytes sector = Ole2Document.GetSector(stream, (int)num, num10); if (sector.Length == 0) { throw new Exception(string.Format("MSAT SID Chain broken - SID [{0}] not found / EOF reached", num10)); } for (int l = 0; l < j; l++) { array2[109 + i * j + l] = BitConverter.ToInt32(sector.Get(l * 4, 4).ByteArray, 0); } num10 = BitConverter.ToInt32(sector.Get(j * 4, 4).ByteArray, 0); i++; } i = array2.Length; while (array2[i - 1] < 0) { i--; } int[] array3 = new int[(uint)((double)i * (Math.Pow(2.0, (double)num) / 4.0))]; int num11 = (int)(Math.Pow(2.0, (double)num) / 4.0); for (int m = 0; m < i; m++) { Bytes sector2 = Ole2Document.GetSector(stream, (int)num, array2[m]); if (sector2.Length == 0) { throw new Exception(string.Format("SAT SID Chain broken - SAT Sector SID{0} not found / EOF reached", array2[m])); } for (j = 0; j < num11; j++) { array3[m * num11 + j] = BitConverter.ToInt32(sector2.Get(j * 4, 4).ByteArray, 0); } } i = 0; int n = num6; int[] array4 = new int[(ulong)(num7 + 1U) * (ulong)((long)num11)]; while (n > -2) { Bytes sector3 = Ole2Document.GetSector(stream, (int)num, n); if (sector3.Length == 0) { throw new Exception(string.Format("SSAT Sector SID{0} not found", n)); } for (int num12 = 0; num12 < num11; num12++) { array4[i * num11 + num12] = BitConverter.ToInt32(sector3.Get(num12 * 4, 4).ByteArray, 0); } n = array3[n]; i++; } if ((long)i < (long)((ulong)num7)) { throw new Exception(string.Format("SSAT Sector chain broken: {0} found, header indicates {1}", i, num7)); } int num13 = 0; int num14 = num4; num11 = (int)(Math.Pow(2.0, (double)num) / 128.0); Dictionary <int, byte[]> dictionary = new Dictionary <int, byte[]>(); while (num14 > -2) { Bytes sector4 = Ole2Document.GetSector(stream, (int)num, num14); if (sector4.Length == 0) { throw new Exception(string.Format("Directory Sector SID{0} not found", num14)); } for (int num15 = 0; num15 < num11; num15++) { dictionary[num13 * num11 + num15] = sector4.Get(num15 * 128, 128).ByteArray; } num14 = array3[num14]; num13++; } for (i = 0; i < dictionary.Count; i++) { byte[] byteArray = dictionary[i]; int length = (int)BitConverter.ToInt16(Ole2Document.MidByteArray(byteArray, 64, 2), 0); byte[] array5 = Ole2Document.MidByteArray(byteArray, 0, length); bool overwrite = false; if (Bytes.AreEqual(array5, Directory.RootName)) { overwrite = true; } Bytes stream2 = this.GetStream(stream, i, dictionary, num, array3, num2, array4, num5); if (array5.Length != 0 || stream2.Length != 0) { this.Streams.AddNamed(stream2, array5, overwrite); } } }