示例#1
0
        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);
        }
示例#2
0
 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));
     }
 }
        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]);
            }
        }
示例#4
0
        public static T AsRecordType <T>(this BiffRecord record) where T : BiffRecord
        {
            byte[] recordBytes = record.GetBytes();
            using (MemoryStream ms = new MemoryStream(recordBytes))
            {
                VirtualStreamReader vsr = new VirtualStreamReader(ms);
                RecordType          id  = (RecordType)vsr.ReadUInt16();
                ushort len             = vsr.ReadUInt16();
                var    typeConstructor = typeof(T).GetConstructor(new Type[]
                                                                  { typeof(IStreamReader), typeof(RecordType), typeof(ushort) });

                if (typeConstructor == null)
                {
                    throw new ArgumentException(string.Format("Could not find appropriate constructor for type {0}", typeof(T).FullName));
                }

                return((T)typeConstructor.Invoke(new object[] { vsr, id, len }));
            }
        }
        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();
                UInt16     length = vsr.ReadUInt16();

                BiffRecord br = new BiffRecord(vsr, id, length);

                vsr.ReadBytes(length);
                records.Add(br);
            }

            return(records);
        }
示例#6
0
        public ToolbarDelta(VirtualStreamReader reader)
            : base(reader, TBDelta_LENGTH)
        {
            byte flags1 = reader.ReadByte();

            this.dopr   = Utils.BitmaskToInt((int)flags1, 0x03);
            this.fAtEnd = Utils.BitmaskToBool((int)flags1, 0x04);

            this.ibts    = reader.ReadByte();
            this.cidNext = reader.ReadInt32();
            this.cid     = reader.ReadInt32();
            this.fc      = reader.ReadInt32();

            UInt16 flags2 = reader.ReadUInt16();

            this.fOnDisk = Utils.BitmaskToBool((int)flags2, 0x0001);
            this.iTB     = Utils.BitmaskToInt((int)flags2, 0x3FFE);
            this.fDead   = Utils.BitmaskToBool((int)flags2, 0x8000);

            this.cbTBC = reader.ReadUInt16();
        }
示例#7
0
        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];
            }
        }
示例#8
0
        /// <summary>
        /// Parses the streams to retrieve a StyleSheet.
        /// </summary>
        /// <param name="fib">The FileInformationBlock</param>
        /// <param name="tableStream">The 0Table or 1Table stream</param>
        public StyleSheet(FileInformationBlock fib, VirtualStream tableStream, VirtualStream dataStream)
        {
            IStreamReader tableReader = new VirtualStreamReader(tableStream);

            //read size of the STSHI
            var stshiLengthBytes = new byte[2];

            tableStream.Read(stshiLengthBytes, 0, stshiLengthBytes.Length, fib.fcStshf);
            short cbStshi = System.BitConverter.ToInt16(stshiLengthBytes, 0);

            //read the bytes of the STSHI
            var stshi = tableReader.ReadBytes(fib.fcStshf + 2, cbStshi);

            //parses STSHI
            this.stshi = new StyleSheetInformation(stshi);

            //create list of STDs
            this.Styles = new List <StyleSheetDescription>();
            for (int i = 0; i < this.stshi.cstd; i++)
            {
                //get the cbStd
                ushort cbStd = tableReader.ReadUInt16();

                if (cbStd != 0)
                {
                    //read the STD bytes
                    var std = tableReader.ReadBytes(cbStd);

                    //parse the STD bytes
                    this.Styles.Add(new StyleSheetDescription(std, (int)this.stshi.cbSTDBaseInFile, dataStream));
                }
                else
                {
                    this.Styles.Add(null);
                }
            }
        }
示例#9
0
        //*****************************************************************************************
        //                                                                              CONSTRUCTOR
        //*****************************************************************************************

        public FileInformationBlock(VirtualStreamReader reader)
        {
            UInt16 flag16 = 0;
            byte   flag8  = 0;

            //read the FIB base
            this.wIdent = reader.ReadUInt16();
            this.nFib   = (FibVersion)reader.ReadUInt16();
            reader.ReadBytes(2);
            this.lid                  = reader.ReadUInt16();
            this.pnNext               = reader.ReadInt16();
            flag16                    = reader.ReadUInt16();
            this.fDot                 = Utils.BitmaskToBool((int)flag16, 0x0001);
            this.fGlsy                = Utils.BitmaskToBool((int)flag16, 0x0002);
            this.fComplex             = Utils.BitmaskToBool((int)flag16, 0x0002);
            this.fHasPic              = Utils.BitmaskToBool((int)flag16, 0x0008);
            this.cQuickSaves          = (UInt16)(((int)flag16 & 0x00F0) >> 4);
            this.fEncrypted           = Utils.BitmaskToBool((int)flag16, 0x0100);
            this.fWhichTblStm         = Utils.BitmaskToBool((int)flag16, 0x0200);
            this.fReadOnlyRecommended = Utils.BitmaskToBool((int)flag16, 0x0400);
            this.fWriteReservation    = Utils.BitmaskToBool((int)flag16, 0x0800);
            this.fExtChar             = Utils.BitmaskToBool((int)flag16, 0x1000);
            this.fLoadOverwrite       = Utils.BitmaskToBool((int)flag16, 0x2000);
            this.fFarEast             = Utils.BitmaskToBool((int)flag16, 0x4000);
            this.fCrypto              = Utils.BitmaskToBool((int)flag16, 0x8000);
            this.nFibBack             = reader.ReadUInt16();
            this.lKey                 = reader.ReadInt32();
            this.envr                 = reader.ReadByte();
            flag8                  = reader.ReadByte();
            this.fMac              = Utils.BitmaskToBool((int)flag8, 0x01);
            this.fEmptySpecial     = Utils.BitmaskToBool((int)flag8, 0x02);
            this.fLoadOverridePage = Utils.BitmaskToBool((int)flag8, 0x04);
            this.fFutureSavedUndo  = Utils.BitmaskToBool((int)flag8, 0x08);
            this.fWord97Saved      = Utils.BitmaskToBool((int)flag8, 0x10);
            reader.ReadBytes(4);
            this.fcMin = reader.ReadInt32();
            this.fcMac = reader.ReadInt32();

            this.csw = reader.ReadUInt16();

            //read the RgW97
            reader.ReadBytes(26);
            this.lidFE = reader.ReadInt16();

            this.cslw = reader.ReadUInt16();

            //read the RgLW97
            this.cbMac = reader.ReadInt32();
            reader.ReadBytes(8);
            this.ccpText = reader.ReadInt32();
            this.ccpFtn  = reader.ReadInt32();
            this.ccpHdr  = reader.ReadInt32();
            reader.ReadBytes(4);
            this.ccpAtn     = reader.ReadInt32();
            this.ccpEdn     = reader.ReadInt32();
            this.ccpTxbx    = reader.ReadInt32();
            this.ccpHdrTxbx = reader.ReadInt32();
            reader.ReadBytes(44);

            this.cbRgFcLcb = reader.ReadUInt16();

            if (this.nFib >= FibVersion.Fib1997Beta)
            {
                //Read the FibRgFcLcb97
                this.fcStshfOrig    = reader.ReadUInt32();
                this.lcbStshfOrig   = reader.ReadUInt32();
                this.fcStshf        = reader.ReadUInt32();
                this.lcbStshf       = reader.ReadUInt32();
                this.fcPlcffndRef   = reader.ReadUInt32();
                this.lcbPlcffndRef  = reader.ReadUInt32();
                this.fcPlcffndTxt   = reader.ReadUInt32();
                this.lcbPlcffndTxt  = reader.ReadUInt32();
                this.fcPlcfandRef   = reader.ReadUInt32();
                this.lcbPlcfandRef  = reader.ReadUInt32();
                this.fcPlcfandTxt   = reader.ReadUInt32();
                this.lcbPlcfandTxt  = reader.ReadUInt32();
                this.fcPlcfSed      = reader.ReadUInt32();
                this.lcbPlcfSed     = reader.ReadUInt32();
                this.fcPlcPad       = reader.ReadUInt32();
                this.lcbPlcPad      = reader.ReadUInt32();
                this.fcPlcfPhe      = reader.ReadUInt32();
                this.lcbPlcfPhe     = reader.ReadUInt32();
                this.fcSttbfGlsy    = reader.ReadUInt32();
                this.lcbSttbfGlsy   = reader.ReadUInt32();
                this.fcPlcfGlsy     = reader.ReadUInt32();
                this.lcbPlcfGlsy    = reader.ReadUInt32();
                this.fcPlcfHdd      = reader.ReadUInt32();
                this.lcbPlcfHdd     = reader.ReadUInt32();
                this.fcPlcfBteChpx  = reader.ReadUInt32();
                this.lcbPlcfBteChpx = reader.ReadUInt32();
                this.fcPlcfBtePapx  = reader.ReadUInt32();
                this.lcbPlcfBtePapx = reader.ReadUInt32();
                this.fcPlcfSea      = reader.ReadUInt32();
                this.lcbPlcfSea     = reader.ReadUInt32();
                this.fcSttbfFfn     = reader.ReadUInt32();
                this.lcbSttbfFfn    = reader.ReadUInt32();
                this.fcPlcfFldMom   = reader.ReadUInt32();
                this.lcbPlcfFldMom  = reader.ReadUInt32();
                this.fcPlcfFldHdr   = reader.ReadUInt32();
                this.lcbPlcfFldHdr  = reader.ReadUInt32();
                this.fcPlcfFldFtn   = reader.ReadUInt32();
                this.lcbPlcfFldFtn  = reader.ReadUInt32();
                this.fcPlcfFldAtn   = reader.ReadUInt32();
                this.lcbPlcfFldAtn  = reader.ReadUInt32();
                this.fcPlcfFldMcr   = reader.ReadUInt32();
                this.lcbPlcfFldMcr  = reader.ReadUInt32();
                this.fcSttbfBkmk    = reader.ReadUInt32();
                this.lcbSttbfBkmk   = reader.ReadUInt32();
                this.fcPlcfBkf      = reader.ReadUInt32();
                this.lcbPlcfBkf     = reader.ReadUInt32();
                this.fcPlcfBkl      = reader.ReadUInt32();
                this.lcbPlcfBkl     = reader.ReadUInt32();
                this.fcCmds         = reader.ReadUInt32();
                this.lcbCmds        = reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                this.fcSttbfMcr         = reader.ReadUInt32();
                this.lcbSttbfMcr        = reader.ReadUInt32();
                this.fcPrDrvr           = reader.ReadUInt32();
                this.lcbPrDrvr          = reader.ReadUInt32();
                this.fcPrEnvPort        = reader.ReadUInt32();
                this.lcbPrEnvPort       = reader.ReadUInt32();
                this.fcPrEnvLand        = reader.ReadUInt32();
                this.lcbPrEnvLand       = reader.ReadUInt32();
                this.fcWss              = reader.ReadUInt32();
                this.lcbWss             = reader.ReadUInt32();
                this.fcDop              = reader.ReadUInt32();
                this.lcbDop             = reader.ReadUInt32();
                this.fcSttbfAssoc       = reader.ReadUInt32();
                this.lcbSttbfAssoc      = reader.ReadUInt32();
                this.fcClx              = reader.ReadUInt32();
                this.lcbClx             = reader.ReadUInt32();
                this.fcPlcfPgdFtn       = reader.ReadUInt32();
                this.lcbPlcfPgdFtn      = reader.ReadUInt32();
                this.fcAutosaveSource   = reader.ReadUInt32();
                this.lcbAutosaveSource  = reader.ReadUInt32();
                this.fcGrpXstAtnOwners  = reader.ReadUInt32();
                this.lcbGrpXstAtnOwners = reader.ReadUInt32();
                this.fcSttbfAtnBkmk     = reader.ReadUInt32();
                this.lcbSttbfAtnBkmk    = reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                this.fcPlcSpaMom     = reader.ReadUInt32();
                this.lcbPlcSpaMom    = reader.ReadUInt32();
                this.fcPlcSpaHdr     = reader.ReadUInt32();
                this.lcbPlcSpaHdr    = reader.ReadUInt32();
                this.fcPlcfAtnBkf    = reader.ReadUInt32();
                this.lcbPlcfAtnBkf   = reader.ReadUInt32();
                this.fcPlcfAtnBkl    = reader.ReadUInt32();
                this.lcbPlcfAtnBkl   = reader.ReadUInt32();
                this.fcPms           = reader.ReadUInt32();
                this.lcbPms          = reader.ReadUInt32();
                this.fcFormFldSttbs  = reader.ReadUInt32();
                this.lcbFormFldSttbs = reader.ReadUInt32();
                this.fcPlcfendRef    = reader.ReadUInt32();
                this.lcbPlcfendRef   = reader.ReadUInt32();
                this.fcPlcfendTxt    = reader.ReadUInt32();
                this.lcbPlcfendTxt   = reader.ReadUInt32();
                this.fcPlcfFldEdn    = reader.ReadUInt32();
                this.lcbPlcfFldEdn   = reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                this.fcDggInfo           = reader.ReadUInt32();
                this.lcbDggInfo          = reader.ReadUInt32();
                this.fcSttbfRMark        = reader.ReadUInt32();
                this.lcbSttbfRMark       = reader.ReadUInt32();
                this.fcSttbfCaption      = reader.ReadUInt32();
                this.lcbSttbfCaption     = reader.ReadUInt32();
                this.fcSttbfAutoCaption  = reader.ReadUInt32();
                this.lcbSttbfAutoCaption = reader.ReadUInt32();
                this.fcPlcfWkb           = reader.ReadUInt32();
                this.lcbPlcfWkb          = reader.ReadUInt32();
                this.fcPlcfSpl           = reader.ReadUInt32();
                this.lcbPlcfSpl          = reader.ReadUInt32();
                this.fcPlcftxbxTxt       = reader.ReadUInt32();
                this.lcbPlcftxbxTxt      = reader.ReadUInt32();
                this.fcPlcfFldTxbx       = reader.ReadUInt32();
                this.lcbPlcfFldTxbx      = reader.ReadUInt32();
                this.fcPlcfHdrtxbxTxt    = reader.ReadUInt32();
                this.lcbPlcfHdrtxbxTxt   = reader.ReadUInt32();
                this.fcPlcffldHdrTxbx    = reader.ReadUInt32();
                this.lcbPlcffldHdrTxbx   = reader.ReadUInt32();
                this.fcStwUser           = reader.ReadUInt32();
                this.lcbStwUser          = reader.ReadUInt32();
                this.fcSttbTtmbd         = reader.ReadUInt32();
                this.lcbSttbTtmbd        = reader.ReadUInt32();
                this.fcCookieData        = reader.ReadUInt32();
                this.lcbCookieData       = reader.ReadUInt32();
                this.fcPgdMotherOldOld   = reader.ReadUInt32();
                this.lcbPgdMotherOldOld  = reader.ReadUInt32();
                this.fcBkdMotherOldOld   = reader.ReadUInt32();
                this.lcbBkdMotherOldOld  = reader.ReadUInt32();
                this.fcPgdFtnOldOld      = reader.ReadUInt32();
                this.lcbPgdFtnOldOld     = reader.ReadUInt32();
                this.fcBkdFtnOldOld      = reader.ReadUInt32();
                this.lcbBkdFtnOldOld     = reader.ReadUInt32();
                this.fcPgdEdnOldOld      = reader.ReadUInt32();
                this.lcbPgdEdnOldOld     = reader.ReadUInt32();
                this.fcBkdEdnOldOld      = reader.ReadUInt32();
                this.lcbBkdEdnOldOld     = reader.ReadUInt32();
                this.fcSttbfIntlFld      = reader.ReadUInt32();
                this.lcbSttbfIntlFld     = reader.ReadUInt32();
                this.fcRouteSlip         = reader.ReadUInt32();
                this.lcbRouteSlip        = reader.ReadUInt32();
                this.fcSttbSavedBy       = reader.ReadUInt32();
                this.lcbSttbSavedBy      = reader.ReadUInt32();
                this.fcSttbFnm           = reader.ReadUInt32();
                this.lcbSttbFnm          = reader.ReadUInt32();
                this.fcPlfLst            = reader.ReadUInt32();
                this.lcbPlfLst           = reader.ReadUInt32();
                this.fcPlfLfo            = reader.ReadUInt32();
                this.lcbPlfLfo           = reader.ReadUInt32();
                this.fcPlcfTxbxBkd       = reader.ReadUInt32();
                this.lcbPlcfTxbxBkd      = reader.ReadUInt32();
                this.fcPlcfTxbxHdrBkd    = reader.ReadUInt32();
                this.lcbPlcfTxbxHdrBkd   = reader.ReadUInt32();
                this.fcDocUndoWord9      = reader.ReadUInt32();
                this.lcbDocUndoWord9     = reader.ReadUInt32();
                this.fcRgbUse            = reader.ReadUInt32();
                this.lcbRgbUse           = reader.ReadUInt32();
                this.fcUsp            = reader.ReadUInt32();
                this.lcbUsp           = reader.ReadUInt32();
                this.fcUskf           = reader.ReadUInt32();
                this.lcbUskf          = reader.ReadUInt32();
                this.fcPlcupcRgbUse   = reader.ReadUInt32();
                this.lcbPlcupcRgbUse  = reader.ReadUInt32();
                this.fcPlcupcUsp      = reader.ReadUInt32();
                this.lcbPlcupcUsp     = reader.ReadUInt32();
                this.fcSttbGlsyStyle  = reader.ReadUInt32();
                this.lcbSttbGlsyStyle = reader.ReadUInt32();
                this.fcPlgosl         = reader.ReadUInt32();
                this.lcbPlgosl        = reader.ReadUInt32();
                this.fcPlcocx         = reader.ReadUInt32();
                this.lcbPlcocx        = reader.ReadUInt32();
                this.fcPlcfBteLvc     = reader.ReadUInt32();
                this.lcbPlcfBteLvc    = reader.ReadUInt32();
                this.dwLowDateTime    = reader.ReadUInt32();
                this.dwHighDateTime   = reader.ReadUInt32();
                this.fcPlcfLvcPre10   = reader.ReadUInt32();
                this.lcbPlcfLvcPre10  = reader.ReadUInt32();
                this.fcPlcfAsumy      = reader.ReadUInt32();
                this.lcbPlcfAsumy     = reader.ReadUInt32();
                this.fcPlcfGram       = reader.ReadUInt32();
                this.lcbPlcfGram      = reader.ReadUInt32();
                this.fcSttbListNames  = reader.ReadUInt32();
                this.lcbSttbListNames = reader.ReadUInt32();
                this.fcSttbfUssr      = reader.ReadUInt32();
                this.lcbSttbfUssr     = reader.ReadUInt32();
            }
            if (this.nFib >= FibVersion.Fib2000)
            {
                //Read also the FibRgFcLcb2000
                this.fcPlcfTch        = reader.ReadUInt32();
                this.lcbPlcfTch       = reader.ReadUInt32();
                this.fcRmdThreading   = reader.ReadUInt32();
                this.lcbRmdThreading  = reader.ReadUInt32();
                this.fcMid            = reader.ReadUInt32();
                this.lcbMid           = reader.ReadUInt32();
                this.fcSttbRgtplc     = reader.ReadUInt32();
                this.lcbSttbRgtplc    = reader.ReadUInt32();
                this.fcMsoEnvelope    = reader.ReadUInt32();
                this.lcbMsoEnvelope   = reader.ReadUInt32();
                this.fcPlcfLad        = reader.ReadUInt32();
                this.lcbPlcfLad       = reader.ReadUInt32();
                this.fcRgDofr         = reader.ReadUInt32();
                this.lcbRgDofr        = reader.ReadUInt32();
                this.fcPlcosl         = reader.ReadUInt32();
                this.lcbPlcosl        = reader.ReadUInt32();
                this.fcPlcfCookieOld  = reader.ReadUInt32();
                this.lcbPlcfCookieOld = reader.ReadUInt32();
                this.fcPgdMotherOld   = reader.ReadUInt32();
                this.lcbPgdMotherOld  = reader.ReadUInt32();
                this.fcBkdMotherOld   = reader.ReadUInt32();
                this.lcbBkdMotherOld  = reader.ReadUInt32();
                this.fcPgdFtnOld      = reader.ReadUInt32();
                this.lcbPgdFtnOld     = reader.ReadUInt32();
                this.fcBkdFtnOld      = reader.ReadUInt32();
                this.lcbBkdFtnOld     = reader.ReadUInt32();
                this.fcPgdEdnOld      = reader.ReadUInt32();
                this.lcbPgdEdnOld     = reader.ReadUInt32();
                this.fcBkdEdnOld      = reader.ReadUInt32();
                this.lcbBkdEdnOld     = reader.ReadUInt32();
            }
            if (this.nFib >= FibVersion.Fib2002)
            {
                //Read also the fibRgFcLcb2002
                reader.ReadUInt32();
                reader.ReadUInt32();
                this.fcPlcfPgp             = reader.ReadUInt32();
                this.lcbPlcfPgp            = reader.ReadUInt32();
                this.fcPlcfuim             = reader.ReadUInt32();
                this.lcbPlcfuim            = reader.ReadUInt32();
                this.fcPlfguidUim          = reader.ReadUInt32();
                this.lcbPlfguidUim         = reader.ReadUInt32();
                this.fcAtrdExtra           = reader.ReadUInt32();
                this.lcbAtrdExtra          = reader.ReadUInt32();
                this.fcPlrsid              = reader.ReadUInt32();
                this.lcbPlrsid             = reader.ReadUInt32();
                this.fcSttbfBkmkFactoid    = reader.ReadUInt32();
                this.lcbSttbfBkmkFactoid   = reader.ReadUInt32();
                this.fcPlcfBkfFactoid      = reader.ReadUInt32();
                this.lcbPlcfBkfFactoid     = reader.ReadUInt32();
                this.fcPlcfcookie          = reader.ReadUInt32();
                this.lcbPlcfcookie         = reader.ReadUInt32();
                this.fcPlcfBklFactoid      = reader.ReadUInt32();
                this.lcbPlcfBklFactoid     = reader.ReadUInt32();
                this.fcFactoidData         = reader.ReadUInt32();
                this.lcbFactoidData        = reader.ReadUInt32();
                this.fcDocUndo             = reader.ReadUInt32();
                this.lcbDocUndo            = reader.ReadUInt32();
                this.fcSttbfBkmkFcc        = reader.ReadUInt32();
                this.lcbSttbfBkmkFcc       = reader.ReadUInt32();
                this.fcPlcfBkfFcc          = reader.ReadUInt32();
                this.lcbPlcfBkfFcc         = reader.ReadUInt32();
                this.fcPlcfBklFcc          = reader.ReadUInt32();
                this.lcbPlcfBklFcc         = reader.ReadUInt32();
                this.fcSttbfbkmkBPRepairs  = reader.ReadUInt32();
                this.lcbSttbfbkmkBPRepairs = reader.ReadUInt32();
                this.fcPlcfbkfBPRepairs    = reader.ReadUInt32();
                this.lcbPlcfbkfBPRepairs   = reader.ReadUInt32();
                this.fcPlcfbklBPRepairs    = reader.ReadUInt32();
                this.lcbPlcfbklBPRepairs   = reader.ReadUInt32();
                this.fcPmsNew              = reader.ReadUInt32();
                this.lcbPmsNew             = reader.ReadUInt32();
                this.fcODSO            = reader.ReadUInt32();
                this.lcbODSO           = reader.ReadUInt32();
                this.fcPlcfpmiOldXP    = reader.ReadUInt32();
                this.lcbPlcfpmiOldXP   = reader.ReadUInt32();
                this.fcPlcfpmiNewXP    = reader.ReadUInt32();
                this.lcbPlcfpmiNewXP   = reader.ReadUInt32();
                this.fcPlcfpmiMixedXP  = reader.ReadUInt32();
                this.lcbPlcfpmiMixedXP = reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                this.fcPlcffactoid     = reader.ReadUInt32();
                this.lcbPlcffactoid    = reader.ReadUInt32();
                this.fcPlcflvcOldXP    = reader.ReadUInt32();
                this.lcbPlcflvcOldXP   = reader.ReadUInt32();
                this.fcPlcflvcNewXP    = reader.ReadUInt32();
                this.lcbPlcflvcNewXP   = reader.ReadUInt32();
                this.fcPlcflvcMixedXP  = reader.ReadUInt32();
                this.lcbPlcflvcMixedXP = reader.ReadUInt32();
            }
            if (this.nFib >= FibVersion.Fib2003)
            {
                //Read also the fibRgFcLcb2003
                this.fcHplxsdr        = reader.ReadUInt32();
                this.lcbHplxsdr       = reader.ReadUInt32();
                this.fcSttbfBkmkSdt   = reader.ReadUInt32();
                this.lcbSttbfBkmkSdt  = reader.ReadUInt32();
                this.fcPlcfBkfSdt     = reader.ReadUInt32();
                this.lcbPlcfBkfSdt    = reader.ReadUInt32();
                this.fcPlcfBklSdt     = reader.ReadUInt32();
                this.lcbPlcfBklSdt    = reader.ReadUInt32();
                this.fcCustomXForm    = reader.ReadUInt32();
                this.lcbCustomXForm   = reader.ReadUInt32();
                this.fcSttbfBkmkProt  = reader.ReadUInt32();
                this.lcbSttbfBkmkProt = reader.ReadUInt32();
                this.fcPlcfBkfProt    = reader.ReadUInt32();
                this.lcbPlcfBkfProt   = reader.ReadUInt32();
                this.fcPlcfBklProt    = reader.ReadUInt32();
                this.lcbPlcfBklProt   = reader.ReadUInt32();
                this.fcSttbProtUser   = reader.ReadUInt32();
                this.lcbSttbProtUser  = reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                this.fcPlcfpmiOld        = reader.ReadUInt32();
                this.lcbPlcfpmiOld       = reader.ReadUInt32();
                this.fcPlcfpmiOldInline  = reader.ReadUInt32();
                this.lcbPlcfpmiOldInline = reader.ReadUInt32();
                this.fcPlcfpmiNew        = reader.ReadUInt32();
                this.lcbPlcfpmiNew       = reader.ReadUInt32();
                this.fcPlcfpmiNewInline  = reader.ReadUInt32();
                this.lcbPlcfpmiNewInline = reader.ReadUInt32();
                this.fcPlcflvcOld        = reader.ReadUInt32();
                this.lcbPlcflvcOld       = reader.ReadUInt32();
                this.fcPlcflvcOldInline  = reader.ReadUInt32();
                this.lcbPlcflvcOldInline = reader.ReadUInt32();
                this.fcPlcflvcNew        = reader.ReadUInt32();
                this.lcbPlcflvcNew       = reader.ReadUInt32();
                this.fcPlcflvcNewInline  = reader.ReadUInt32();
                this.lcbPlcflvcNewInline = reader.ReadUInt32();
                this.fcPgdMother         = reader.ReadUInt32();
                this.lcbPgdMother        = reader.ReadUInt32();
                this.fcBkdMother         = reader.ReadUInt32();
                this.lcbBkdMother        = reader.ReadUInt32();
                this.fcAfdMother         = reader.ReadUInt32();
                this.lcbAfdMother        = reader.ReadUInt32();
                this.fcPgdFtn            = reader.ReadUInt32();
                this.lcbPgdFtn           = reader.ReadUInt32();
                this.fcBkdFtn            = reader.ReadUInt32();
                this.lcbBkdFtn           = reader.ReadUInt32();
                this.fcAfdFtn            = reader.ReadUInt32();
                this.lcbAfdFtn           = reader.ReadUInt32();
                this.fcPgdEdn            = reader.ReadUInt32();
                this.lcbPgdEdn           = reader.ReadUInt32();
                this.fcBkdEdn            = reader.ReadUInt32();
                this.lcbBkdEdn           = reader.ReadUInt32();
                this.fcAfdEdn            = reader.ReadUInt32();
                this.lcbAfdEdn           = reader.ReadUInt32();
                this.fcAfd  = reader.ReadUInt32();
                this.lcbAfd = reader.ReadUInt32();
            }
            if (this.nFib >= FibVersion.Fib2007)
            {
                //Read also the fibRgFcLcb2007
                this.fcPlcfmthd           = reader.ReadUInt32();
                this.lcbPlcfmthd          = reader.ReadUInt32();
                this.fcSttbfBkmkMoveFrom  = reader.ReadUInt32();
                this.lcbSttbfBkmkMoveFrom = reader.ReadUInt32();
                this.fcPlcfBkfMoveFrom    = reader.ReadUInt32();
                this.lcbPlcfBkfMoveFrom   = reader.ReadUInt32();
                this.fcPlcfBklMoveFrom    = reader.ReadUInt32();
                this.lcbPlcfBklMoveFrom   = reader.ReadUInt32();
                this.fcSttbfBkmkMoveTo    = reader.ReadUInt32();
                this.lcbSttbfBkmkMoveTo   = reader.ReadUInt32();
                this.fcPlcfBkfMoveTo      = reader.ReadUInt32();
                this.lcbPlcfBkfMoveTo     = reader.ReadUInt32();
                this.fcPlcfBklMoveTo      = reader.ReadUInt32();
                this.lcbPlcfBklMoveTo     = reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                this.fcSttbfBkmkArto  = reader.ReadUInt32();
                this.lcbSttbfBkmkArto = reader.ReadUInt32();
                this.fcPlcfBkfArto    = reader.ReadUInt32();
                this.lcbPlcfBkfArto   = reader.ReadUInt32();
                this.fcPlcfBklArto    = reader.ReadUInt32();
                this.lcbPlcfBklArto   = reader.ReadUInt32();
                this.fcArtoData       = reader.ReadUInt32();
                this.lcbArtoData      = reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                this.fcOssTheme            = reader.ReadUInt32();
                this.lcbOssTheme           = reader.ReadUInt32();
                this.fcColorSchemeMapping  = reader.ReadUInt32();
                this.lcbColorSchemeMapping = reader.ReadUInt32();
            }

            this.cswNew = reader.ReadUInt16();

            if (this.cswNew != 0)
            {
                //Read the FibRgCswNew
                this.nFibNew        = (FibVersion)reader.ReadUInt16();
                this.cQuickSavesNew = reader.ReadUInt16();
            }
        }
示例#10
0
        public ToolbarControl(VirtualStreamReader reader)
            : base(reader, ByteStructure.VARIABLE_LENGTH)
        {
            //HEADER START

            this.bSignature = reader.ReadByte();
            this.bVersion   = reader.ReadByte();

            int bFlagsTCR = (int)reader.ReadByte();

            this.fHidden      = Utils.BitmaskToBool(bFlagsTCR, 0x01);
            this.fBeginGroup  = Utils.BitmaskToBool(bFlagsTCR, 0x02);
            this.fOwnLine     = Utils.BitmaskToBool(bFlagsTCR, 0x04);
            this.fNoCustomize = Utils.BitmaskToBool(bFlagsTCR, 0x08);
            this.fSaveDxy     = Utils.BitmaskToBool(bFlagsTCR, 0x10);
            this.fBeginLine   = Utils.BitmaskToBool(bFlagsTCR, 0x40);

            this.tct       = (ToolbarControlType)reader.ReadByte();
            this.tcid      = reader.ReadInt16();
            this.tbct      = reader.ReadInt32();
            this.bPriority = reader.ReadByte();

            if (this.fSaveDxy)
            {
                this.width  = reader.ReadUInt16();
                this.height = reader.ReadUInt16();
            }

            //HEADER END

            //cid
            if (this.tcid != 0x01 && this.tcid != 0x1051)
            {
                this.cid = reader.ReadBytes(4);
            }

            //DATA START

            if (this.tct != ToolbarControlType.ActiveX)
            {
                //general control info
                byte flags = reader.ReadByte();
                this.fSaveText          = Utils.BitmaskToBool((int)flags, 0x01);
                this.fSaveMiscUIStrings = Utils.BitmaskToBool((int)flags, 0x02);
                this.fSaveMiscCustom    = Utils.BitmaskToBool((int)flags, 0x04);
                this.fDisabled          = Utils.BitmaskToBool((int)flags, 0x04);

                if (this.fSaveText)
                {
                    this.customText = Utils.ReadWString(reader.BaseStream);
                }
                if (this.fSaveMiscUIStrings)
                {
                    this.descriptionText = Utils.ReadWString(reader.BaseStream);
                    this.tooltip         = Utils.ReadWString(reader.BaseStream);
                }
                if (this.fSaveMiscCustom)
                {
                    this.helpFile      = Utils.ReadWString(reader.BaseStream);
                    this.idHelpContext = reader.ReadInt32();
                    this.tag           = Utils.ReadWString(reader.BaseStream);
                    this.onAction      = Utils.ReadWString(reader.BaseStream);
                    this.param         = Utils.ReadWString(reader.BaseStream);
                    this.tbcu          = reader.ReadByte();
                    this.tbmg          = reader.ReadByte();
                }

                //control specific info
                switch (this.tct)
                {
                case ToolbarControlType.Button:
                case ToolbarControlType.ExpandingGrid:

                    //TBCB Specific
                    int  bFlags         = (int)reader.ReadByte();
                    int  state          = Utils.BitmaskToInt(bFlags, 0x03);
                    bool fAccelerator   = Utils.BitmaskToBool(bFlags, 0x04);
                    bool fCustomBitmap  = Utils.BitmaskToBool(bFlags, 0x08);
                    bool fCustomBtnFace = Utils.BitmaskToBool(bFlags, 0x10);
                    bool fHyperlinkType = Utils.BitmaskToBool(bFlags, 0x20);
                    if (fCustomBitmap)
                    {
                        ToolbarControlBitmap icon     = new ToolbarControlBitmap(reader);
                        ToolbarControlBitmap iconMask = new ToolbarControlBitmap(reader);
                    }
                    if (fCustomBtnFace)
                    {
                        UInt16 iBtnFace = reader.ReadUInt16();
                    }
                    if (fAccelerator)
                    {
                        string wstrAcc = Utils.ReadWString(reader.BaseStream);
                    }

                    break;

                case ToolbarControlType.Popup:
                case ToolbarControlType.ButtonPopup:
                case ToolbarControlType.SplitButtonPopup:
                case ToolbarControlType.SplitButtonMRUPopup:

                    //TBC Menu Specific
                    Int32  tbid = reader.ReadInt32();
                    string name = Utils.ReadWString(reader.BaseStream);

                    break;

                case ToolbarControlType.Edit:
                case ToolbarControlType.ComboBox:
                case ToolbarControlType.GraphicCombo:
                case ToolbarControlType.Dropdown:
                case ToolbarControlType.SplitDropDown:
                case ToolbarControlType.OCXDropDown:
                case ToolbarControlType.GraphicDropDown:

                    //TBC Combo Dropdown Specific
                    if (this.tcid == 1)
                    {
                        Int16  cwstrItems = reader.ReadInt16();
                        string wstrList   = Utils.ReadWString(reader.BaseStream);
                        Int16  cwstrMRU   = reader.ReadInt16();
                        Int16  iSel       = reader.ReadInt16();
                        Int16  cLines     = reader.ReadInt16();
                        Int16  dxWidth    = reader.ReadInt16();
                        string wstrEdit   = Utils.ReadWString(reader.BaseStream);
                    }

                    break;

                default:
                    //no control Specific Info
                    break;
                }
            }
        }
