示例#1
0
        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));
        }
示例#2
0
        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;
            }
        }
示例#3
0
        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) { }
        }
示例#4
0
        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);
        }
示例#5
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];
            }
        }
示例#6
0
        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);
        }
示例#7
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);
        }
示例#8
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 ToolbarControlBitmap(VirtualStreamReader reader)
            : base(reader, ByteStructure.VARIABLE_LENGTH)
        {
            this.cbDIB = reader.ReadInt32();

            //ToDo: Read TBCBitmap
            reader.ReadBytes(cbDIB - 10);
        }
示例#10
0
        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)));
            }
        }
示例#11
0
        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);
            }
        }
示例#12
0
        public CustomToolbar(VirtualStreamReader reader)
            : base(reader, ByteStructure.VARIABLE_LENGTH)
        {
            this.name     = Utils.ReadXst(reader.BaseStream);
            this.cbTBData = reader.ReadInt32();

            //cbTBData specifies the size of this structure excluding the name, cCtls, and rTBC fields
            //so it is the size of cbtb + tb + rVisualData + iWCTB + 4ignore bytes
            //so we can retrieve the size of tb:
            this.tb          = reader.ReadBytes(this.cbTBData - 4 - 100 - 4 - 4);
            this.rVisualData = reader.ReadBytes(100);
            this.iWCTB       = reader.ReadInt32();
            reader.ReadBytes(4);

            this.cCtls = reader.ReadInt32();
            this.rTBC  = new List <ToolbarControl>();
            for (int i = 0; i < this.cCtls; i++)
            {
                this.rTBC.Add(new ToolbarControl(reader));
            }
        }
        /// <summary>
        /// Extracts the TAPX SPRMs out of a PAPX
        /// </summary>
        /// <param name="papx"></param>
        public TablePropertyExceptions(ParagraphPropertyExceptions papx, VirtualStream dataStream)
        {
            this.grpprl = new List <SinglePropertyModifier>();
            foreach (var sprm in papx.grpprl)
            {
                if (sprm.Type == SinglePropertyModifier.SprmType.TAP)
                {
                    this.grpprl.Add(sprm);
                }
                else if ((int)sprm.OpCode == 0x646b)
                {
                    IStreamReader reader = new VirtualStreamReader(dataStream);

                    //there is a native TAP in the data stream
                    uint fc = System.BitConverter.ToUInt32(sprm.Arguments, 0);

                    //get the size of the following grpprl
                    //byte[] sizebytes = new byte[2];
                    //dataStream.Read(sizebytes, 2, (int)fc);
                    var    sizebytes  = reader.ReadBytes(fc, 2);
                    ushort grpprlSize = System.BitConverter.ToUInt16(sizebytes, 0);

                    //read the grpprl
                    //byte[] grpprlBytes = new byte[grpprlSize];
                    //dataStream.Read(grpprlBytes);
                    var grpprlBytes = reader.ReadBytes(grpprlSize);

                    //parse the grpprl
                    var externalPx = new PropertyExceptions(grpprlBytes);

                    foreach (var sprmExternal in externalPx.grpprl)
                    {
                        if (sprmExternal.Type == SinglePropertyModifier.SprmType.TAP)
                        {
                            this.grpprl.Add(sprmExternal);
                        }
                    }
                }
            }
        }
示例#14
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);
                }
            }
        }
示例#15
0
        private void processCompObjStream(string compStream)
        {
            try
            {
                VirtualStreamReader reader = new VirtualStreamReader(_docStorage.GetStream(compStream));

                //skip the CompObjHeader
                reader.ReadBytes(28);

                this.UserType        = Utils.ReadLengthPrefixedAnsiString(reader.BaseStream);
                this.ClipboardFormat = Utils.ReadLengthPrefixedAnsiString(reader.BaseStream);
                this.Program         = Utils.ReadLengthPrefixedAnsiString(reader.BaseStream);
            }
            catch (StreamNotFoundException) { }
        }
