diff options
author | Eike Rathke <erack@redhat.com> | 2014-03-18 23:06:39 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2014-03-18 23:56:44 +0100 |
commit | 2864bcdf49e916bd532c7ba0c4e678df9dc52e8f (patch) | |
tree | 4dfd70f733187dc2744471bea98e02fc929f777d | |
parent | a8f2c8c026b2d8d729b87991129ffd59781dbd56 (diff) |
start reading 0x0868 FEAT enhanced protection feature
Change-Id: Id38a7629ea5ed4bbb1a7d696926335ce0bdec6a6
-rw-r--r-- | sc/source/filter/excel/excimp8.cxx | 66 | ||||
-rw-r--r-- | sc/source/filter/excel/read.cxx | 1 | ||||
-rw-r--r-- | sc/source/filter/excel/xicontent.cxx | 25 | ||||
-rw-r--r-- | sc/source/filter/inc/excimp8.hxx | 1 | ||||
-rw-r--r-- | sc/source/filter/inc/xicontent.hxx | 24 |
5 files changed, 114 insertions, 3 deletions
diff --git a/sc/source/filter/excel/excimp8.cxx b/sc/source/filter/excel/excimp8.cxx index e806999fab82..84174b1b6e10 100644 --- a/sc/source/filter/excel/excimp8.cxx +++ b/sc/source/filter/excel/excimp8.cxx @@ -187,6 +187,22 @@ public: } }; + +namespace { + +/** Future Record Type header. + @return whether read rt matches nRecordID + */ +bool readFrtHeader( XclImpStream& rStrm, sal_uInt16 nRecordID ) +{ + sal_uInt16 nRt = rStrm.ReaduInt16(); + rStrm.Ignore(10); // grbitFrt (2 bytes) and reserved (8 bytes) + return nRt == nRecordID; +} + +} + + ImportExcel8::ImportExcel8( XclImpRootData& rImpData, SvStream& rStrm ) : ImportExcel( rImpData, rStrm ) { @@ -304,12 +320,12 @@ void ImportExcel8::Labelsst( void ) void ImportExcel8::FeatHdr( void ) { - aIn.Ignore(12); + if (!readFrtHeader( aIn, 0x0867)) + return; // Feature type (isf) can be EXC_ISFPROTECTION, EXC_ISFFEC2 or // EXC_ISFFACTOID. - sal_uInt16 nFeatureType(0); - aIn >> nFeatureType; + sal_uInt16 nFeatureType = aIn.ReaduInt16(); if (nFeatureType != EXC_ISFPROTECTION) // We currently only support import of enhanced protection data. return; @@ -319,6 +335,50 @@ void ImportExcel8::FeatHdr( void ) GetSheetProtectBuffer().ReadOptions( aIn, GetCurrScTab() ); } + +void ImportExcel8::Feat( void ) +{ + if (!readFrtHeader( aIn, 0x0868)) + return; + + // Feature type (isf) can be EXC_ISFPROTECTION, EXC_ISFFEC2 or + // EXC_ISFFACTOID. + sal_uInt16 nFeatureType = aIn.ReaduInt16(); + if (nFeatureType != EXC_ISFPROTECTION) + // We currently only support import of enhanced protection data. + return; + + aIn.Ignore(5); // reserved1 (1 byte) and reserved2 (4 bytes) + + sal_uInt16 nCref = aIn.ReaduInt16(); // number of ref elements + aIn.Ignore(4); // size if EXC_ISFFEC2, else 0 and to be ignored + aIn.Ignore(2); // reserved3 (2 bytes) + + XclEnhancedProtection aProt; + aProt.maRefs.reserve( nCref); + XclRef8U aRef; + for (sal_uInt16 i=0; i < nCref && aIn.IsValid(); ++i) + { + aProt.maRefs.push_back( aRef.read( aIn)); + } + + // FeatProtection structure follows in record. + + aProt.mnAreserved = aIn.ReaduInt32(); + aProt.mnPasswordVerifier = aIn.ReaduInt32(); + aProt.maTitle = aIn.ReadUniString(); + if ((aProt.mnAreserved & 1) == 1) + { + sal_uInt32 nCbSD = aIn.ReaduInt32(); + // TODO: could here be some sanity check applied to not allocate 4GB? + aProt.maSecurityDescriptor.reserve( nCbSD); + aIn.Read( &aProt.maSecurityDescriptor.front(), nCbSD); + } + + GetSheetProtectBuffer().AppendEnhancedProtection( aProt, GetCurrScTab() ); +} + + void ImportExcel8::ReadBasic( void ) { SfxObjectShell* pShell = GetDocShell(); diff --git a/sc/source/filter/excel/read.cxx b/sc/source/filter/excel/read.cxx index d3a1e28d5c97..16cb97b7ba5f 100644 --- a/sc/source/filter/excel/read.cxx +++ b/sc/source/filter/excel/read.cxx @@ -1143,6 +1143,7 @@ FltError ImportExcel8::Read( void ) case EXC_ID3_ARRAY: Array34(); break; // ARRAY [ 34 ] case 0x0225: Defrowheight345();break;//DEFAULTROWHEI[ 345 ] case 0x0867: FeatHdr(); break; // FEATHDR + case 0x0868: Feat(); break; // FEAT } } break; diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx index cd23adb69729..4edbff68308e 100644 --- a/sc/source/filter/excel/xicontent.cxx +++ b/sc/source/filter/excel/xicontent.cxx @@ -64,6 +64,22 @@ using ::com::sun::star::uno::Sequence; using ::std::auto_ptr; + +const XclRef8U & XclRef8U::read( XclImpStream & rStrm ) +{ + mnRow1 = rStrm.ReaduInt16(); + mnRow2 = rStrm.ReaduInt16(); + mnCol1 = rStrm.ReaduInt16(); + mnCol2 = rStrm.ReaduInt16(); + return *this; +} + +ScRange XclRef8U::convertToScRange( SCTAB nTab ) +{ + return ScRange( mnCol1, mnRow1, nTab, mnCol2, mnRow2, nTab); +} + + // Shared string table ======================================================== XclImpSst::XclImpSst( const XclImpRoot& rRoot ) : @@ -1246,6 +1262,13 @@ void XclImpSheetProtectBuffer::ReadOptions( XclImpStream& rStrm, SCTAB nTab ) pSheet->mnOptions = nOptions; } +void XclImpSheetProtectBuffer::AppendEnhancedProtection( const XclEnhancedProtection & rProt, SCTAB nTab ) +{ + Sheet* pSheet = GetSheetItem(nTab); + if (pSheet) + pSheet->maEnhancedProtections.push_back( rProt); +} + void XclImpSheetProtectBuffer::ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab ) { sal_uInt16 nHash(0); @@ -1279,6 +1302,8 @@ void XclImpSheetProtectBuffer::Apply() const pProtect->setPasswordHash(aPass, PASSHASH_XL); } + // ranges the protection is applied to + // sheet protection options const sal_uInt16 nOptions = itr->second.mnOptions; pProtect->setOption( ScTableProtection::OBJECTS, (nOptions & 0x0001) ); diff --git a/sc/source/filter/inc/excimp8.hxx b/sc/source/filter/inc/excimp8.hxx index 54a5d0f53762..f0270fe9c311 100644 --- a/sc/source/filter/inc/excimp8.hxx +++ b/sc/source/filter/inc/excimp8.hxx @@ -59,6 +59,7 @@ public: void Hlink( void ); // 0x01B8 void FeatHdr( void ); // 0x0867 + void Feat( void ); // 0x0868 virtual void EndSheet( void ); virtual void PostDocLoad( void ); diff --git a/sc/source/filter/inc/xicontent.hxx b/sc/source/filter/inc/xicontent.hxx index 4a7f1024d255..72ed769156ea 100644 --- a/sc/source/filter/inc/xicontent.hxx +++ b/sc/source/filter/inc/xicontent.hxx @@ -44,6 +44,27 @@ globals for the document). - Stream decryption ============================================================================ */ +struct XclRef8U +{ + sal_uInt16 mnRow1; + sal_uInt16 mnRow2; + sal_uInt16 mnCol1; + sal_uInt16 mnCol2; + + const XclRef8U & read( XclImpStream & rStrm ); + ScRange convertToScRange( SCTAB nTab ); +}; + +/** Feat ISFPROTECTION refs plus FeatProtection */ +struct XclEnhancedProtection +{ + ::std::vector< XclRef8U > maRefs; + sal_uInt32 mnAreserved; + sal_uInt32 mnPasswordVerifier; + OUString maTitle; + ::std::vector< sal_uInt8 > maSecurityDescriptor; // raw data +}; + // Shared string table ======================================================== /** The SST (shared string table) contains all strings used in a BIFF8 file. @@ -305,6 +326,8 @@ public: void ReadOptions( XclImpStream& rStrm, SCTAB nTab ); + void AppendEnhancedProtection( const XclEnhancedProtection & rProt, SCTAB nTab ); + void ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab ); void Apply() const; @@ -315,6 +338,7 @@ private: bool mbProtected; sal_uInt16 mnPasswordHash; sal_uInt16 mnOptions; + ::std::vector< XclEnhancedProtection > maEnhancedProtections; Sheet(); Sheet(const Sheet& r); |