示例#11
0
        public byte[] TransformWorkbookBytes(byte[] bytes, ObfuscationMode mode, string password = XorObfuscation.DefaultPassword)
        {
            VirtualStreamReader vsr = new VirtualStreamReader(new MemoryStream(bytes));
            MemoryStream        ms  = new MemoryStream();
            BinaryWriter        bw  = new BinaryWriter(ms);

            while (vsr.BaseStream.Position < vsr.BaseStream.Length)
            {
                BiffHeader bh;
                bh.id = (RecordType)vsr.ReadUInt16();

                //Handle case where RecordId is empty
                if (bh.id == 0)
                {
                    break;
                }

                bh.length = vsr.ReadUInt16();

                //Taken from https://social.msdn.microsoft.com/Forums/en-US/3dadbed3-0e68-4f11-8b43-3a2328d9ebd5/xls-xor-data-transformation-method-1


                byte XorArrayIndex = (byte)((vsr.BaseStream.Position + bh.length) % 16);


                //We remove the FilePass Record for the decrypted document
                if (mode == ObfuscationMode.Decrypt && bh.id == RecordType.FilePass)
                {
                    //Skip the remaining FilePass bytes
                    ushort encryptionMode = vsr.ReadUInt16();

                    if (encryptionMode != 0)
                    {
                        throw new NotImplementedException("FilePass EncryptionMode of " + encryptionMode +
                                                          " is unsupported.");
                    }

                    ushort key    = vsr.ReadUInt16();
                    ushort verify = vsr.ReadUInt16();

                    ushort passwordVerify = CreatePasswordVerifier_Method1(password);

                    if (verify != passwordVerify)
                    {
                        throw new ArgumentException(
                                  "Incorrect decryption password. Try bruteforcing the password with another tool.");
                    }

                    continue;
                }
                ;

                bw.Write(Convert.ToUInt16(bh.id));
                bw.Write(Convert.ToUInt16(bh.length));

                //If we're encrypting, then use the byte writer for our current position rather than the read stream
                if (mode == ObfuscationMode.Encrypt)
                {
                    XorArrayIndex = (byte)((bw.BaseStream.Position + bh.length) % 16);
                }

                //Nothing to decrypt for 0 length
                if (bh.length == 0)
                {
                    continue;
                }

                switch (bh.id)
                {
                case RecordType.BOF:
                case RecordType.FilePass:
                case RecordType.UsrExcl:
                case RecordType.FileLock:
                case RecordType.InterfaceHdr:
                case RecordType.RRDInfo:
                case RecordType.RRDHead:
                    byte[] recordBytes = vsr.ReadBytes(bh.length);
                    bw.Write(recordBytes);

                    //If this is the first BOF record, we inject the appropriate FilePass record
                    if (mode == ObfuscationMode.Encrypt &&
                        bh.id == RecordType.BOF &&
                        vsr.BaseStream.Position == (bh.length + 4))
                    {
                        ushort   key           = CreateXorKey_Method1(password);
                        ushort   verify        = CreatePasswordVerifier_Method1(password);
                        FilePass filePass      = new FilePass(key, verify);
                        byte[]   filePassBytes = filePass.GetBytes();
                        bw.Write(filePassBytes);
                    }

                    continue;

                case RecordType.BoundSheet8:
                    //Special Case - don't encrypt/decrypt the lbPlyPos Field
                    uint lbPlyPos = vsr.ReadUInt32();

                    //For encryption we need to adjust this by the added FilePass record length
                    //Decryption we auto-fix afterwards, but encrypted entries don't auto-fix well
                    // if (mode == ObfuscationMode.Encrypt)
                    // {
                    //     lbPlyPos += 10;
                    // }

                    bw.Write(lbPlyPos);
                    //Since we are skipping lbPlyPos, we need to update the XorArrayIndex offset as well
                    XorArrayIndex = (byte)((XorArrayIndex + 4) % 16);
                    byte[] remainingBytes = vsr.ReadBytes(bh.length - 4);
                    if (mode == ObfuscationMode.Decrypt)
                    {
                        byte[] decryptedBytes = DecryptData_Method1(password, remainingBytes, XorArrayIndex);
                        bw.Write(decryptedBytes);
                    }
                    else
                    {
                        byte[] encryptedBytes = EncryptData_Method1(password, remainingBytes, XorArrayIndex);
                        bw.Write(encryptedBytes);
                    }
                    continue;

                default:
                    byte[] preTransformBytes = vsr.ReadBytes(bh.length);
                    if (mode == ObfuscationMode.Decrypt)
                    {
                        byte[] decBytes = DecryptData_Method1(password, preTransformBytes, XorArrayIndex);
                        bw.Write(decBytes);
                    }
                    else
                    {
                        byte[] encBytes = EncryptData_Method1(password, preTransformBytes, XorArrayIndex);
                        bw.Write(encBytes);
                    }
                    continue;
                }
            }

            return(bw.GetBytesWritten());
        }
        private void parse(VirtualStream stream, Int32 fc)
        {
            stream.Seek(fc, System.IO.SeekOrigin.Begin);
            VirtualStreamReader reader = new VirtualStreamReader(stream);

            Int32 lcb = reader.ReadInt32();

            if (lcb > 0)
            {
                UInt16 cbHeader = reader.ReadUInt16();

                this.mfp      = new MetafilePicture();
                this.mfp.mm   = reader.ReadInt16();
                this.mfp.xExt = reader.ReadInt16();
                this.mfp.yExt = reader.ReadInt16();
                this.mfp.hMf  = reader.ReadInt16();

                if (this.mfp.mm > 98)
                {
                    this.rcWinMf = reader.ReadBytes(14);

                    //dimensions
                    this.dxaGoal = reader.ReadInt16();
                    this.dyaGoal = reader.ReadInt16();
                    this.mx      = reader.ReadUInt16();
                    this.my      = reader.ReadUInt16();

                    //cropping
                    this.dxaCropLeft   = reader.ReadInt16();
                    this.dyaCropTop    = reader.ReadInt16();
                    this.dxaCropRight  = reader.ReadInt16();
                    this.dyaCropBottom = reader.ReadInt16();

                    Int16 brcl = reader.ReadInt16();

                    //borders
                    this.brcTop    = new BorderCode(reader.ReadBytes(4));
                    this.brcLeft   = new BorderCode(reader.ReadBytes(4));
                    this.brcBottom = new BorderCode(reader.ReadBytes(4));
                    this.brcRight  = new BorderCode(reader.ReadBytes(4));

                    this.dxaOrigin = reader.ReadInt16();
                    this.dyaOrigin = reader.ReadInt16();
                    this.cProps    = reader.ReadInt16();

                    //Parse the OfficeDrawing Stuff
                    Record r = Record.ReadRecord(reader);
                    if (r is ShapeContainer)
                    {
                        this.ShapeContainer = (ShapeContainer)r;
                        long pos = reader.BaseStream.Position;
                        if (pos < (fc + lcb))
                        {
                            Record rec = Record.ReadRecord(reader);
                            if (rec.GetType() == typeof(BlipStoreEntry))
                            {
                                this.BlipStoreEntry = (BlipStoreEntry)rec;
                            }
                        }
                    }
                }
            }
        }
示例#13
0
        private void parse(Type dataType, VirtualStreamReader reader, UInt32 fc)
        {
            //read fExtend
            if (reader.ReadUInt16() == 0xFFFF)
            {
                //if the first 2 bytes are 0xFFFF the STTB contains unicode characters
                this.fExtend = true;
                _enc         = Encoding.Unicode;
            }
            else
            {
                //else the STTB contains 1byte characters and the fExtend field is non-existend
                //seek back to the beginning
                this.fExtend = false;
                _enc         = Encoding.ASCII;
                reader.BaseStream.Seek((long)fc, System.IO.SeekOrigin.Begin);
            }

            //read cData
            long   cDataStart = reader.BaseStream.Position;
            UInt16 c          = reader.ReadUInt16();

            if (c != 0xFFFF)
            {
                //cData is a 2byte unsigned Integer and the read bytes are already cData
                this.cData = (int)c;
            }
            else
            {
                //cData is a 4byte signed Integer, so we need to seek back
                reader.BaseStream.Seek((long)fc + cDataStart, System.IO.SeekOrigin.Begin);
                this.cData = reader.ReadInt32();
            }

            //read cbExtra
            this.cbExtra = reader.ReadUInt16();

            //read the strings and extra datas
            for (int i = 0; i < this.cData; i++)
            {
                int cchData = 0;
                int cbData  = 0;
                if (this.fExtend)
                {
                    cchData = (int)reader.ReadUInt16();
                    cbData  = cchData * 2;
                }
                else
                {
                    cchData = (int)reader.ReadByte();
                    cbData  = cchData;
                }

                long posBeforeType = reader.BaseStream.Position;

                if (dataType == typeof(string))
                {
                    //It's a real string table
                    this.Strings.Add(_enc.GetString(reader.ReadBytes(cbData)));
                }
                else
                {
                    //It's a modified string table that contains custom data
                    ConstructorInfo constructor = dataType.GetConstructor(new Type[] { typeof(VirtualStreamReader), typeof(int) });
                    ByteStructure   data        = (ByteStructure)constructor.Invoke(new object[] { reader, cbData });
                    this.Data.Add(data);
                }

                reader.BaseStream.Seek(posBeforeType + cbData, System.IO.SeekOrigin.Begin);

                //skip the extra byte
                reader.ReadBytes(cbExtra);
            }
        }