示例#16
0
        private void processOleStream(string oleStream)
        {
            try
            {
                VirtualStreamReader reader = new VirtualStreamReader(_docStorage.GetStream(oleStream));

                //skip version
                reader.ReadBytes(4);

                //read the embedded/linked flag
                Int32 flag = reader.ReadInt32();
                this.fLinked = Utils.BitmaskToBool(flag, 0x1);

                //Link update option
                this.UpdateMode = (LinkUpdateOption)reader.ReadInt32();
            }
            catch (StreamNotFoundException) { }
        }
        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);
        }
        public ToolbarCustomization(VirtualStreamReader reader)
            : base(reader, ByteStructure.VARIABLE_LENGTH)
        {
            this.tbidForTBD = reader.ReadInt32();
            reader.ReadBytes(2);
            this.ctbds = reader.ReadInt16();

            //read the cutomization data
            if (this.tbidForTBD == 0)
            {
                this.customToolbar = new CustomToolbar(reader);
            }
            else
            {
                this.customToolbarDeltas = new List <ToolbarDelta>();
                for (int i = 0; i < this.ctbds; i++)
                {
                    this.customToolbarDeltas.Add(new ToolbarDelta(reader));
                }
            }
        }
        /// <summary>
        /// Parses the bytes to retrieve a PAPX
        /// </summary>
        /// <param name="bytes">The bytes starting with the istd</param>
        public ParagraphPropertyExceptions(byte[] bytes, VirtualStream dataStream)
            : base(new List <byte>(bytes).GetRange(2, bytes.Length - 2).ToArray())
        {
            if (bytes.Length != 0)
            {
                this.istd = System.BitConverter.ToUInt16(bytes, 0);
            }

            //There is a SPRM that points to an offset in the data stream,
            //where a list of SPRM is saved.
            foreach (SinglePropertyModifier sprm in this.grpprl)
            {
                if (sprm.OpCode == SinglePropertyModifier.OperationCode.sprmPHugePapx || (int)sprm.OpCode == 0x6646)
                {
                    IStreamReader reader = new VirtualStreamReader(dataStream);
                    UInt32        fc     = System.BitConverter.ToUInt32(sprm.Arguments, 0);

                    //parse the size of the external grpprl
                    byte[] sizebytes = new byte[2];
                    dataStream.Read(sizebytes, 0, 2, (int)fc);
                    UInt16 size = System.BitConverter.ToUInt16(sizebytes, 0);

                    //parse the external grpprl
                    //byte[] grpprlBytes = new byte[size];
                    //dataStream.Read(grpprlBytes);
                    byte[]             grpprlBytes = reader.ReadBytes(size);
                    PropertyExceptions externalPx  = new PropertyExceptions(grpprlBytes);

                    //assign the external grpprl
                    this.grpprl = externalPx.grpprl;

                    //remove the sprmPHugePapx
                    this.grpprl.Remove(sprm);
                }
            }
        }
示例#20
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);
            }
        }
