Пример #1
0
        public PropertySet(VirtualStreamReader stream)
        {
            long pos = stream.BaseStream.Position;

            //read size and number of properties
            this.size          = stream.ReadUInt32();
            this.numProperties = stream.ReadUInt32();

            //read the identifier and offsets
            this.identifiers = new UInt32[this.numProperties];
            this.offsets     = new UInt32[this.numProperties];
            for (int i = 0; i < this.numProperties; i++)
            {
                this.identifiers[i] = stream.ReadUInt32();
                this.offsets[i]     = stream.ReadUInt32();
            }

            //read the properties
            for (int i = 0; i < this.numProperties; i++)
            {
                if (this.identifiers[i] == 0)
                {
                    // dictionary property
                    throw new NotImplementedException("Dictionary Properties are not yet implemented!");
                }
                else
                {
                    // value property
                    this.Add(new ValueProperty(stream));
                }
            }

            // seek to the end of the property set to avoid crashes
            stream.BaseStream.Seek(pos + size, SeekOrigin.Begin);
        }
Пример #2
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();
            }
        }
Пример #3
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());
        }
Пример #4
0
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="reader">Reader to parse the document </param>
        /// <param name="id">BiffRecord ID</param>
        /// <param name="length">The lengt of the biffrecord </param>
        public SST(IStreamReader reader, RecordType id, UInt16 length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            this.StringList = new List <string>();
            this.FormatList = new List <StringFormatAssignment>();

            // copy data to a memory stream to cope with Continue records
            using (MemoryStream ms = new MemoryStream())
            {
                List <long> recordBorders = new List <long>();

                byte[] buffer = reader.ReadBytes(length);
                ms.Write(buffer, 0, length);

                while (BiffRecord.GetNextRecordType(reader) == RecordType.Continue)
                {
                    BiffHeader bh;
                    bh.id     = (RecordType)reader.ReadUInt16();
                    bh.length = reader.ReadUInt16();

                    recordBorders.Add(ms.Position);
                    buffer = reader.ReadBytes(bh.length);
                    ms.Write(buffer, 0, bh.length);
                }

                ms.Position = 0;

                VirtualStreamReader sr = new VirtualStreamReader(ms);

                try
                {
                    this.cstTotal  = sr.ReadUInt32();
                    this.cstUnique = sr.ReadUInt32();

                    // run over the different strings
                    // there are x strings where x = cstUnique
                    for (int i = 0; i < this.cstUnique; i++)
                    {
                        XLUnicodeRichExtendedString str = new XLUnicodeRichExtendedString(sr, recordBorders);

                        //// first get the char count of this string
                        //UInt16 cch = sr.ReadUInt16();
                        //// get the grbit mask
                        //Byte grbit = sr.ReadByte();
                        //bool isCompressedString = !Utils.BitmaskToBool((int)grbit, 0x0001);
                        //bool isExtString = Utils.BitmaskToBool((int)grbit, 0x0004);
                        //bool isRichString = Utils.BitmaskToBool((int)grbit, 0x0008);

                        //int cRun = 0;
                        //int cbExtRst = 0;

                        //if (isRichString)
                        //{
                        //    cRun = sr.ReadUInt16();
                        //}

                        //if (isExtString)
                        //{
                        //    cbExtRst = sr.ReadInt32();
                        //}

                        //// read characters from the string
                        //int charcount = 0;
                        //if (isCompressedString)
                        //    charcount = 1;
                        //else
                        //    charcount = 2;

                        //String stringbuffer = "";

                        //// read chars !!!
                        //while (sr.BaseStream.Length < sr.BaseStream.Position + cch * charcount)
                        //{
                        //    ushort currentLength = (ushort)(sr.BaseStream.Length - sr.BaseStream.Position);
                        //    cch -= (ushort)(currentLength / charcount);
                        //    for (int j = 0; j < currentLength / charcount; j++)
                        //    {
                        //        if (isCompressedString)
                        //        {
                        //            stringbuffer += (char)sr.ReadByte();
                        //        }
                        //        else
                        //        {
                        //            stringbuffer += System.BitConverter.ToChar(sr.ReadBytes(2), 0);
                        //        }
                        //    }

                        //    // read compressed/uncompressed byte value
                        //    byte grbit2 = sr.ReadByte();
                        //    if (grbit2 > 0)
                        //        isCompressedString = false;
                        //    else
                        //        isCompressedString = true;
                        //}

                        //for (int j = 0; j < cch; j++)
                        //{
                        //    if (isCompressedString)
                        //    {
                        //        stringbuffer += (char)sr.ReadByte();
                        //    }
                        //    else
                        //    {
                        //        stringbuffer += System.BitConverter.ToChar(sr.ReadBytes(2), 0);
                        //    }
                        //}
                        this.StringList.Add(str.Value);

                        if (str.fRichSt)
                        {
                            foreach (FormatRun formatRun in str.rgRun)
                            {
                                StringFormatAssignment format = new StringFormatAssignment();
                                format.StringNumber = i + 1;

                                format.CharNumber = formatRun.ich;
                                format.FontRecord = formatRun.ifnt;

                                // NOTE: If this value is less than 4, then it specifies a *zero-based* index of a Font record
                                //  in the collection of Font records in the globals substream. If this value is greater than 4,
                                //  then it specifies a *one-based* index of a Font record in the collection of Font records in
                                //  the globals substream.
                                //
                                if (format.FontRecord > 4)
                                {
                                    format.FontRecord--;
                                }

                                if (format.CharNumber < str.Value.Length)
                                {
                                    this.FormatList.Add(format);
                                }
                            }
                        }

                        //// read formatting runs!!
                        //if (isRichString)
                        //{
                        //    int countFormatingRuns = cRun;
                        //    while (sr.BaseStream.Length < sr.BaseStream.Position + countFormatingRuns * 4)
                        //    {
                        //        ushort currentLength = (ushort)(sr.BaseStream.Length - sr.BaseStream.Position);
                        //        countFormatingRuns -= (ushort)(currentLength / 4);
                        //        // get formating data
                        //        for (int j = 0; j < currentLength / 4; j++)
                        //        {
                        //            StringFormatAssignment format = new StringFormatAssignment();
                        //            format.StringNumber = i + 1;

                        //            format.CharNumber = sr.ReadUInt16();
                        //            format.FontRecord = sr.ReadUInt16();

                        //            if (format.CharNumber < stringbuffer.Length)
                        //            {
                        //                this.FormatList.Add(format);
                        //            }
                        //        }
                        //    }
                        //    // get formating data
                        //    for (int j = 0; j < countFormatingRuns; j++)
                        //    {
                        //        StringFormatAssignment format = new StringFormatAssignment();
                        //        format.StringNumber = i + 1;
                        //        format.CharNumber = sr.ReadUInt16();
                        //        format.FontRecord = sr.ReadUInt16();

                        //        if (format.FontRecord > 4)
                        //        {
                        //            format.FontRecord--;
                        //        }

                        //        /// ToDo: Check why some charNumbers are greater then string length
                        //        if (format.CharNumber < stringbuffer.Length)
                        //        {
                        //            this.FormatList.Add(format);
                        //        }
                        //    }
                        //}

                        //if (isExtString)
                        //{
                        //    int cchExtRst = cbExtRst;
                        //    byte[] ExtRst;
                        //    while (sr.BaseStream.Length < sr.BaseStream.Position + cchExtRst)
                        //    {
                        //        ushort currentLength = (ushort)(sr.BaseStream.Length - sr.BaseStream.Position);
                        //        cchExtRst -= (currentLength);
                        //        ExtRst = sr.ReadBytes(currentLength);
                        //    }

                        //    ExtRst = sr.ReadBytes(cchExtRst);
                        //}
                    }
                }
                catch (Exception ex)
                {
                    TraceLogger.Error(ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
            }
            // assert that the correct number of bytes has been read from the stream
            // Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }