1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XISTREAM_HXX 21 #define INCLUDED_SC_SOURCE_FILTER_INC_XISTREAM_HXX 22 23 #include <comphelper/docpasswordhelper.hxx> 24 #include <com/sun/star/beans/NamedValue.hpp> 25 #include <filter/msfilter/mscodec.hxx> 26 #include <tools/stream.hxx> 27 #include <memory> 28 #include "xlstream.hxx" 29 #include "xlconst.hxx" 30 31 class XclImpRoot; 32 33 /* ============================================================================ 34 Input stream class for Excel import 35 - CONTINUE record handling 36 - Decryption 37 ============================================================================ */ 38 39 // Decryption 40 41 class XclImpDecrypter; 42 typedef std::shared_ptr< XclImpDecrypter > XclImpDecrypterRef; 43 44 /** Base class for BIFF stream decryption. */ 45 class XclImpDecrypter : public ::comphelper::IDocPasswordVerifier 46 { 47 public: 48 explicit XclImpDecrypter(); 49 virtual ~XclImpDecrypter() override; 50 51 /** Returns the current error code of the decrypter. */ GetError() const52 const ErrCode& GetError() const { return mnError; } 53 /** Returns true, if the decoder has been initialized correctly. */ IsValid() const54 bool IsValid() const { return mnError == ERRCODE_NONE; } 55 56 /** Creates a (ref-counted) copy of this decrypter object. */ 57 XclImpDecrypterRef Clone() const; 58 59 /** Implementation of the ::comphelper::IDocPasswordVerifier interface */ 60 virtual ::comphelper::DocPasswordVerifierResult verifyPassword( const OUString& rPassword, css::uno::Sequence< css::beans::NamedValue >& o_rEncryptionData ) override; 61 virtual ::comphelper::DocPasswordVerifierResult verifyEncryptionData( const css::uno::Sequence< css::beans::NamedValue >& rEncryptionData ) override; 62 63 /** Updates the decrypter on start of a new record or after seeking stream. */ 64 void Update( const SvStream& rStrm, sal_uInt16 nRecSize ); 65 /** Reads and decrypts nBytes bytes and stores data into the existing(!) buffer pData. 66 @return Count of bytes really read. */ 67 sal_uInt16 Read( SvStream& rStrm, void* pData, sal_uInt16 nBytes ); 68 69 protected: 70 /** Protected copy c'tor for OnClone(). */ 71 explicit XclImpDecrypter( const XclImpDecrypter& rSrc ); 72 73 private: 74 /** Implementation of cloning this object. */ 75 virtual XclImpDecrypter* OnClone() const = 0; 76 /** Derived classes implement password verification and initialization of 77 the decoder. */ 78 virtual css::uno::Sequence< css::beans::NamedValue > 79 OnVerifyPassword( const OUString& rPassword ) = 0; 80 virtual bool OnVerifyEncryptionData( const css::uno::Sequence< css::beans::NamedValue >& rEncryptionData ) = 0; 81 82 /** Implementation of updating the decrypter. */ 83 virtual void OnUpdate( std::size_t nOldStrmPos, std::size_t nNewStrmPos, sal_uInt16 nRecSize ) = 0; 84 /** Implementation of the decryption. */ 85 virtual sal_uInt16 OnRead( SvStream& rStrm, sal_uInt8* pnData, sal_uInt16 nBytes ) = 0; 86 87 private: 88 ErrCode mnError; /// Decrypter error code. 89 sal_uInt64 mnOldPos; /// Last known stream position. 90 sal_uInt16 mnRecSize; /// Current record size. 91 }; 92 93 /** Decrypts BIFF5 stream contents. */ 94 class XclImpBiff5Decrypter : public XclImpDecrypter 95 { 96 public: 97 explicit XclImpBiff5Decrypter( sal_uInt16 nKey, sal_uInt16 nHash ); 98 99 private: 100 /** Private copy c'tor for OnClone(). */ 101 explicit XclImpBiff5Decrypter( const XclImpBiff5Decrypter& rSrc ); 102 103 /** Implementation of cloning this object. */ 104 virtual XclImpBiff5Decrypter* OnClone() const override; 105 /** Implements password verification and initialization of the decoder. */ 106 virtual css::uno::Sequence< css::beans::NamedValue > 107 OnVerifyPassword( const OUString& rPassword ) override; 108 virtual bool OnVerifyEncryptionData( const css::uno::Sequence< css::beans::NamedValue >& rEncryptionData ) override; 109 /** Implementation of updating the decrypter. */ 110 virtual void OnUpdate( std::size_t nOldStrmPos, std::size_t nNewStrmPos, sal_uInt16 nRecSize ) override; 111 /** Implementation of the decryption. */ 112 virtual sal_uInt16 OnRead( SvStream& rStrm, sal_uInt8* pnData, sal_uInt16 nBytes ) override; 113 114 private: 115 ::msfilter::MSCodec_XorXLS95 maCodec; /// Crypto algorithm implementation. 116 css::uno::Sequence< css::beans::NamedValue > maEncryptionData; 117 sal_uInt16 const mnKey; 118 sal_uInt16 const mnHash; 119 }; 120 121 /** Decrypts BIFF8 stream contents using the given document identifier. */ 122 class XclImpBiff8Decrypter : public XclImpDecrypter 123 { 124 private: 125 /** Implements password verification and initialization of the decoder. */ 126 virtual css::uno::Sequence< css::beans::NamedValue > 127 OnVerifyPassword( const OUString& rPassword ) override; 128 virtual bool OnVerifyEncryptionData( const css::uno::Sequence< css::beans::NamedValue >& rEncryptionData ) override; 129 /** Implementation of updating the decrypter. */ 130 virtual void OnUpdate( std::size_t nOldStrmPos, std::size_t nNewStrmPos, sal_uInt16 nRecSize ) override; 131 /** Implementation of the decryption. */ 132 virtual sal_uInt16 OnRead( SvStream& rStrm, sal_uInt8* pnData, sal_uInt16 nBytes ) override; 133 134 /** Returns the block number corresponding to the passed stream position. */ 135 static sal_uInt32 GetBlock( std::size_t nStrmPos ); 136 /** Returns the block offset corresponding to the passed stream position. */ 137 static sal_uInt16 GetOffset( std::size_t nStrmPos ); 138 139 protected: 140 explicit XclImpBiff8Decrypter(const std::vector<sal_uInt8>& rSalt, 141 const std::vector<sal_uInt8>& rVerifier, 142 const std::vector<sal_uInt8>& rVerifierHash); 143 144 explicit XclImpBiff8Decrypter(const XclImpBiff8Decrypter& rSrc); 145 146 css::uno::Sequence< css::beans::NamedValue > maEncryptionData; 147 std::vector< sal_uInt8 > maSalt; 148 std::vector< sal_uInt8 > maVerifier; 149 std::vector< sal_uInt8 > maVerifierHash; 150 msfilter::MSCodec97* mpCodec; /// Crypto algorithm implementation. 151 }; 152 153 class XclImpBiff8StdDecrypter : public XclImpBiff8Decrypter 154 { 155 public: XclImpBiff8StdDecrypter(const std::vector<sal_uInt8> & rSalt,const std::vector<sal_uInt8> & rVerifier,const std::vector<sal_uInt8> & rVerifierHash)156 explicit XclImpBiff8StdDecrypter(const std::vector<sal_uInt8>& rSalt, 157 const std::vector<sal_uInt8>& rVerifier, 158 const std::vector<sal_uInt8>& rVerifierHash) 159 : XclImpBiff8Decrypter(rSalt, rVerifier, rVerifierHash) 160 { 161 mpCodec = &maCodec; 162 } 163 164 private: 165 /** Private copy c'tor for OnClone(). */ 166 explicit XclImpBiff8StdDecrypter(const XclImpBiff8StdDecrypter& rSrc); 167 168 /** Implementation of cloning this object. */ 169 virtual XclImpBiff8StdDecrypter* OnClone() const override; 170 171 private: 172 ::msfilter::MSCodec_Std97 maCodec; /// Crypto algorithm implementation. 173 }; 174 175 class XclImpBiff8CryptoAPIDecrypter : public XclImpBiff8Decrypter 176 { 177 public: XclImpBiff8CryptoAPIDecrypter(const std::vector<sal_uInt8> & rSalt,const std::vector<sal_uInt8> & rVerifier,const std::vector<sal_uInt8> & rVerifierHash)178 explicit XclImpBiff8CryptoAPIDecrypter(const std::vector<sal_uInt8>& rSalt, 179 const std::vector<sal_uInt8>& rVerifier, 180 const std::vector<sal_uInt8>& rVerifierHash) 181 : XclImpBiff8Decrypter(rSalt, rVerifier, rVerifierHash) 182 { 183 mpCodec = &maCodec; 184 } 185 186 private: 187 /** Private copy c'tor for OnClone(). */ 188 explicit XclImpBiff8CryptoAPIDecrypter(const XclImpBiff8CryptoAPIDecrypter& rSrc); 189 190 /** Implementation of cloning this object. */ 191 virtual XclImpBiff8CryptoAPIDecrypter* OnClone() const override; 192 193 private: 194 ::msfilter::MSCodec_CryptoAPI maCodec; /// Crypto algorithm implementation. 195 }; 196 197 // Stream 198 199 /** This class represents an Excel stream position. 200 @descr It contains the relevant data for a stream position inside of a record 201 (including CONTINUE records). */ 202 class XclImpStreamPos 203 { 204 public: 205 /** Constructs an invalid stream position data object. */ 206 explicit XclImpStreamPos(); 207 208 /** Sets the stream position data to the passed values. */ 209 void Set( const SvStream& rStrm, std::size_t nNextPos, std::size_t nCurrSize, 210 sal_uInt16 nRawRecId, sal_uInt16 nRawRecSize, sal_uInt16 nRawRecLeft, 211 bool bValid ); 212 213 /** Writes the contained stream position data to the given variables. */ 214 void Get( SvStream& rStrm, std::size_t& rnNextPos, std::size_t& rnCurrSize, 215 sal_uInt16& rnRawRecId, sal_uInt16& rnRawRecSize, sal_uInt16& rnRawRecLeft, 216 bool& rbValid ) const; 217 218 /** Returns the stored stream position. */ GetPos() const219 std::size_t GetPos() const { return mnPos; } 220 221 private: 222 std::size_t mnPos; /// Absolute position of the stream. 223 std::size_t mnNextPos; /// Absolute position of next record. 224 std::size_t mnCurrSize; /// Current calculated size of the record. 225 sal_uInt16 mnRawRecId; /// Current raw record ID (including CONTINUEs). 226 sal_uInt16 mnRawRecSize; /// Current raw record size (without following CONTINUEs). 227 sal_uInt16 mnRawRecLeft; /// Bytes left in current raw record (without following CONTINUEs). 228 bool mbValid; /// Read state: false = record overread. 229 }; 230 231 /** This class is used to import record oriented streams. 232 @descr An instance is constructed with an SvStream. The SvStream stream is 233 reset to its start while constructing this stream. 234 235 To start reading a record call StartNextRecord(). Now it is possible to 236 read all contents of the record using operator>>() or any of the Read***() 237 functions. If some data exceeds the record size limit, the stream looks for 238 a following CONTINUE record and jumps automatically to it. It is NOT 239 allowed that an atomic data type is split into two records (i.e. 4 bytes of 240 a double in one record and the other 4 bytes in a following CONTINUE). 241 242 Trying to read over the record limits results in a stream error. The 243 IsValid() function indicates that with returning false. From now on it is 244 undefined what data the read functions will return. The error state will be 245 reset, if the record is reset (with the method ResetRecord()) or if the 246 next record is started. 247 248 To switch off the automatic lookup of CONTINUE records, use ResetRecord() 249 with false parameter. This is useful i.e. on import of Escher objects, 250 where sometimes solely CONTINUE records will occur. The automatic lookup 251 keeps switched off until the method ResetRecord() is called with parameter 252 true. All other settings done on the stream (i.e. alternative CONTINUE 253 record identifier, enabled decryption, NUL substitution character) will be 254 reset to default values, if a new record is started. 255 256 The import stream supports decrypting the stream data. The contents of a 257 record (not the record header) will be encrypted by Excel if the file has 258 been stored with password protection. The functions SetDecrypter(), 259 EnableDecryption(), and DisableDecryption() control the usage of the 260 decryption algorithms. SetDecrypter() sets a new decryption algorithm and 261 initially enables it. DisableDecryption() may be used to stop the usage of 262 the decryption temporarily (sometimes record contents are never encrypted, 263 i.e. all BOF records or the stream position in BOUNDSHEET). Decryption will 264 be re-enabled automatically, if a new record is started with the function 265 StartNextRecord(). 266 267 It is possible to store several stream positions inside a record (including 268 its CONTINUE records). The positions are stored on a stack, which can be 269 controlled with the functions PushPosition(), PopPosition() and 270 RejectPosition(). The stack will be cleared whenever a new record is 271 started with the function StartNextRecord(). 272 273 Additionally a single global stream position can be stored which keeps 274 valid during the whole import process (methods StoreGlobalPosition(), 275 SeekGlobalPosition() and DeleteGlobalPosition()). This is the only way to 276 jump back to a previous record (that is a real jump without return). 277 */ 278 class XclImpStream 279 { 280 public: 281 /** Detects the BIFF version of the passed workbook stream. */ 282 static XclBiff DetectBiffVersion( SvStream& rStrm ); 283 284 /** Constructs the Excel record import stream using a TOOLS stream object. 285 @param rInStrm The system input stream. Will be set to its start position. 286 Must exist as long as this object exists */ 287 explicit XclImpStream( 288 SvStream& rInStrm, 289 const XclImpRoot& rRoot ); 290 291 ~XclImpStream(); 292 293 /** Returns the filter root data. */ GetRoot() const294 const XclImpRoot& GetRoot() const { return mrRoot; } 295 296 /** Sets stream pointer to the start of the next record content. 297 @descr Ignores all CONTINUE records of the current record, if automatic 298 CONTINUE usage is switched on. 299 @return false = no record found (end of stream). */ 300 bool StartNextRecord(); 301 /** Sets stream pointer to the start of the record content for the record 302 at the passed absolute stream position. 303 @return false = no record found (end of stream). */ 304 bool StartNextRecord( std::size_t nNextRecPos ); 305 /** Sets stream pointer to begin of record content. 306 @param bContLookup Automatic CONTINUE lookup on/off. In difference 307 to other stream settings, this setting is persistent until next call of 308 this function (because it is wanted to receive the next CONTINUE 309 records separately). 310 @param nAltContId Sets an alternative record ID for content 311 continuation. This value is reset automatically when a new record is 312 started with StartNextRecord(). */ 313 void ResetRecord( bool bContLookup, 314 sal_uInt16 nAltContId = EXC_ID_UNKNOWN ); 315 /** Sets stream pointer before current record and invalidates stream. 316 @descr The next call to StartNextRecord() will start again the current 317 record. This can be used in situations where a loop or a function 318 leaves on a specific record, but the parent context expects to start 319 this record by itself. The stream is invalid as long as the first 320 record has not been started (it is not allowed to call any other stream 321 operation then). */ 322 void RewindRecord(); 323 324 /** Enables decryption of record contents for the rest of the stream. */ 325 void SetDecrypter( XclImpDecrypterRef const & xDecrypter ); 326 /** Sets decrypter from another stream. */ 327 void CopyDecrypterFrom( const XclImpStream& rStrm ); 328 /** Switches usage of current decryption algorithm on/off. 329 @descr Encryption is re-enabled automatically, if a new record is 330 started using the function StartNextRecord(). */ 331 void EnableDecryption( bool bEnable = true ); 332 /** Switches usage of current decryption algorithm off. 333 @descr This is a record-local setting. The function StartNextRecord() 334 always enables decryption. */ DisableDecryption()335 void DisableDecryption() { EnableDecryption( false ); } 336 337 /** Pushes current position on user position stack. 338 @descr This stack is emptied when starting a new record with 339 StartNextRecord(). The decryption state (enabled/disabled) is not 340 pushed onto the stack. */ 341 void PushPosition(); 342 /** Seeks to last position from user position stack. 343 @descr This position will be removed from the stack. */ 344 void PopPosition(); 345 346 /** Stores current position. This position keeps valid in all records. */ 347 void StoreGlobalPosition(); 348 /** Seeks to the stored global user position. */ 349 void SeekGlobalPosition(); 350 351 /** Returns record reading state: false = record overread. */ IsValid() const352 bool IsValid() const { return mbValid; } 353 /** Returns the current record ID. */ GetRecId() const354 sal_uInt16 GetRecId() const { return mnRecId; } 355 /** Returns the position inside of the whole record content. */ 356 std::size_t GetRecPos() const; 357 /** Returns the data size of the whole record without record headers. */ 358 std::size_t GetRecSize(); 359 /** Returns remaining data size of the whole record without record headers. */ 360 std::size_t GetRecLeft(); 361 /** Returns the record ID of the following record. */ 362 sal_uInt16 GetNextRecId(); 363 364 sal_uInt16 PeekRecId( std::size_t nPos ); 365 366 [[nodiscard]] 367 sal_uInt8 ReaduInt8(); 368 [[nodiscard]] 369 sal_Int16 ReadInt16(); 370 [[nodiscard]] 371 sal_uInt16 ReaduInt16(); 372 [[nodiscard]] 373 sal_Int32 ReadInt32(); 374 [[nodiscard]] 375 sal_uInt32 ReaduInt32(); 376 [[nodiscard]] 377 double ReadDouble(); 378 379 /** Reads nBytes bytes to the existing(!) buffer pData. 380 @return Count of bytes really read. */ 381 std::size_t Read( void* pData, std::size_t nBytes ); 382 /** Copies nBytes bytes to rOutStrm. 383 @return Count of bytes really written. */ 384 std::size_t CopyToStream( SvStream& rOutStrm, std::size_t nBytes ); 385 386 /** Copies the entire record to rOutStrm. The current record position keeps unchanged. */ 387 void CopyRecordToStream( SvStream& rOutStrm ); 388 389 /** Seeks absolute in record content to the specified position. 390 @descr The value 0 means start of record, independent from physical stream position. */ 391 void Seek( std::size_t nPos ); 392 /** Seeks forward inside the current record. */ 393 void Ignore( std::size_t nBytes ); 394 395 // *** special string functions *** --------------------------------------- 396 397 // *** read/ignore unicode strings *** ------------------------------------ 398 /* - look for CONTINUE records even if CONTINUE handling disabled 399 (only if inside of a CONTINUE record - for TXO import) 400 - no overread assertions (for Applix wrong string length export bug) 401 402 structure of an Excel unicode string: 403 (1) 2 byte character count 404 (2) 1 byte flags (16-bit-characters, rich string, far east string) 405 (3) [2 byte rich string format run count] 406 (4) [4 byte far east data size] 407 (5) character array 408 (6) [4 * (rich string format run count) byte] 409 (7) [(far east data size) byte] 410 header = (1), (2) 411 ext. header = (3), (4) 412 ext. data = (6), (7) 413 */ 414 415 /** Reads ext. header, detects 8/16 bit mode, sets all ext. info. 416 @return Total size of ext. data. */ 417 std::size_t ReadUniStringExtHeader( 418 bool& rb16Bit, bool& rbRich, bool& rbFareast, 419 sal_uInt16& rnFormatRuns, sal_uInt32& rnExtInf, sal_uInt8 nFlags ); 420 /** Seeks to begin of character array, detects 8/16 bit mode. 421 @return Total size of ext. data. */ 422 std::size_t ReadUniStringExtHeader( bool& rb16Bit, sal_uInt8 nFlags ); 423 424 /** Sets a replacement character for NUL characters. 425 @descr NUL characters must be replaced, because Tools strings cannot 426 handle them. The substitution character is reset to '?' automatically, 427 if a new record is started using the function StartNextRecord(). 428 @param cNulSubst The character to use for NUL replacement. It is 429 possible to specify NUL here. in this case strings are terminated when 430 the first NUL occurs during string import. */ SetNulSubstChar(sal_Unicode cNulSubst='?')431 void SetNulSubstChar( sal_Unicode cNulSubst = '?' ) { mcNulSubst = cNulSubst; } 432 433 /** Reads nChars characters and returns the string. */ 434 OUString ReadRawUniString( sal_uInt16 nChars, bool b16Bit ); 435 /** Reads ext. header, nChar characters, ext. data and returns the string. */ 436 OUString ReadUniString( sal_uInt16 nChars, sal_uInt8 nFlags ); 437 /** Reads 8 bit flags, ext. header, nChar characters, ext. data and returns the string. */ 438 OUString ReadUniString( sal_uInt16 nChars ); 439 /** Reads 16 bit character count, 8 bit flags, ext. header, character array, 440 ext. data and returns the string. */ 441 OUString ReadUniString(); 442 443 /** Ignores nChars characters. */ 444 void IgnoreRawUniString( sal_uInt16 nChars, bool b16Bit ); 445 /** Ignores ext. header, nChar characters, ext. data. */ 446 void IgnoreUniString( sal_uInt16 nChars, sal_uInt8 nFlags ); 447 /** Ignores 8 bit flags, ext. header, nChar characters, ext. data. */ 448 void IgnoreUniString( sal_uInt16 nChars ); 449 450 // *** read/ignore 8-bit-strings, store in String *** --------------------- 451 452 /** Reads nChar byte characters and returns the string. */ 453 OUString ReadRawByteString( sal_uInt16 nChars ); 454 /** Reads 8/16 bit string length, character array and returns the string. */ 455 OUString ReadByteString( bool b16BitLen ); 456 457 // *** SvStream functions *** --------------------------------------------- 458 459 /** Returns the absolute stream position. */ GetSvStreamPos() const460 std::size_t GetSvStreamPos() const { return mrStrm.Tell(); } 461 /** Returns the stream size. */ GetSvStreamSize() const462 std::size_t GetSvStreamSize() const { return mnStreamSize; } 463 464 /** Stores current stream position into rPos. */ 465 void StorePosition( XclImpStreamPos& rPos ); 466 /** Restores stream position contained in rPos. */ 467 void RestorePosition( const XclImpStreamPos& rPos ); 468 469 private: 470 /** Seeks to next raw record header and reads record ID and size. 471 @descr This is a "raw" function, means that stream members are 472 inconsistent after return. Does only change mnRawRecId, mnRawRecSize, 473 and the base stream position, but no other members. 474 @return false = No record header found (end of stream). */ 475 bool ReadNextRawRecHeader(); 476 477 /** Initializes the decrypter to read a new record. */ 478 void SetupDecrypter(); 479 /** Initializes all members after base stream has been sought to new raw record. */ 480 void SetupRawRecord(); 481 /** Initializes all members after base stream has been sought to new record. */ 482 void SetupRecord(); 483 484 /** Returns true, if the passed ID is real or alternative continuation record ID. */ 485 bool IsContinueId( sal_uInt16 nRecId ) const; 486 487 /** Goes to start of the next CONTINUE record. 488 @descr Stream must be located at the end of a raw record, and handling 489 of CONTINUE records must be enabled. 490 @return Copy of mbValid. */ 491 bool JumpToNextContinue(); 492 /** Goes to start of the next CONTINUE record while reading strings. 493 @descr Stream must be located at the end of a raw record. If reading 494 has been started in a CONTINUE record, jumps to an existing following 495 CONTINUE record, even if handling of CONTINUE records is disabled (This 496 is a special handling for TXO string data). Reads additional Unicode 497 flag byte at start of the new raw record and sets or resets rb16Bit. 498 @return Copy of mbValid. */ 499 bool JumpToNextStringContinue( bool& rb16Bit ); 500 501 /** Ensures that reading nBytes bytes is possible with next stream access. 502 @descr Stream must be located at the end of a raw record, and handling 503 of CONTINUE records must be enabled. 504 @return Copy of mbValid. */ 505 bool EnsureRawReadSize( sal_uInt16 nBytes ); 506 /** Returns the maximum size of raw data possible to read in one block. */ 507 sal_uInt16 GetMaxRawReadSize( std::size_t nBytes ) const; 508 509 /** Reads and decrypts nBytes bytes to the existing(!) buffer pData. 510 @return Count of bytes really read. */ 511 sal_uInt16 ReadRawData( void* pData, sal_uInt16 nBytes ); 512 513 private: 514 typedef ::std::vector< XclImpStreamPos > XclImpStreamPosStack; 515 516 SvStream& mrStrm; /// Reference to the system input stream. 517 const XclImpRoot& mrRoot; /// Filter root data. 518 519 XclImpDecrypterRef mxDecrypter; /// Provides methods to decrypt data. 520 521 XclImpStreamPos maFirstRec; /// Start position of current record. 522 XclImpStreamPosStack maPosStack; /// Stack for record positions. 523 524 XclImpStreamPos maGlobPos; /// User defined position elsewhere in stream. 525 sal_uInt16 mnGlobRecId; /// Record ID for user defined position. 526 bool mbGlobValidRec; /// Was user position a valid record? 527 bool mbHasGlobPos; /// Is user position defined? 528 529 std::size_t mnStreamSize; /// Size of system stream. 530 std::size_t mnNextRecPos; /// Start of next record header. 531 std::size_t mnCurrRecSize; /// Helper for record position. 532 std::size_t mnComplRecSize; /// Size of complete record data (with CONTINUEs). 533 bool mbHasComplRec; /// true = mnComplRecSize is valid. 534 535 sal_uInt16 mnRecId; /// Current record ID (not the CONTINUE ID). 536 sal_uInt16 mnAltContId; /// Alternative record ID for content continuation. 537 538 sal_uInt16 mnRawRecId; /// Current raw record ID (including CONTINUEs). 539 sal_uInt16 mnRawRecSize; /// Current raw record size (without following CONTINUEs). 540 sal_uInt16 mnRawRecLeft; /// Bytes left in current raw record (without following CONTINUEs). 541 542 sal_Unicode mcNulSubst; /// Replacement for NUL characters. 543 544 bool mbCont; /// Automatic CONTINUE lookup on/off. 545 bool mbUseDecr; /// Usage of decryption. 546 bool mbValidRec; /// false = No more records to read. 547 bool mbValid; /// false = Record overread. 548 }; 549 550 #endif 551 552 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 553