示例#21
0
        void Parse(StructuredStorageReader reader, int fibFC)
        {
            this.Storage            = reader;
            this.WordDocumentStream = reader.GetStream("WordDocument");

            //parse FIB
            this.WordDocumentStream.Seek(fibFC, System.IO.SeekOrigin.Begin);
            this.FIB = new FileInformationBlock(new VirtualStreamReader(this.WordDocumentStream));

            //check the file version
            if ((int)this.FIB.nFib != 0)
            {
                if (this.FIB.nFib < FileInformationBlock.FibVersion.Fib1997Beta)
                {
                    throw new ByteParseException("Could not parse the file because it was created by an unsupported application (Word 95 or older).");
                }
            }
            else
            {
                if (this.FIB.nFibNew < FileInformationBlock.FibVersion.Fib1997Beta)
                {
                    throw new ByteParseException("Could not parse the file because it was created by an unsupported application (Word 95 or older).");
                }
            }

            //get the streams
            this.TableStream = reader.GetStream(this.FIB.fWhichTblStm ? "1Table" : "0Table");

            try
            {
                this.DataStream = reader.GetStream("Data");
            }
            catch (StreamNotFoundException)
            {
                this.DataStream = null;
            }

            //Read all needed STTBs
            this.RevisionAuthorTable = new StringTable(typeof(string), this.TableStream, this.FIB.fcSttbfRMark, this.FIB.lcbSttbfRMark);
            this.FontTable           = new StringTable(typeof(FontFamilyName), this.TableStream, this.FIB.fcSttbfFfn, this.FIB.lcbSttbfFfn);
            this.BookmarkNames       = new StringTable(typeof(string), this.TableStream, this.FIB.fcSttbfBkmk, this.FIB.lcbSttbfBkmk);
            this.AutoTextNames       = new StringTable(typeof(string), this.TableStream, this.FIB.fcSttbfGlsy, this.FIB.lcbSttbfGlsy);
            //this.ProtectionUsers = new StringTable(typeof(String), this.TableStream, this.FIB.fcSttbProtUser, this.FIB.lcbSttbProtUser);
            //
            this.UserVariables = new StwStructure(this.TableStream, this.FIB.fcStwUser, this.FIB.lcbStwUser);

            //Read all needed PLCFs
            this.AnnotationsReferencePlex = new Plex <AnnotationReferenceDescriptor>(30, this.TableStream, this.FIB.fcPlcfandRef, this.FIB.lcbPlcfandRef);
            this.TextboxBreakPlex         = new Plex <BreakDescriptor>(6, this.TableStream, this.FIB.fcPlcfTxbxBkd, this.FIB.lcbPlcfTxbxBkd);
            this.TextboxBreakPlexHeader   = new Plex <BreakDescriptor>(6, this.TableStream, this.FIB.fcPlcfTxbxHdrBkd, this.FIB.lcbPlcfTxbxHdrBkd);
            this.OfficeDrawingPlex        = new Plex <FileShapeAddress>(26, this.TableStream, this.FIB.fcPlcSpaMom, this.FIB.lcbPlcSpaMom);
            this.OfficeDrawingPlexHeader  = new Plex <FileShapeAddress>(26, this.TableStream, this.FIB.fcPlcSpaHdr, this.FIB.lcbPlcSpaHdr);
            this.SectionPlex           = new Plex <SectionDescriptor>(12, this.TableStream, this.FIB.fcPlcfSed, this.FIB.lcbPlcfSed);
            this.BookmarkStartPlex     = new Plex <BookmarkFirst>(4, this.TableStream, this.FIB.fcPlcfBkf, this.FIB.lcbPlcfBkf);
            this.EndnoteReferencePlex  = new Plex <short>(2, this.TableStream, this.FIB.fcPlcfendRef, this.FIB.lcbPlcfendRef);
            this.FootnoteReferencePlex = new Plex <short>(2, this.TableStream, this.FIB.fcPlcffndRef, this.FIB.lcbPlcffndRef);
            // PLCFs without types
            this.BookmarkEndPlex = new Plex <Exception>(0, this.TableStream, this.FIB.fcPlcfBkl, this.FIB.lcbPlcfBkl);
            this.AutoTextPlex    = new Plex <Exception>(0, this.TableStream, this.FIB.fcPlcfGlsy, this.FIB.lcbPlcfGlsy);

            //read the FKPs
            this.AllPapxFkps = FormattedDiskPagePAPX.GetAllPAPXFKPs(this.FIB, this.WordDocumentStream, this.TableStream, this.DataStream);
            this.AllChpxFkps = FormattedDiskPageCHPX.GetAllCHPXFKPs(this.FIB, this.WordDocumentStream, this.TableStream);

            //read custom tables
            this.DocumentProperties            = new DocumentProperties(this.FIB, this.TableStream);
            this.Styles                        = new StyleSheet(this.FIB, this.TableStream, this.DataStream);
            this.ListTable                     = new ListTable(this.FIB, this.TableStream);
            this.ListFormatOverrideTable       = new ListFormatOverrideTable(this.FIB, this.TableStream);
            this.OfficeArtContent              = new OfficeArtContent(this.FIB, this.TableStream);
            this.HeaderAndFooterTable          = new HeaderAndFooterTable(this);
            this.AnnotationReferenceExtraTable = new AnnotationReferenceExtraTable(this.FIB, this.TableStream);
            this.CommandTable                  = new CommandTable(this.FIB, this.TableStream);
            this.AnnotationOwners              = new AnnotationOwnerList(this.FIB, this.TableStream);

            //parse the piece table and construct a list that contains all chars
            this.PieceTable = new PieceTable(this.FIB, this.TableStream);
            this.Text       = this.PieceTable.GetAllChars(this.WordDocumentStream);

            //build a dictionaries of all PAPX
            this.AllPapx = new Dictionary <int, ParagraphPropertyExceptions>();
            for (int i = 0; i < this.AllPapxFkps.Count; i++)
            {
                for (int j = 0; j < this.AllPapxFkps[i].grppapx.Length; j++)
                {
                    this.AllPapx.Add(this.AllPapxFkps[i].rgfc[j], this.AllPapxFkps[i].grppapx[j]);
                }
            }

            //build a dictionary of all SEPX
            this.AllSepx = new Dictionary <int, SectionPropertyExceptions>();
            for (int i = 0; i < this.SectionPlex.Elements.Count; i++)
            {
                //Read the SED
                var sed = (SectionDescriptor)this.SectionPlex.Elements[i];
                int cp  = this.SectionPlex.CharacterPositions[i + 1];

                //Get the SEPX
                var wordReader = new VirtualStreamReader(this.WordDocumentStream);
                this.WordDocumentStream.Seek(sed.fcSepx, System.IO.SeekOrigin.Begin);
                short cbSepx = wordReader.ReadInt16();
                var   sepx   = new SectionPropertyExceptions(wordReader.ReadBytes(cbSepx - 2));

                this.AllSepx.Add(cp, sepx);
            }

            //read the Glossary
            if (this.FIB.pnNext > 0)
            {
                this.Glossary = new WordDocument(this.Storage, (int)(this.FIB.pnNext * 512));
            }
        }
