//[Test] public void TestEmptyBlankBiff8Streams() { byte[] stream1Name = new byte[] { 0x57, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6B, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x6F, 0x00, 0x6B, 0x00, 0x00, 0x00 }; byte[] stream2Name = new byte[] { 0x05, 0x00, 0x53, 0x00, 0x75, 0x00, 0x6D, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x72, 0x00, 0x79, 0x00, 0x49, 0x00, 0x6E, 0x00, 0x66, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x00, 0x00 }; byte[] stream1 = GetBytes(@"C:\Documents and Settings\pengt\My Documents\Visual Studio 2005\Projects\MyXls\Docs\Stream1.bin"); //Assert.AreEqual(579, stream1.Length); byte[] stream2 = GetBytes(@"C:\Documents and Settings\pengt\My Documents\Visual Studio 2005\Projects\MyXls\Docs\Stream2.bin"); //Assert.AreEqual(312, stream2.Length); Ole2Document doc = new Ole2Document(); doc.Streams.AddNamed(stream1, stream1Name); doc.Streams.AddNamed(stream2, stream2Name); WriteBytesToFile(doc.Bytes.ByteArray, @"C:\Documents and Settings\pengt\My Documents\Visual Studio 2005\Projects\MyXls\Docs\test.xls"); //Assert.AreEqual(3072, doc.Bytes.Length); }
// 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)); }
public void TestLoad() { Ole2Document doc = new Ole2Document(); FileInfo fi = new FileInfo(TestsConfig.ReferenceFileFolder + "Book1.xls"); doc.Load(fi.Open(FileMode.Open, FileAccess.Read, FileShare.Read)); Assert.AreEqual(2, doc.Streams.Count, "# Streams"); byte[] refStream1 = GetBytes(TestsConfig.ReferenceFileFolder + "Stream1.bin"); byte[] refStream2 = GetBytes(TestsConfig.ReferenceFileFolder + "Stream2.bin"); byte[] tstStream1 = doc.Streams[1].Bytes.ByteArray; byte[] tstStream2 = doc.Streams[2].Bytes.ByteArray; Assert.AreEqual(refStream1, tstStream1, "Stream 1 ref & test stream bytes"); Assert.AreEqual(refStream2, tstStream2, "Stream 2 ref & test stream bytes"); }
// Token: 0x0600027A RID: 634 RVA: 0x0000BC3C File Offset: 0x0000AC3C private static Bytes GetSector(System.IO.Stream stream, int sectorSize, int sidIndex) { int num = (int)Math.Pow(2.0, (double)sectorSize); int num2 = 512 + sidIndex * num; if (stream.Length < (long)(num2 + num)) { return(new Bytes()); } byte[] array = new byte[num]; stream.Seek((long)num2, SeekOrigin.Begin); Ole2Document.ReadWholeArray(stream, array); return(new Bytes(array)); }
//[Test] public void TestLoad() { Ole2Document doc = new Ole2Document(); FileInfo fi = new FileInfo("..\\..\\..\\Docs\\Book1.xls"); doc.Load(fi.Open(FileMode.Open, FileAccess.Read, FileShare.Read)); //Assert.AreEqual(4, doc.Streams.Count, "# Streams"); byte[] refStream1 = GetBytes("..\\..\\..\\Docs\\Stream1.bin"); byte[] refStream2 = GetBytes("..\\..\\..\\Docs\\Stream2.bin"); byte[] tstStream1 = doc.Streams[2].Bytes.ByteArray; byte[] tstStream2 = doc.Streams[3].Bytes.ByteArray; //Assert.AreEqual(refStream1, tstStream1, "Stream 1 ref & test stream bytes"); //Assert.AreEqual(refStream2, tstStream2, "Stream 2 ref & test stream bytes"); }
public void TestEmptyBlankBiff8Streams() { byte[] stream1Name = new byte[] { 0x57, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6B, 0x00, 0x62, 0x00, 0x6F, 0x00, 0x6F, 0x00, 0x6B, 0x00, 0x00, 0x00}; byte[] stream2Name = new byte[] { 0x05, 0x00, 0x53, 0x00, 0x75, 0x00, 0x6D, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x72, 0x00, 0x79, 0x00, 0x49, 0x00, 0x6E, 0x00, 0x66, 0x00, 0x6F, 0x00, 0x72, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x00, 0x00}; byte[] stream1 = GetBytes(TestsConfig.ReferenceFileFolder + "Stream1.bin"); Assert.AreEqual(579, stream1.Length); byte[] stream2 = GetBytes(TestsConfig.ReferenceFileFolder + "Stream2.bin"); Assert.AreEqual(312, stream2.Length); Ole2Document doc = new Ole2Document(); doc.Streams.AddNamed(stream1, stream1Name); doc.Streams.AddNamed(stream2, stream2Name); WriteBytesToFile(doc.Bytes.ByteArray, "test.xls"); Assert.AreEqual(3072, doc.Bytes.Length); }
/// <summary> /// Initializes a new instance of the Msat class for the given Doc object. /// </summary> /// <param name="doc">The parent Doc object for the new Msat object.</param> public Msat(Ole2Document doc) { _doc = doc; }
// Token: 0x060002AB RID: 683 RVA: 0x0000CCFE File Offset: 0x0000BCFE public Stream(Ole2Document doc) { this._doc = doc; }
/// <summary> /// Initializes a new instance of the Directory class for the provided Doc object. /// </summary> /// <param name="doc">The Doc object to which this new Directory is to belong.</param> public Directory(Ole2Document doc) { _doc = doc; }
/// <summary> /// Initializes a new instance of the Header class for the given Document object. /// </summary> /// <param name="doc">The parent OleDocument object for this Header object.</param> public Header(Ole2Document doc) { _doc = doc; SetDefaults(); }
private void AssertFailMyXls(string message, string expectedFile, string actualFile) { Ole2Document n2doc = new Ole2Document(); FileStream fs = new FileInfo(actualFile).Open(FileMode.Open, FileAccess.Read); n2doc.Load(fs); fs.Close(); Bytes actualWorksheet = n2doc.Streams[n2doc.Streams.GetIndex(Directory.Biff8Workbook)].Bytes; n2doc = new Ole2Document(); fs = new FileInfo(expectedFile).Open(FileMode.Open, FileAccess.Read); n2doc.Load(fs); fs.Close(); Bytes expectedWorksheet = n2doc.Streams[n2doc.Streams.GetIndex(Directory.Biff8Workbook)].Bytes; string expectedWorksheetFile = "ExpectedWorksheet.records"; string actualWorksheetFile = "ActualWorksheet.records"; WriteRecordsToFile(actualWorksheet, actualWorksheetFile); WriteRecordsToFile(expectedWorksheet, expectedWorksheetFile); Process ueProc = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "uedit32"; startInfo.Arguments = string.Format("/a \"{0}\" \"{1}\" \"{2}\" \"{3}\"", expectedFile, actualFile, expectedWorksheetFile, actualWorksheetFile); ueProc.StartInfo = startInfo; ueProc.Start(); Assert.Fail(message); }
public void Instantiate() { #pragma warning disable 168 Ole2Document doc = new Ole2Document(); #pragma warning restore 168 }
/// <summary> /// Initializes a new instance of the Ssat class for the provided Doc object. /// </summary> /// <param name="doc">The parent Doc object for this new Ssat object.</param> public Ssat(Ole2Document doc) { _doc = doc; }
/// <summary> /// Initializes a new instance of the Stream class for the provided Doc object. /// </summary> /// <param name="doc">The parent Doc object for this new Stream object.</param> public Stream(Ole2Document doc) { _doc = doc; }
//[Test] public void Instantiate() { Ole2Document doc = new Ole2Document(); }
// Token: 0x06000054 RID: 84 RVA: 0x00003862 File Offset: 0x00002862 public Ssat(Ole2Document doc) { this._doc = doc; }
// Token: 0x06000008 RID: 8 RVA: 0x0000226C File Offset: 0x0000126C public Header(Ole2Document doc) { this._doc = doc; this.SetDefaults(); }
// 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); } } }