public StringTable(Type dataType, VirtualStreamReader reader) { this.Strings = new List <string>(); this.Data = new List <ByteStructure>(); parse(dataType, reader, (UInt32)reader.BaseStream.Position); }
public FontFamilyName(VirtualStreamReader reader, int length) : base(reader, length) { long startPos = this._reader.BaseStream.Position; //FFID int ffid = (int)this._reader.ReadByte(); int req = ffid; req = req << 6; req = req >> 6; this.prq = (byte)req; this.fTrueType = Utils.BitmaskToBool(ffid, 0x04); int family = ffid; family = family << 1; family = family >> 4; this.ff = (byte)family; this.wWeight = this._reader.ReadInt16(); this.chs = this._reader.ReadByte(); //skip byte 5 this._reader.ReadByte(); //read the 10 bytes panose this.panose = this._reader.ReadBytes(10); //read the 24 bytes FontSignature this.fs = new FontSignature { UnicodeSubsetBitfield0 = this._reader.ReadUInt32(), UnicodeSubsetBitfield1 = this._reader.ReadUInt32(), UnicodeSubsetBitfield2 = this._reader.ReadUInt32(), UnicodeSubsetBitfield3 = this._reader.ReadUInt32(), CodePageBitfield0 = this._reader.ReadUInt32(), CodePageBitfield1 = this._reader.ReadUInt32() }; //read the next \0 terminated string long strStart = reader.BaseStream.Position; long strEnd = searchTerminationZero(this._reader); this.xszFtn = Encoding.Unicode.GetString(this._reader.ReadBytes((int)(strEnd - strStart))); this.xszFtn = this.xszFtn.Replace("\0", ""); long readBytes = this._reader.BaseStream.Position - startPos; if (readBytes < this._length) { //read the next \0 terminated string strStart = reader.BaseStream.Position; strEnd = searchTerminationZero(this._reader); this.xszAlt = Encoding.Unicode.GetString(this._reader.ReadBytes((int)(strEnd - strStart))); this.xszAlt = this.xszAlt.Replace("\0", ""); } }
public CommandIdentifier(VirtualStreamReader reader) : base(reader, CID_LENGTH) { byte[] bytes = reader.ReadBytes(4); CidType type = (CidType)Utils.BitmaskToInt((int)bytes[0], 0x07); switch (type) { case CidType.cmtFci: break; case CidType.cmtMacro: this.ibstMacro = System.BitConverter.ToInt16(bytes, 2); break; case CidType.cmtAllocated: break; case CidType.cmtNil: break; default: break; } }
public static List <BiffRecord> ParseBiffStreamBytes(byte[] bytes) { List <BiffRecord> records = new List <BiffRecord>(); MemoryStream ms = new MemoryStream(bytes); VirtualStreamReader vsr = new VirtualStreamReader(ms); while (vsr.BaseStream.Position < vsr.BaseStream.Length) { RecordType id = (RecordType)vsr.ReadUInt16(); if (id == 0) { // Console.WriteLine("RecordID == 0 - stopping"); break; } UInt16 length = vsr.ReadUInt16(); BiffRecord br = new BiffRecord(vsr, id, length); vsr.ReadBytes(length); records.Add(br); } return(records); }
private void processLinkInfoStream(string linkStream) { try { VirtualStreamReader reader = new VirtualStreamReader(_docStorage.GetStream(linkStream)); //there are two versions of the Link string, one contains ANSI characters, the other contains //unicode characters. //Both strings seem not to be standardized: //The length prefix is a character count EXCLUDING the terminating zero //Read the ANSI version Int16 cch = reader.ReadInt16(); byte[] str = reader.ReadBytes(cch); this.Link = Encoding.ASCII.GetString(str); //skip the terminating zero of the ANSI string //even if the characters are ANSI chars, the terminating zero has 2 bytes reader.ReadBytes(2); //skip the next 4 bytes (flags?) reader.ReadBytes(4); //Read the Unicode version cch = reader.ReadInt16(); str = reader.ReadBytes(cch * 2); this.Link = Encoding.Unicode.GetString(str); //skip the terminating zero of the Unicode string reader.ReadBytes(2); } catch (StreamNotFoundException) { } }
public CustomToolbarWrapper(VirtualStreamReader reader) : base(reader, ByteStructure.VARIABLE_LENGTH) { long startPos = reader.BaseStream.Position; //skip the first 7 bytes byte[] skipped = reader.ReadBytes(7); this.cbTBD = reader.ReadInt16(); this.cCust = reader.ReadInt16(); this.cbDTBC = reader.ReadInt32(); this.rTBDC = new List <ToolbarControl>(); int rTbdcEndPos = (int)(reader.BaseStream.Position + cbDTBC); while (reader.BaseStream.Position < rTbdcEndPos) { this.rTBDC.Add(new ToolbarControl(reader)); } reader.BaseStream.Seek(rTbdcEndPos, System.IO.SeekOrigin.Begin); this.rCustomizations = new List <ToolbarCustomization>(); for (int i = 0; i < cCust; i++) { this.rCustomizations.Add(new ToolbarCustomization(reader)); } long endPos = reader.BaseStream.Position; //read the raw bytes reader.BaseStream.Seek(startPos - 1, System.IO.SeekOrigin.Begin); this._rawBytes = reader.ReadBytes((int)(endPos - startPos + 1)); }
private void ProcessFormulaValue() { if (this.val[6] == 0xFF && this.val[7] == 0xFF) { // this value is a string, an error or a boolean value byte firstOffset = this.val[0]; if (firstOffset == 1) { // this is a boolean value this.boolValue = this.val[2]; this.boolValueSet = true; } if (firstOffset == 2) { // this is a error value this.errorValue = (int)this.val[2]; } } else { using (BinaryReader b = new VirtualStreamReader(new MemoryStream(this.val))) { this.calculatedValue = b.ReadDouble(); } } }
public PropertySet(VirtualStreamReader stream) { long pos = stream.BaseStream.Position; //read size and number of properties this.size = stream.ReadUInt32(); this.numProperties = stream.ReadUInt32(); //read the identifier and offsets this.identifiers = new UInt32[this.numProperties]; this.offsets = new UInt32[this.numProperties]; for (int i = 0; i < this.numProperties; i++) { this.identifiers[i] = stream.ReadUInt32(); this.offsets[i] = stream.ReadUInt32(); } //read the properties for (int i = 0; i < this.numProperties; i++) { if (this.identifiers[i] == 0) { // dictionary property throw new NotImplementedException("Dictionary Properties are not yet implemented!"); } else { // value property this.Add(new ValueProperty(stream)); } } // seek to the end of the property set to avoid crashes stream.BaseStream.Seek(pos + size, SeekOrigin.Begin); }
public ListTable(FileInformationBlock fib, VirtualStream tableStream) { if (fib.lcbPlfLst > 0) { var reader = new VirtualStreamReader(tableStream); reader.BaseStream.Seek(fib.fcPlfLst, System.IO.SeekOrigin.Begin); //the ListTable is not a real plex: //it starts with a count, followed by the array of LSTF structs, //followed by the array of LVLF structs //read count short count = reader.ReadInt16(); //read the LSTF structs for (int i = 0; i < count; i++) { this.Add(new ListData(reader, ByteStructure.VARIABLE_LENGTH)); } //read the LVLF structs for (int i = 0; i < count; i++) { var lstf = this[i]; for (int j = 0; j < lstf.rglvl.Length; j++) { lstf.rglvl[j] = new ListLevel(reader, ByteStructure.VARIABLE_LENGTH); } } } }
public ListFormatOverrideTable(FileInformationBlock fib, VirtualStream tableStream) { if (fib.lcbPlfLfo > 0) { var reader = new VirtualStreamReader(tableStream); reader.BaseStream.Seek((long)fib.fcPlfLfo, System.IO.SeekOrigin.Begin); //read the count of LFOs int count = reader.ReadInt32(); //read the LFOs for (int i = 0; i < count; i++) { this.Add(new ListFormatOverride(reader, LFO_LENGTH)); } //read the LFOLVLs for (int i = 0; i < count; i++) { for (int j = 0; j < this[i].clfolvl; j++) { this[i].rgLfoLvl[j] = new ListFormatOverrideLevel(reader, LFOLVL_LENGTH); } } } }
public void TestParseRC4CryptoAPIFilePassRecord() { byte[] rc4CryptoApiFilePassRecord = new byte[] { 0x2F, 0x00, 0xC8, 0x00, 0x01, 0x00, 0x04, 0x00, 0x02, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x68, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x00, 0x69, 0x00, 0x63, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x73, 0x00, 0x6F, 0x00, 0x66, 0x00, 0x74, 0x00, 0x20, 0x00, 0x45, 0x00, 0x6E, 0x00, 0x68, 0x00, 0x61, 0x00, 0x6E, 0x00, 0x63, 0x00, 0x65, 0x00, 0x64, 0x00, 0x20, 0x00, 0x43, 0x00, 0x72, 0x00, 0x79, 0x00, 0x70, 0x00, 0x74, 0x00, 0x6F, 0x00, 0x67, 0x00, 0x72, 0x00, 0x61, 0x00, 0x70, 0x00, 0x68, 0x00, 0x69, 0x00, 0x63, 0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x76, 0x00, 0x69, 0x00, 0x64, 0x00, 0x65, 0x00, 0x72, 0x00, 0x20, 0x00, 0x76, 0x00, 0x31, 0x00, 0x2E, 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x98, 0xC3, 0xA1, 0xA0, 0x9A, 0xC8, 0x92, 0x3D, 0x7A, 0x5D, 0x03, 0x30, 0x34, 0xE8, 0x67, 0x64, 0xA8, 0xA9, 0x29, 0xF0, 0xA6, 0xA8, 0xB6, 0xA1, 0x1F, 0x8C, 0x6F, 0x27, 0xB6, 0xA8, 0x82, 0xEB, 0x14, 0x00, 0x00, 0x00, 0xE8, 0xAF, 0x8B, 0x67, 0x4E, 0x3F, 0xA7, 0xA1, 0x39, 0x9D, 0x9F, 0x2D, 0xDC, 0xB5, 0x1A, 0x33, 0x5D, 0x8A, 0xB2, 0x69 }; VirtualStreamReader vsr = new VirtualStreamReader(new MemoryStream(rc4CryptoApiFilePassRecord)); FilePass filePassRecord = new FilePass(vsr, (RecordType)vsr.ReadUInt16(), vsr.ReadUInt16()); byte[] filePassBytes = filePassRecord.GetBytes(); Assert.AreEqual(rc4CryptoApiFilePassRecord.Length, filePassBytes.Length); Assert.IsFalse(filePassRecord.encryptionHeader.fDocProps); Assert.IsFalse(filePassRecord.encryptionHeader.fCryptoAPI); Assert.IsTrue(filePassRecord.encryptionHeader.fExternal); Assert.IsTrue(filePassRecord.encryptionHeader.fAES); for (int offset = 0; offset < rc4CryptoApiFilePassRecord.Length; offset += 1) { Assert.AreEqual(rc4CryptoApiFilePassRecord[offset], filePassBytes[offset]); } }
public KeyMapEntry(VirtualStreamReader reader) : base(reader, KME_LENGTH) { //ignore the first 4 bytes reader.ReadBytes(4); //Primary KCM this.kcm1 = reader.ReadInt16(); //Secondary KCM this.kcm2 = reader.ReadInt16(); //Key Action Type this.kt = (ActionType)reader.ReadInt16(); //read the params switch (this.kt) { case ActionType.ktCid: this.paramCid = new CommandIdentifier(reader); break; case ActionType.ktChar: this.paramChar = (char)reader.ReadInt32(); break; default: reader.ReadBytes(4); break; } }
public ToolbarControlBitmap(VirtualStreamReader reader) : base(reader, ByteStructure.VARIABLE_LENGTH) { this.cbDIB = reader.ReadInt32(); //ToDo: Read TBCBitmap reader.ReadBytes(cbDIB - 10); }
/// <summary> /// CTor /// </summary> /// <param name="reader"></param> /// <param name="bsd"> Boundsheetdata container</param> public MacroWorksheetExtractor(VirtualStreamReader reader, MacroWorkSheetData bsd) : base(reader) { UnparsedHeaders = new List <BiffHeader>(); this.bsd = bsd; this.extractData(); }
/// <summary> /// Ctor /// </summary> /// <param name="sum">workbookstream </param> public Extractor(VirtualStreamReader reader) { this.StreamReader = reader; if (this.StreamReader == null) { throw new ExtractorException(ExtractorException.NULLPOINTEREXCEPTION); } }
public SectionDescriptor(VirtualStreamReader reader, int length) : base(reader, length) { this.fn = _reader.ReadInt16(); this.fcSepx = _reader.ReadInt32(); this.fnMpr = _reader.ReadInt16(); this.fcMpr = _reader.ReadInt32(); }
/// <summary> /// Parses the given StreamReader to retrieve a LVL struct /// </summary> /// <param name="bytes"></param> public ListLevel(VirtualStreamReader reader, int length) : base(reader, length) { long startPos = this._reader.BaseStream.Position; //parse the fix part this.iStartAt = this._reader.ReadInt32(); this.nfc = this._reader.ReadByte(); int flag = this._reader.ReadByte(); this.jc = (byte)(flag & 0x03); this.fLegal = Utils.BitmaskToBool(flag, 0x04); this.fNoRestart = Utils.BitmaskToBool(flag, 0x08); this.fPrev = Utils.BitmaskToBool(flag, 0x10); this.fPrevSpace = Utils.BitmaskToBool(flag, 0x20); this.fWord6 = Utils.BitmaskToBool(flag, 0x40); this.rgbxchNums = new byte[9]; for (int i = 0; i < 9; i++) { this.rgbxchNums[i] = this._reader.ReadByte(); } this.ixchFollow = (FollowingChar)this._reader.ReadByte(); this.dxaSpace = this._reader.ReadInt32(); this.dxaIndent = this._reader.ReadInt32(); this.cbGrpprlChpx = this._reader.ReadByte(); this.cbGrpprlPapx = this._reader.ReadByte(); this.ilvlRestartLim = this._reader.ReadByte(); this.grfhic = this._reader.ReadByte(); //parse the variable part //read the group of papx sprms //this papx has no istd, so use PX to parse it var px = new PropertyExceptions(this._reader.ReadBytes(this.cbGrpprlPapx)); this.grpprlPapx = new ParagraphPropertyExceptions { grpprl = px.grpprl }; //read the group of chpx sprms this.grpprlChpx = new CharacterPropertyExceptions(this._reader.ReadBytes(this.cbGrpprlChpx)); //read the number text short strLen = this._reader.ReadInt16(); this.xst = Encoding.Unicode.GetString(this._reader.ReadBytes(strLen * 2)); long endPos = this._reader.BaseStream.Position; this._reader.BaseStream.Seek(startPos, System.IO.SeekOrigin.Begin); this._rawBytes = this._reader.ReadBytes((int)(endPos - startPos)); }
private BoundSheet8 BuildBoundSheetFromBytes(byte[] bytes) { using (MemoryStream ms = new MemoryStream(bytes)) { VirtualStreamReader vsr = new VirtualStreamReader(ms); RecordType id = (RecordType)vsr.ReadUInt16(); ushort len = vsr.ReadUInt16(); return(new BoundSheet8(vsr, id, len)); } }
private void parse(VirtualStream stream, int fc) { stream.Seek(fc, System.IO.SeekOrigin.Begin); var reader = new VirtualStreamReader(stream); this.lcb = reader.ReadInt32(); this.cbHeader = reader.ReadInt16(); reader.ReadBytes(62); this.binData = reader.ReadBytes(this.lcb - this.cbHeader); }
public CommentAuthorTable(FileInformationBlock fib, VirtualStream tableStream) { tableStream.Seek(fib.fcGrpXstAtnOwners, System.IO.SeekOrigin.Begin); VirtualStreamReader reader = new VirtualStreamReader(tableStream); while (tableStream.Position < (fib.fcGrpXstAtnOwners + fib.lcbGrpXstAtnOwners)) { Int16 cch = reader.ReadInt16(); this.Add(Encoding.Unicode.GetString(reader.ReadBytes(cch * 2))); } }
/// <summary> /// Ctor /// </summary> /// <param name="sum">Summary stream </param> public FileInformationExtractor(VirtualStream sum) { this.Title = null; if (sum == null) { throw new ExtractorException(ExtractorException.NULLPOINTEREXCEPTION); } this.summaryStream = sum; this.SummaryStream = new VirtualStreamReader(sum); this.extractData(); }
public ByteStructure(VirtualStreamReader reader, int length) { _reader = reader; _length = length; //read the raw bytes if (_length != VARIABLE_LENGTH) { _rawBytes = _reader.ReadBytes(_length); _reader.BaseStream.Seek(-1 * _length, System.IO.SeekOrigin.Current); } }
public ByteStructure(VirtualStreamReader reader, int length) { this._reader = reader; this._length = length; //read the raw bytes if (this._length != VARIABLE_LENGTH) { this._rawBytes = this._reader.ReadBytes(this._length); this._reader.BaseStream.Seek(-1 * this._length, SeekOrigin.Current); } }
public AnnotationReferenceDescriptorExtra(VirtualStreamReader reader, int length) : base(reader, length) { this.Date = new DateAndTime(_reader.ReadBytes(4)); _reader.ReadBytes(2); this.CommentDepth = _reader.ReadInt32(); this.ParentOffset = _reader.ReadInt32(); if (length > 16) { Int32 flag = _reader.ReadInt32(); } }
public ValueProperty(VirtualStreamReader stream) { //read type this.Type = (PropertyType)stream.ReadUInt16(); //skip padding stream.ReadBytes(2); //read data if ( this.Type == PropertyType.SignedInt16 || this.Type == PropertyType.UnsignedInt16 ) { // 2 bytes data this.Data = stream.ReadBytes(2); } else if ( this.Type == PropertyType.SignedInt32 || this.Type == PropertyType.UnsignedInt32 || this.Type == PropertyType.FloatingPoint32 || this.Type == PropertyType.NewSignedInt32 || this.Type == PropertyType.NewUnsignedInt32 || this.Type == PropertyType.HResult || this.Type == PropertyType.Boolean) { // 4 bytes data this.Data = stream.ReadBytes(4); } else if ( this.Type == PropertyType.FloatingPoint64 || this.Type == PropertyType.SignedInt64 || this.Type == PropertyType.UsignedInt64 || this.Type == PropertyType.Currency || this.Type == PropertyType.Date ) { // 8 bytes data this.Data = stream.ReadBytes(8); } else if ( this.Type == PropertyType.Decimal ) { // 16 bytes data this.Data = stream.ReadBytes(16); } else { // not yet implemented this.Data = new byte[0]; } }
public void DoTheMagic() { try { using (StructuredStorageReader reader = new StructuredStorageReader(this.Options.InputDocument)) { IStreamReader workbookReader = new VirtualStreamReader(reader.GetStream("Workbook")); using (StreamWriter sw = this.Options.Mode == BiffViewerMode.File ? File.CreateText(this.Options.OutputFileName) : new StreamWriter(Console.OpenStandardOutput())) { sw.AutoFlush = true; if (this.Options.PrintTextOnly) { PrintText(sw, workbookReader); } else { PrintHtml(sw, workbookReader); } if (!_isCancelled && this.Options.ShowInBrowser && this.Options.Mode == BiffViewerMode.File) { Util.VisitLink(this.Options.OutputFileName); } } } } catch (MagicNumberException ex) { if (this.Options.ShowErrors) { MessageBox.Show(string.Format("This file is not a valid Excel file ({0})", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Console.WriteLine(ex.ToString()); } } catch (Exception ex) { if (this.Options.ShowErrors) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Console.WriteLine(ex.ToString()); } } }
public MacroData(VirtualStreamReader reader) : base(reader, MCD_LENGTH) { //first 2 bytes are reserved reader.ReadBytes(2); this.ibst = reader.ReadInt16(); this.ibstName = reader.ReadInt16(); //last 18 bytes are reserved reader.ReadBytes(18); }
private long searchTerminationZero(VirtualStreamReader reader) { long strStart = reader.BaseStream.Position; while (reader.ReadInt16() != 0) { ; } long pos = reader.BaseStream.Position; reader.BaseStream.Seek(strStart, System.IO.SeekOrigin.Begin); return(pos); }
/// <summary> /// Ctor /// </summary> /// <param name="reader">Reader</param> public WorkbookExtractor(VirtualStreamReader reader, WorkBookData workBookData) : base(reader) { this.boundsheets = new List <BoundSheet8>(); this.supBooks = new List <SupBook>(); this.externSheets = new List <ExternSheet>(); this.XCTList = new List <XCT>(); this.CRNList = new List <CRN>(); this.workBookData = workBookData; this.oldOffset = 0; this.extractData(); }
public Plex(int structureLength, VirtualStream tableStream, uint fc, uint lcb) { tableStream.Seek((long)fc, System.IO.SeekOrigin.Begin); var reader = new VirtualStreamReader(tableStream); int n = 0; if (structureLength > 0) { //this PLEX contains CPs and Elements n = ((int)lcb - CP_LENGTH) / (structureLength + CP_LENGTH); } else { //this PLEX only contains CPs n = ((int)lcb - CP_LENGTH) / CP_LENGTH; } //read the n + 1 CPs this.CharacterPositions = new List <int>(); for (int i = 0; i < n + 1; i++) { this.CharacterPositions.Add(reader.ReadInt32()); } //read the n structs this.Elements = new List <T>(); var genericType = typeof(T); if (genericType == typeof(short)) { this.Elements = new List <T>(); for (int i = 0; i < n; i++) { short value = reader.ReadInt16(); var genericValue = (T)Convert.ChangeType(value, typeof(T)); this.Elements.Add(genericValue); } } else if (structureLength > 0) { for (int i = 0; i < n; i++) { var constructor = genericType.GetConstructor(new Type[] { typeof(VirtualStreamReader), typeof(int) }); object value = constructor.Invoke(new object[] { reader, structureLength }); var genericValue = (T)Convert.ChangeType(value, typeof(T)); this.Elements.Add(genericValue); } } }