示例#22
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();
            }
        }
示例#23
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;
                }
            }
        }
        public CommandTable(FileInformationBlock fib, VirtualStream tableStream)
        {
            tableStream.Seek(fib.fcCmds, System.IO.SeekOrigin.Begin);
            VirtualStreamReader reader = new VirtualStreamReader(tableStream);

            //byte[] bytes = reader.ReadBytes((int)fib.lcbCmds);
            this.MacroDatas    = new List <MacroData>();
            this.KeyMapEntries = new List <KeyMapEntry>();
            this.MacroNames    = new Dictionary <int, string>();

            //skip the version
            reader.ReadByte();

            //parse the commandtable
            while (reader.BaseStream.Position < (fib.fcCmds + fib.lcbCmds) && !breakWhile)
            {
                //read the type
                byte ch = reader.ReadByte();

                switch (ch)
                {
                case 0x1:
                    //it's a PlfMcd
                    int iMacMcd = reader.ReadInt32();
                    for (int i = 0; i < iMacMcd; i++)
                    {
                        this.MacroDatas.Add(new MacroData(reader));
                    }
                    break;

                case 0x2:
                    //it's a PlfAcd
                    //skip the ACDs
                    int iMacAcd = reader.ReadInt32();
                    reader.ReadBytes(iMacAcd * 4);
                    break;

                case 0x3:
                    //Keymap Entries
                    int iMacKme = reader.ReadInt32();
                    for (int i = 0; i < iMacKme; i++)
                    {
                        this.KeyMapEntries.Add(new KeyMapEntry(reader));
                    }
                    break;

                case 0x4:
                    //Keymap Entries
                    int iMacKmeInvalid = reader.ReadInt32();
                    for (int i = 0; i < iMacKmeInvalid; i++)
                    {
                        this.KeyMapEntries.Add(new KeyMapEntry(reader));
                    }
                    break;

                case 0x10:
                    //it's a TcgSttbf
                    this.CommandStringTable = new StringTable(typeof(String), reader);
                    break;

                case 0x11:
                    //it's a MacroNames table
                    int iMacMn = reader.ReadInt16();
                    for (int i = 0; i < iMacMn; i++)
                    {
                        Int16 ibst = reader.ReadInt16();
                        Int16 cch  = reader.ReadInt16();
                        this.MacroNames[ibst] = Encoding.Unicode.GetString(reader.ReadBytes(cch * 2));
                        //skip the terminating zero
                        reader.ReadBytes(2);
                    }
                    break;

                case 0x12:
                    //it's a CTBWRAPPER structure
                    this.CustomToolbars = new CustomToolbarWrapper(reader);
                    break;

                default:
                    breakWhile = true;
                    break;
                }
            }
        }
        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;
                            }
                        }
                    }
                }
            }
        }
示例#26
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());
        }