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 #include <sal/config.h>
21 
22 #include <string_view>
23 
24 #include <oox/dump/oledumper.hxx>
25 
26 #include <rtl/tencinfo.h>
27 #include <oox/ole/vbainputstream.hxx>
28 
29 #ifdef DBG_UTIL
30 
31 namespace oox::dump {
32 
33 using namespace ::com::sun::star::io;
34 using namespace ::com::sun::star::uno;
35 
dumpAnsiString32(const String & rName)36 OUString OleInputObjectBase::dumpAnsiString32( const String& rName )
37 {
38     return dumpCharArray( rName, mxStrm->readInt32(), RTL_TEXTENCODING_MS_1252 );
39 }
40 
dumpUniString32(const String & rName)41 OUString OleInputObjectBase::dumpUniString32( const String& rName )
42 {
43     return dumpUnicodeArray( rName, mxStrm->readInt32() );
44 }
45 
dumpStdClipboardFormat(const String & rName)46 sal_Int32 OleInputObjectBase::dumpStdClipboardFormat( const String& rName )
47 {
48     return dumpDec< sal_Int32 >( rName( "clipboard-format" ), "OLE-STD-CLIPBOARD-FORMAT" );
49 }
50 
dumpAnsiString32OrStdClip(const String & rName)51 OUString OleInputObjectBase::dumpAnsiString32OrStdClip( const String& rName )
52 {
53     sal_Int32 nLen = mxStrm->readInt32();
54     return (nLen < 0) ? OUString::number( dumpStdClipboardFormat( rName ) ) : dumpCharArray( rName, nLen, RTL_TEXTENCODING_MS_1252 );
55 }
56 
dumpUniString32OrStdClip(const String & rName)57 OUString OleInputObjectBase::dumpUniString32OrStdClip( const String& rName )
58 {
59     sal_Int32 nLen = mxStrm->readInt32();
60     return (nLen < 0) ? OUString::number( dumpStdClipboardFormat( rName ) ) : dumpUnicodeArray( rName, nLen );
61 }
62 
writeOleColorItem(const String & rName,sal_uInt32 nColor)63 void OleInputObjectBase::writeOleColorItem( const String& rName, sal_uInt32 nColor )
64 {
65     MultiItemsGuard aMultiGuard( mxOut );
66     writeHexItem( rName, nColor, "OLE-COLOR" );
67 }
68 
dumpOleColor(const String & rName)69 sal_uInt32 OleInputObjectBase::dumpOleColor( const String& rName )
70 {
71     sal_uInt32 nOleColor = mxStrm->readuInt32();
72     writeOleColorItem( rName, nOleColor );
73     return nOleColor;
74 }
75 
StdFontObject(const InputObjectBase & rParent)76 StdFontObject::StdFontObject( const InputObjectBase& rParent )
77 {
78     construct( rParent );
79 }
80 
implDump()81 void StdFontObject::implDump()
82 {
83     dumpDec< sal_uInt8 >( "version" );
84     dumpDec< sal_uInt16 >( "charset", "CHARSET" );
85     dumpHex< sal_uInt8 >( "flags", "STDFONT-FLAGS" );
86     dumpDec< sal_uInt16 >( "weight", "FONT-WEIGHT" );
87     dumpDec< sal_uInt32 >( "height", "STDFONT-HEIGHT" );
88     dumpCharArray( "name", mxStrm->readuInt8(), RTL_TEXTENCODING_ASCII_US );
89 }
90 
StdPicObject(const InputObjectBase & rParent)91 StdPicObject::StdPicObject( const InputObjectBase& rParent )
92 {
93     construct( rParent );
94 }
95 
implDump()96 void StdPicObject::implDump()
97 {
98     dumpHex< sal_uInt32 >( "identifier", "STDPIC-ID" );
99     sal_uInt32 nSize = dumpHex< sal_uInt32 >( "image-size", "CONV-DEC" );
100     dumpBinary( "image-data", nSize );
101 }
102 
OleStreamObject(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName)103 OleStreamObject::OleStreamObject( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName )
104 {
105     construct( rParent, rxStrm, rSysFileName );
106 }
107 
OleCompObjObject(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName)108 OleCompObjObject::OleCompObjObject( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName ) :
109     OleStreamObject( rParent, rxStrm, rSysFileName )
110 {
111 }
112 
implDump()113 void OleCompObjObject::implDump()
114 {
115     dumpUnused( 4 );
116     dumpDec< sal_uInt32 >( "version" );
117     dumpUnused( 20 );
118     dumpAnsiString32( "ansi-display-name" );
119     dumpAnsiString32OrStdClip( "ansi-clipboard-format" );
120     if( mxStrm->getRemaining() >= 4 )
121     {
122         sal_Int32 nLen = mxStrm->readInt32();
123         if( (0 <= nLen) && (nLen <= 40) )
124         {
125             dumpCharArray( "ansi-unused", nLen, RTL_TEXTENCODING_MS_1252 );
126             if( (mxStrm->getRemaining() >= 4) && (dumpHex< sal_Int32 >( "unicode-marker" ) == 0x71B239F4) )
127             {
128                 dumpUniString32( "unicode-display-name" );
129                 dumpUniString32OrStdClip( "unicode-clipboard-format" );
130                 dumpUniString32( "unicode-unused" );
131             }
132         }
133         else
134             writeDecItem( "length", nLen );
135     }
136     dumpRemainingStream();
137 }
138 
139 namespace {
140 
141 const sal_Int32 OLEPROP_ID_DICTIONARY   = 0;
142 const sal_Int32 OLEPROP_ID_CODEPAGE     = 1;
143 
144 const sal_uInt16 OLEPROP_TYPE_INT16     = 2;
145 const sal_uInt16 OLEPROP_TYPE_INT32     = 3;
146 const sal_uInt16 OLEPROP_TYPE_FLOAT     = 4;
147 const sal_uInt16 OLEPROP_TYPE_DOUBLE    = 5;
148 const sal_uInt16 OLEPROP_TYPE_DATE      = 7;
149 const sal_uInt16 OLEPROP_TYPE_STRING    = 8;
150 const sal_uInt16 OLEPROP_TYPE_STATUS    = 10;
151 const sal_uInt16 OLEPROP_TYPE_BOOL      = 11;
152 const sal_uInt16 OLEPROP_TYPE_VARIANT   = 12;
153 const sal_uInt16 OLEPROP_TYPE_INT8      = 16;
154 const sal_uInt16 OLEPROP_TYPE_UINT8     = 17;
155 const sal_uInt16 OLEPROP_TYPE_UINT16    = 18;
156 const sal_uInt16 OLEPROP_TYPE_UINT32    = 19;
157 const sal_uInt16 OLEPROP_TYPE_INT64     = 20;
158 const sal_uInt16 OLEPROP_TYPE_UINT64    = 21;
159 const sal_uInt16 OLEPROP_TYPE_STRING8   = 30;
160 const sal_uInt16 OLEPROP_TYPE_STRING16  = 31;
161 const sal_uInt16 OLEPROP_TYPE_FILETIME  = 64;
162 const sal_uInt16 OLEPROP_TYPE_BLOB      = 65;
163 const sal_uInt16 OLEPROP_TYPE_STREAM    = 66;
164 const sal_uInt16 OLEPROP_TYPE_STORAGE   = 67;
165 const sal_uInt16 OLEPROP_TYPE_CLIPFMT   = 71;
166 
167 const sal_uInt16 OLEPROP_TYPE_SIMPLE    = 0x0000;
168 const sal_uInt16 OLEPROP_TYPE_VECTOR    = 0x1000;
169 const sal_uInt16 OLEPROP_TYPE_ARRAY     = 0x2000;
170 
171 const sal_uInt16 CODEPAGE_UNICODE       = 1200;
172 
173 const sal_uInt32 AX_STRING_COMPRESSED   = 0x80000000;
174 
175 } // namespace
176 
OlePropertyStreamObject(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName)177 OlePropertyStreamObject::OlePropertyStreamObject( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName )
178 {
179     construct( rParent, rxStrm, rSysFileName );
180 }
181 
implDump()182 void OlePropertyStreamObject::implDump()
183 {
184     OUStringVector aGuidVec;
185     ::std::vector< sal_uInt32 > aStartPosVec;
186 
187     // dump header
188     writeEmptyItem( "HEADER" );
189     {
190         IndentGuard aIndGuard( mxOut );
191         dumpHex< sal_uInt16 >( "byte-order", "OLEPROP-BYTE-ORDER" );
192         dumpDec< sal_uInt16 >( "version" );
193         dumpDec< sal_uInt16 >( "os-minor" );
194         dumpDec< sal_uInt16 >( "os-type", "OLEPROP-OSTYPE" );
195         dumpGuid( "guid" );
196         sal_Int32 nSectCount = dumpDec< sal_Int32 >( "section-count" );
197 
198         // dump table of section positions
199         {
200             TableGuard aTabGuard( mxOut, 15, 60 );
201             mxOut->resetItemIndex();
202             for( sal_Int32 nSectIdx = 0; !mxStrm->isEof() && (nSectIdx < nSectCount); ++nSectIdx )
203             {
204                 MultiItemsGuard aMultiGuard( mxOut );
205                 writeEmptyItem( "#section" );
206                 aGuidVec.push_back( dumpGuid( "guid" ) );
207                 aStartPosVec.push_back( dumpHex< sal_uInt32 >( "start-pos", "CONV-DEC" ) );
208             }
209         }
210     }
211     mxOut->emptyLine();
212 
213     // dump sections
214     for( size_t nSectIdx = 0; !mxStrm->isEof() && (nSectIdx < aStartPosVec.size()); ++nSectIdx )
215         dumpSection( aGuidVec[ nSectIdx ], aStartPosVec[ nSectIdx ] );
216 }
217 
dumpSection(const OUString & rGuid,sal_uInt32 nStartPos)218 void OlePropertyStreamObject::dumpSection( const OUString& rGuid, sal_uInt32 nStartPos )
219 {
220     // property ID names
221     mxPropIds = cfg().createNameList< ConstList >( "OLEPROP-IDS" );
222     OUString aGuidName = cfg().getStringOption( rGuid, OUString() );
223     if ( aGuidName == "GlobalDocProp" )
224         mxPropIds->includeList( cfg().getNameList( "OLEPROP-GLOBALIDS" ) );
225     else if ( aGuidName == "BuiltinDocProp" )
226         mxPropIds->includeList( cfg().getNameList( "OLEPROP-BUILTINIDS" ) );
227     else
228         mxPropIds->includeList( cfg().getNameList( "OLEPROP-BASEIDS" ) );
229 
230     // property ID/position map
231     typedef ::std::map< sal_Int32, sal_uInt32 > PropertyPosMap;
232     PropertyPosMap aPropMap;
233 
234     // dump section header line
235     writeSectionHeader( rGuid, nStartPos );
236 
237     // seek to section
238     IndentGuard aIndGuard( mxOut );
239     if( startElement( nStartPos ) )
240     {
241         // dump section header
242         dumpDec< sal_Int32 >( "size" );
243         sal_Int32 nPropCount = dumpDec< sal_Int32 >( "property-count" );
244 
245         // dump table of property positions
246         {
247             TableGuard aTabGuard( mxOut, 15, 25 );
248             mxOut->resetItemIndex();
249             for( sal_Int32 nPropIdx = 0; !mxStrm->isEof() && (nPropIdx < nPropCount); ++nPropIdx )
250             {
251                 MultiItemsGuard aMultiGuard( mxOut );
252                 writeEmptyItem( "#property" );
253                 sal_Int32 nPropId = dumpDec< sal_Int32 >( "id", mxPropIds );
254                 sal_uInt32 nPropPos = nStartPos + dumpHex< sal_uInt32 >( "start-pos", "CONV-DEC" );
255                 aPropMap[ nPropId ] = nPropPos;
256             }
257         }
258     }
259     mxOut->emptyLine();
260 
261     // code page property
262     meTextEnc = RTL_TEXTENCODING_MS_1252;
263     mbIsUnicode = false;
264     PropertyPosMap::iterator aCodePageIt = aPropMap.find( OLEPROP_ID_CODEPAGE );
265     if( aCodePageIt != aPropMap.end() )
266     {
267         dumpCodePageProperty( aCodePageIt->second );
268         aPropMap.erase( aCodePageIt );
269     }
270 
271     // dictionary property
272     PropertyPosMap::iterator aDictIt = aPropMap.find( OLEPROP_ID_DICTIONARY );
273     if( aDictIt != aPropMap.end() )
274     {
275         dumpDictionaryProperty( aDictIt->second );
276         aPropMap.erase( aDictIt );
277     }
278 
279     // other properties
280     for (auto const& elem : aPropMap)
281         dumpProperty( elem.first, elem.second );
282 
283     // remove the user defined list of property ID names
284     cfg().eraseNameList( "OLEPROP-IDS" );
285 }
286 
dumpProperty(sal_Int32 nPropId,sal_uInt32 nStartPos)287 void OlePropertyStreamObject::dumpProperty( sal_Int32 nPropId, sal_uInt32 nStartPos )
288 {
289     writePropertyHeader( nPropId, nStartPos );
290     IndentGuard aIndGuard( mxOut );
291     if( startElement( nStartPos ) )
292         dumpPropertyContents( nPropId );
293     mxOut->emptyLine();
294 }
295 
dumpCodePageProperty(sal_uInt32 nStartPos)296 void OlePropertyStreamObject::dumpCodePageProperty( sal_uInt32 nStartPos )
297 {
298     writePropertyHeader( OLEPROP_ID_CODEPAGE, nStartPos );
299     IndentGuard aIndGuard( mxOut );
300     if( startElement( nStartPos ) )
301     {
302         sal_uInt16 nType = dumpPropertyType();
303         if( nType == OLEPROP_TYPE_INT16 )
304         {
305             sal_uInt16 nCodePage = dumpDec< sal_uInt16 >( "codepage", "CODEPAGES" );
306             rtl_TextEncoding eNewTextEnc = rtl_getTextEncodingFromWindowsCodePage( nCodePage );
307             if( eNewTextEnc != RTL_TEXTENCODING_DONTKNOW )
308                 meTextEnc = eNewTextEnc;
309             mbIsUnicode = nCodePage == CODEPAGE_UNICODE;
310         }
311         else
312             dumpPropertyContents( OLEPROP_ID_CODEPAGE );
313     }
314     mxOut->emptyLine();
315 }
316 
dumpDictionaryProperty(sal_uInt32 nStartPos)317 void OlePropertyStreamObject::dumpDictionaryProperty( sal_uInt32 nStartPos )
318 {
319     writePropertyHeader( OLEPROP_ID_DICTIONARY, nStartPos );
320     IndentGuard aIndGuard( mxOut );
321     if( startElement( nStartPos ) )
322     {
323         sal_Int32 nCount = dumpDec< sal_Int32 >( "count" );
324         for( sal_Int32 nIdx = 0; !mxStrm->isEof() && (nIdx < nCount); ++nIdx )
325         {
326             MultiItemsGuard aMultiGuard( mxOut );
327             TableGuard aTabGuard( mxOut, 10, 20 );
328             sal_Int32 nId = dumpDec< sal_Int32 >( "id" );
329             OUString aName = dumpString8( "name" );
330             if( mxPropIds )
331                 mxPropIds->setName( nId, aName );
332         }
333     }
334     mxOut->emptyLine();
335 }
336 
dumpPropertyContents(sal_Int32 nPropId)337 sal_uInt16 OlePropertyStreamObject::dumpPropertyContents( sal_Int32 nPropId )
338 {
339     sal_uInt16 nType = dumpPropertyType();
340     sal_uInt16 nBaseType = static_cast< sal_uInt16 >( nType & 0x0FFF );
341     sal_uInt16 nArrayType = static_cast< sal_uInt16 >( nType & 0xF000 );
342     switch( nArrayType )
343     {
344         case OLEPROP_TYPE_SIMPLE:   dumpPropertyValue( nPropId, nBaseType );    break;
345         case OLEPROP_TYPE_VECTOR:   dumpPropertyVector( nPropId, nBaseType );   break;
346         case OLEPROP_TYPE_ARRAY:    /*TODO*/;    break;
347     }
348     return nType;
349 }
350 
dumpPropertyValue(sal_Int32 nPropId,sal_uInt16 nBaseType)351 void OlePropertyStreamObject::dumpPropertyValue( sal_Int32 nPropId, sal_uInt16 nBaseType )
352 {
353     switch( nBaseType )
354     {
355         case OLEPROP_TYPE_INT16:        dumpDec< sal_Int16 >( "value" );        break;
356         case OLEPROP_TYPE_INT32:        dumpDec< sal_Int32 >( "value" );        break;
357         case OLEPROP_TYPE_FLOAT:        dumpDec< float >( "value" );            break;
358         case OLEPROP_TYPE_DOUBLE:       dumpDec< double >( "value" );           break;
359         case OLEPROP_TYPE_DATE:         dumpDec< double >( "date" );            break;
360         case OLEPROP_TYPE_STRING:       dumpString8( "value" );                 break;
361         case OLEPROP_TYPE_STATUS:       dumpHex< sal_Int32 >( "status" );       break;
362         case OLEPROP_TYPE_BOOL:         dumpBool< sal_Int16 >( "value" );       break;
363         case OLEPROP_TYPE_VARIANT:      dumpPropertyContents( nPropId );        break;
364         case OLEPROP_TYPE_INT8:         dumpDec< sal_Int8 >( "value" );         break;
365         case OLEPROP_TYPE_UINT8:        dumpDec< sal_uInt8 >( "value" );        break;
366         case OLEPROP_TYPE_UINT16:       dumpDec< sal_uInt16 >( "value" );       break;
367         case OLEPROP_TYPE_UINT32:       dumpDec< sal_uInt32 >( "value" );       break;
368         case OLEPROP_TYPE_INT64:        dumpDec< sal_Int64 >( "value" );        break;
369         case OLEPROP_TYPE_UINT64:       dumpDec< sal_uInt64 >( "value" );       break;
370         case OLEPROP_TYPE_STRING8:      dumpString8( "value" );                 break;
371         case OLEPROP_TYPE_STRING16:     dumpString16( "value" );                break;
372         case OLEPROP_TYPE_FILETIME:     dumpFileTime( "file-time" );            break;
373         case OLEPROP_TYPE_BLOB:         dumpBlob( nPropId, "data" );            break;
374         case OLEPROP_TYPE_STREAM:       dumpString8( "stream-name" );           break;
375         case OLEPROP_TYPE_STORAGE:      dumpString8( "storage-name" );          break;
376         case OLEPROP_TYPE_CLIPFMT:      dumpBlob( nPropId, "clip-data" );       break;
377     }
378 }
379 
dumpPropertyVector(sal_Int32 nPropId,sal_uInt16 nBaseType)380 void OlePropertyStreamObject::dumpPropertyVector( sal_Int32 nPropId, sal_uInt16 nBaseType )
381 {
382     sal_Int32 nElemCount = dumpDec< sal_Int32 >( "element-count" );
383     for( sal_Int32 nElemIdx = 0; !mxStrm->isEof() && (nElemIdx < nElemCount); ++nElemIdx )
384     {
385         mxOut->resetItemIndex( nElemIdx );
386         writeEmptyItem( "#element" );
387         IndentGuard aIndGuard( mxOut );
388         dumpPropertyValue( nPropId, nBaseType );
389     }
390 }
391 
dumpPropertyType()392 sal_uInt16 OlePropertyStreamObject::dumpPropertyType()
393 {
394     return static_cast< sal_uInt16 >( dumpHex< sal_Int32 >( "type", "OLEPROP-TYPE" ) & 0xFFFF );
395 }
396 
dumpBlob(sal_Int32 nPropId,const String & rName)397 void OlePropertyStreamObject::dumpBlob( sal_Int32 nPropId, const String& rName )
398 {
399     sal_Int32 nSize = dumpDec< sal_Int32 >( "data-size" );
400     if( nSize > 0 )
401     {
402         OUString aPropName = mxPropIds->getName( cfg(), nPropId );
403         if( aPropName == "'_PID_HLINKS'" )
404             dumpHlinks( nSize );
405         else
406             dumpBinary( rName, nSize );
407     }
408 }
409 
dumpString8(const String & rName)410 OUString OlePropertyStreamObject::dumpString8( const String& rName )
411 {
412     sal_Int32 nLen = dumpDec< sal_Int32 >( "string-len" );
413     return mbIsUnicode ? dumpCharArray16( rName, nLen ) : dumpCharArray8( rName, nLen );
414 }
415 
dumpCharArray8(const String & rName,sal_Int32 nLen)416 OUString OlePropertyStreamObject::dumpCharArray8( const String& rName, sal_Int32 nLen )
417 {
418     sal_Int32 nNewLen = getLimitedValue< sal_Int32, sal_Int32 >( nLen, 0, 1024 );
419     OUString aData = mxStrm->readCharArrayUC( nNewLen, meTextEnc );
420     writeStringItem( rName, aData );
421     return aData;
422 }
423 
dumpString16(const String & rName)424 OUString OlePropertyStreamObject::dumpString16( const String& rName )
425 {
426     sal_Int32 nLen = dumpDec< sal_Int32 >( "string-len" );
427     return dumpCharArray16( rName, nLen );
428 }
429 
dumpCharArray16(const String & rName,sal_Int32 nLen)430 OUString OlePropertyStreamObject::dumpCharArray16( const String& rName, sal_Int32 nLen )
431 {
432     sal_Int32 nNewLen = getLimitedValue< sal_Int32, sal_Int32 >( nLen, 0, 1024 );
433     OUString aData = mxStrm->readUnicodeArray( nNewLen );
434     writeStringItem( rName, aData );
435     if( nNewLen & 1 ) dumpUnused( 2 ); // always padding to 32bit
436     return aData;
437 }
438 
dumpTypedProperty(const String & rName,sal_uInt16 nExpectedType)439 bool OlePropertyStreamObject::dumpTypedProperty( const String& rName, sal_uInt16 nExpectedType )
440 {
441     writeEmptyItem( rName );
442     IndentGuard aIndGuard( mxOut );
443     return (dumpPropertyContents( -1 ) == nExpectedType) && !mxStrm->isEof();
444 }
445 
dumpHlinks(sal_Int32 nSize)446 void OlePropertyStreamObject::dumpHlinks( sal_Int32 nSize )
447 {
448     sal_Int64 nEndPos = mxStrm->tell() + nSize;
449     sal_Int32 nCount = dumpDec< sal_Int32 >( "property-count" );
450     bool bValid = true;
451     for( sal_Int32 nHlinkIndex = 0, nHlinkCount = nCount / 6; bValid && !mxStrm->isEof() && (nHlinkIndex < nHlinkCount); ++nHlinkIndex )
452     {
453         writeEmptyItem( "HYPERLINK" );
454         IndentGuard aIndGuard( mxOut );
455         bValid =
456             dumpTypedProperty( "hash", OLEPROP_TYPE_INT32 ) &&
457             dumpTypedProperty( "app", OLEPROP_TYPE_INT32 ) &&
458             dumpTypedProperty( "shape-id", OLEPROP_TYPE_INT32 ) &&
459             dumpTypedProperty( "info", OLEPROP_TYPE_INT32 ) &&
460             dumpTypedProperty( "target", OLEPROP_TYPE_STRING16 ) &&
461             dumpTypedProperty( "location", OLEPROP_TYPE_STRING16 );
462     }
463     dumpRemainingTo( nEndPos );
464 }
465 
startElement(sal_uInt32 nStartPos)466 bool OlePropertyStreamObject::startElement( sal_uInt32 nStartPos )
467 {
468     mxStrm->seek( nStartPos );
469     if( mxStrm->isEof() )
470         writeInfoItem( "stream-state", OOX_DUMP_ERR_STREAM );
471     return !mxStrm->isEof();
472 }
473 
writeSectionHeader(const OUString & rGuid,sal_uInt32 nStartPos)474 void OlePropertyStreamObject::writeSectionHeader( const OUString& rGuid, sal_uInt32 nStartPos )
475 {
476     MultiItemsGuard aMultiGuard( mxOut );
477     writeEmptyItem( "SECTION" );
478     writeHexItem( "pos", nStartPos, "CONV-DEC" );
479     writeGuidItem( "guid", rGuid );
480 }
481 
writePropertyHeader(sal_Int32 nPropId,sal_uInt32 nStartPos)482 void OlePropertyStreamObject::writePropertyHeader( sal_Int32 nPropId, sal_uInt32 nStartPos )
483 {
484     MultiItemsGuard aMultiGuard( mxOut );
485     writeEmptyItem( "PROPERTY" );
486     writeHexItem( "pos", nStartPos, "CONV-DEC" );
487     writeDecItem( "id", nPropId, mxPropIds );
488 }
489 
OleStorageObject(const ObjectBase & rParent,const StorageRef & rxStrg,const OUString & rSysPath)490 OleStorageObject::OleStorageObject( const ObjectBase& rParent, const StorageRef& rxStrg, const OUString& rSysPath )
491 {
492     construct( rParent, rxStrg, rSysPath );
493 }
494 
implDumpStream(const Reference<XInputStream> & rxStrm,const OUString &,const OUString & rStrmName,const OUString & rSysFileName)495 void OleStorageObject::implDumpStream( const Reference< XInputStream >& rxStrm, const OUString& /*rStrgPath*/, const OUString& rStrmName, const OUString& rSysFileName )
496 {
497     if ( rStrmName == "\001CompObj" )
498         OleCompObjObject( *this, rxStrm, rSysFileName ).dump();
499     else if( rStrmName ==  "\005SummaryInformation"  || rStrmName == "\005DocumentSummaryInformation" )
500         OlePropertyStreamObject( *this, rxStrm, rSysFileName ).dump();
501     else
502         BinaryStreamObject( *this, rxStrm, rSysFileName ).dump();
503 }
504 
ComCtlObjectBase(const InputObjectBase & rParent,sal_uInt32 nDataId5,sal_uInt32 nDataId6,sal_uInt16 nVersion,bool bCommonPart,bool bComplexPart)505 ComCtlObjectBase::ComCtlObjectBase( const InputObjectBase& rParent,
506         sal_uInt32 nDataId5, sal_uInt32 nDataId6, sal_uInt16 nVersion, bool bCommonPart, bool bComplexPart ) :
507     mnDataId5( nDataId5 ),
508     mnDataId6( nDataId6 ),
509     mnVersion( nVersion ),
510     mbCommonPart( bCommonPart ),
511     mbComplexPart( bComplexPart )
512 {
513     construct( rParent );
514 }
515 
implDump()516 void ComCtlObjectBase::implDump()
517 {
518     sal_uInt32 nCommonSize = 0;
519     dumpComCtlSize() && dumpComCtlData( nCommonSize ) && (!mbCommonPart || dumpComCtlCommon( nCommonSize )) && (!mbComplexPart || dumpComCtlComplex());
520 }
521 
implDumpCommonExtra(sal_Int64)522 void ComCtlObjectBase::implDumpCommonExtra( sal_Int64 /*nEndPos*/ )
523 {
524 }
525 
implDumpCommonTrailing()526 void ComCtlObjectBase::implDumpCommonTrailing()
527 {
528 }
529 
dumpComCtlHeader(sal_uInt32 nExpId,sal_uInt16 nExpMajor,sal_uInt16 nExpMinor)530 bool ComCtlObjectBase::dumpComCtlHeader( sal_uInt32 nExpId, sal_uInt16 nExpMajor, sal_uInt16 nExpMinor )
531 {
532     // no idea if all this is correct...
533     sal_uInt32 nId = dumpHex< sal_uInt32 >( "header-id", "COMCTL-HEADER-IDS" );
534     ItemGuard aItem( mxOut, "version" );
535     sal_uInt16 nMinor = mxStrm->readuInt16();
536     sal_uInt16 nMajor = mxStrm->readuInt16();
537     mxOut->writeDec( nMajor );
538     mxOut->writeChar( '.' );
539     mxOut->writeDec( nMinor );
540     return !mxStrm->isEof() && (nId == nExpId) && ((nExpMajor == SAL_MAX_UINT16) || (nExpMajor == nMajor)) && ((nExpMinor == SAL_MAX_UINT16) || (nExpMinor == nMinor));
541 }
542 
dumpComCtlSize()543 bool ComCtlObjectBase::dumpComCtlSize()
544 {
545     if( dumpComCtlHeader( 0x12344321, 0, 8 ) )
546     {
547         IndentGuard aIndGuard( mxOut );
548         dumpDec< sal_Int32 >( "width", "CONV-HMM-TO-CM" );
549         dumpDec< sal_Int32 >( "height", "CONV-HMM-TO-CM" );
550         return !mxStrm->isEof();
551     }
552     return false;
553 }
554 
dumpComCtlData(sal_uInt32 & ornCommonPartSize)555 bool ComCtlObjectBase::dumpComCtlData( sal_uInt32& ornCommonPartSize )
556 {
557     if( dumpComCtlHeader( (mnVersion == 5) ? mnDataId5 : mnDataId6, mnVersion ) )
558     {
559         IndentGuard aIndGuard( mxOut );
560         if( mbCommonPart )
561             ornCommonPartSize = dumpDec< sal_uInt32 >( "common-part-size" );
562         implDumpProperties();
563         return !mxStrm->isEof();
564     }
565     return false;
566 }
567 
dumpComCtlCommon(sal_uInt32 nPartSize)568 bool ComCtlObjectBase::dumpComCtlCommon( sal_uInt32 nPartSize )
569 {
570     sal_Int64 nEndPos = mxStrm->tell() + nPartSize;
571     if( (nPartSize >= 16) && dumpComCtlHeader( 0xABCDEF01, 5, 0 ) )
572     {
573         IndentGuard aIndGuard( mxOut );
574         dumpUnknown( 4 );
575         dumpHex< sal_uInt32 >( "common-flags", "COMCTL-COMMON-FLAGS" );
576         implDumpCommonExtra( nEndPos );
577         dumpRemainingTo( nEndPos );
578         implDumpCommonTrailing();
579         return !mxStrm->isEof();
580     }
581     return false;
582 }
583 
dumpComCtlComplex()584 bool ComCtlObjectBase::dumpComCtlComplex()
585 {
586     if( dumpComCtlHeader( 0xBDECDE1F, 5, 1 ) )
587     {
588         IndentGuard aIndGuard( mxOut );
589         sal_uInt32 nFlags = dumpHex< sal_uInt32 >( "comctl-complex-flags", "COMCTL-COMPLEX-FLAGS" );
590         if( !mxStrm->isEof() && (nFlags & 0x01) )
591         {
592             writeEmptyItem( "font" );
593             IndentGuard aIndGuard2( mxOut );
594             OUString aClassName = cfg().getStringOption( dumpGuid(), OUString() );
595             if ( aClassName == "StdFont" )
596                 StdFontObject( *this ).dump();
597         }
598         if( !mxStrm->isEof() && (nFlags & 0x02) )
599         {
600             writeEmptyItem( "mouse-icon" );
601             IndentGuard aIndGuard2( mxOut );
602             OUString aClassName = cfg().getStringOption( dumpGuid(), OUString() );
603             if ( aClassName == "StdPic" )
604                 StdPicObject( *this ).dump();
605         }
606         return !mxStrm->isEof();
607     }
608     return false;
609 }
610 
ComCtlScrollBarObject(const InputObjectBase & rParent,sal_uInt16 nVersion)611 ComCtlScrollBarObject::ComCtlScrollBarObject( const InputObjectBase& rParent, sal_uInt16 nVersion ) :
612     ComCtlObjectBase( rParent, SAL_MAX_UINT32, 0x99470A83, nVersion, true, true )
613 {
614 }
615 
implDumpProperties()616 void ComCtlScrollBarObject::implDumpProperties()
617 {
618     dumpHex< sal_uInt32 >( "flags", "COMCTL-SCROLLBAR-FLAGS" );
619     dumpDec< sal_Int32 >( "large-change" );
620     dumpDec< sal_Int32 >( "small-change" );
621     dumpDec< sal_Int32 >( "min" );
622     dumpDec< sal_Int32 >( "max" );
623     dumpDec< sal_Int32 >( "value" );
624 }
625 
ComCtlProgressBarObject(const InputObjectBase & rParent,sal_uInt16 nVersion)626 ComCtlProgressBarObject::ComCtlProgressBarObject( const InputObjectBase& rParent, sal_uInt16 nVersion ) :
627     ComCtlObjectBase( rParent, 0xE6E17E84, 0x97AB8A01, nVersion, true, true )
628 {
629 }
630 
implDumpProperties()631 void ComCtlProgressBarObject::implDumpProperties()
632 {
633     dumpDec< float >( "min" );
634     dumpDec< float >( "max" );
635     if( mnVersion == 6 )
636     {
637         dumpBool< sal_uInt16 >( "vertical" );
638         dumpBool< sal_uInt16 >( "smooth-scroll" );
639     }
640 }
641 
ComCtlSliderObject(const InputObjectBase & rParent,sal_uInt16 nVersion)642 ComCtlSliderObject::ComCtlSliderObject( const InputObjectBase& rParent, sal_uInt16 nVersion ) :
643     ComCtlObjectBase( rParent, 0xE6E17E86, 0x0A2BAE11, nVersion, true, true )
644 {
645 }
646 
implDumpProperties()647 void ComCtlSliderObject::implDumpProperties()
648 {
649     dumpBool< sal_Int32 >( "vertical" );
650     dumpDec< sal_Int32 >( "large-change" );
651     dumpDec< sal_Int32 >( "small-change" );
652     dumpDec< sal_Int32 >( "min" );
653     dumpDec< sal_Int32 >( "max" );
654     dumpDec< sal_Int16 >( "select-range", "COMCTL-SLIDER-SELECTRANGE" );
655     dumpUnused( 2 );
656     dumpDec< sal_Int32 >( "select-start" );
657     dumpDec< sal_Int32 >( "select-length" );
658     dumpDec< sal_Int32 >( "tick-style", "COMCTL-SLIDER-TICKSTYLE" );
659     dumpDec< sal_Int32 >( "tick-frequency" );
660     dumpDec< sal_Int32 >( "value" );
661     if( mnVersion == 6 )
662         dumpBool< sal_Int32 >( "tooltip-below" );
663 }
664 
ComCtlUpDownObject(const InputObjectBase & rParent,sal_uInt16 nVersion)665 ComCtlUpDownObject::ComCtlUpDownObject( const InputObjectBase& rParent, sal_uInt16 nVersion ) :
666     ComCtlObjectBase( rParent, 0xFF3626A0, 0xFF3626A0, nVersion, false, false )
667 {
668 }
669 
implDumpProperties()670 void ComCtlUpDownObject::implDumpProperties()
671 {
672     dumpUnknown( 16 ); // buddy-property, somehow
673     dumpDec< sal_Int32 >( "buddy-control" );
674     dumpUnknown( 8 );
675     dumpDec< sal_Int32 >( "value" );
676     dumpUnknown( 4 );
677     dumpDec< sal_Int32 >( "increment" );
678     dumpDec< sal_Int32 >( "max" );
679     dumpDec< sal_Int32 >( "min" );
680     dumpHex< sal_uInt32 >( "flags-1", "COMCTL-UPDOWN-FLAGS1" );
681     dumpHex< sal_uInt32 >( "flags-2", "COMCTL-UPDOWN-FLAGS2" );
682     dumpUnknown( 4 );
683 }
684 
ComCtlImageListObject(const InputObjectBase & rParent,sal_uInt16 nVersion)685 ComCtlImageListObject::ComCtlImageListObject( const InputObjectBase& rParent, sal_uInt16 nVersion ) :
686     ComCtlObjectBase( rParent, 0xE6E17E80, 0xE6E17E80, nVersion, true, false )
687 {
688 }
689 
implDumpProperties()690 void ComCtlImageListObject::implDumpProperties()
691 {
692     dumpDec< sal_uInt16 >( "image-width" );
693     dumpDec< sal_uInt16 >( "image-height" );
694     dumpOleColor( "mask-color" );
695     dumpBool< sal_Int16 >( "use-mask-color" );
696     dumpUnknown( 2 );
697 }
698 
implDumpCommonExtra(sal_Int64)699 void ComCtlImageListObject::implDumpCommonExtra( sal_Int64 /*nEndPos*/ )
700 {
701     dumpUnknown( 4 );
702     dumpOleColor( "back-color" );
703     dumpUnknown( 4 );
704     sal_Int32 nImageCount = dumpDec< sal_Int32 >( "image-count" );
705     mxOut->resetItemIndex();
706     for( sal_Int32 nImageIndex = 0; (nImageIndex < nImageCount) && !mxStrm->isEof(); ++nImageIndex )
707     {
708         writeEmptyItem( "#image" );
709         IndentGuard aIndGuard( mxOut );
710         sal_uInt8 nFlags = dumpHex< sal_uInt8 >( "text-flags", "COMCTL-IMAGELIST-TEXTFLAGS" );
711         if( nFlags & 0x01 ) dumpUniString32( "caption" );
712         if( nFlags & 0x02 ) dumpUniString32( "key" );
713     }
714 }
715 
implDumpCommonTrailing()716 void ComCtlImageListObject::implDumpCommonTrailing()
717 {
718     sal_Int32 nImageCount = dumpDec< sal_Int32 >( "image-count" );
719     mxOut->resetItemIndex();
720     for( sal_Int32 nImageIndex = 0; (nImageIndex < nImageCount) && !mxStrm->isEof(); ++nImageIndex )
721     {
722         writeEmptyItem( "#image" );
723         IndentGuard aIndGuard( mxOut );
724         dumpDec< sal_Int32 >( "index" );
725         StdPicObject( *this ).dump();
726     }
727 }
728 
ComCtlTabStripObject(const InputObjectBase & rParent,sal_uInt16 nVersion)729 ComCtlTabStripObject::ComCtlTabStripObject( const InputObjectBase& rParent, sal_uInt16 nVersion ) :
730     ComCtlObjectBase( rParent, 0xE6E17E8A, 0xD12A7AC1, nVersion, true, true )
731 {
732 }
733 
implDumpProperties()734 void ComCtlTabStripObject::implDumpProperties()
735 {
736     dumpHex< sal_uInt32 >( "flags-1", "COMCTL-TABSTRIP-FLAGS1" );
737     dumpDec< sal_uInt16 >( "tab-fixed-width", "CONV-HMM-TO-CM" );
738     dumpDec< sal_uInt16 >( "tab-fixed-height", "CONV-HMM-TO-CM" );
739     if( mnVersion == 6 )
740     {
741         dumpHex< sal_uInt32 >( "flags-2", "COMCTL-TABSTRIP-FLAGS2" );
742         dumpDec< sal_uInt16 >( "tab-min-width", "CONV-HMM-TO-CM" );
743         dumpUnknown( 2 );
744         dumpHex< sal_uInt32 >( "flags-3", "COMCTL-TABSTRIP-FLAGS3" );
745     }
746 }
747 
implDumpCommonExtra(sal_Int64)748 void ComCtlTabStripObject::implDumpCommonExtra( sal_Int64 /*nEndPos*/ )
749 {
750     dumpUnknown( 12 );
751     dumpUniString32( "image-list" );
752     sal_Int32 nTabCount = dumpDec< sal_Int32 >( "tab-count" );
753     mxOut->resetItemIndex();
754     for( sal_Int32 nTabIndex = 0; (nTabIndex < nTabCount) && !mxStrm->isEof(); ++nTabIndex )
755     {
756         writeEmptyItem( "#tab" );
757         IndentGuard aIndGuard( mxOut );
758         dumpUnknown( 4 );
759         sal_uInt32 nTabFlags = dumpHex< sal_uInt32 >( "tab-flags", "COMCTL-TABSTRIP-TABFLAGS" );
760         if( nTabFlags & 0x01 ) dumpUniString32( "caption" );
761         if( nTabFlags & 0x02 ) dumpUniString32( "key" );
762         if( nTabFlags & 0x04 ) dumpUniString32( "tag" );
763         if( nTabFlags & 0x08 ) dumpUniString32( "tooltip" );
764         dumpDec< sal_uInt16 >( "image-id" );
765     }
766 }
767 
ComCtlTreeViewObject(const InputObjectBase & rParent,sal_uInt16 nVersion)768 ComCtlTreeViewObject::ComCtlTreeViewObject( const InputObjectBase& rParent, sal_uInt16 nVersion ) :
769     ComCtlObjectBase( rParent, 0xE6E17E8E, 0x6AC13CB1, nVersion, true, true ),
770     mnStringFlags( 0 )
771 {
772 }
773 
implDumpProperties()774 void ComCtlTreeViewObject::implDumpProperties()
775 {
776     dumpHex< sal_uInt32 >( "flags", "COMCTL-TREEVIEW-FLAGS" );
777     dumpDec< sal_Int32 >( "indentation", "CONV-HMM-TO-CM" );
778     if( mnVersion == 6 )
779         dumpHex< sal_uInt32 >( "flags-2", "COMCTL-TREEVIEW-FLAGS2" );
780     mnStringFlags = dumpHex< sal_uInt32 >( "string-flags", "COMCTL-TREEVIEW-STRINGFLAGS" );
781 }
782 
implDumpCommonExtra(sal_Int64)783 void ComCtlTreeViewObject::implDumpCommonExtra( sal_Int64 /*nEndPos*/ )
784 {
785     dumpOleColor( "text-color" );
786     dumpOleColor( "back-color" );
787     dumpUnknown( 4 );
788     if( mnStringFlags & 0x02 )
789         dumpUniString32( "image-list" );
790     dumpUniString32( "path-separator" );
791 }
792 
ComCtlStatusBarObject(const InputObjectBase & rParent,sal_uInt16 nVersion)793 ComCtlStatusBarObject::ComCtlStatusBarObject( const InputObjectBase& rParent, sal_uInt16 nVersion ) :
794     ComCtlObjectBase( rParent, 0xE6E17E88, SAL_MAX_UINT32, nVersion, true, true )
795 {
796 }
797 
implDumpProperties()798 void ComCtlStatusBarObject::implDumpProperties()
799 {
800     dumpBool< sal_Int32 >( "style-simple-text" );
801     dumpBool< sal_Int16 >( "show-tips" );
802     dumpUnknown( 2 );
803 }
804 
implDumpCommonExtra(sal_Int64)805 void ComCtlStatusBarObject::implDumpCommonExtra( sal_Int64 /*nEndPos*/ )
806 {
807     dumpUnknown( 12 );
808     dumpUniString32( "simple-text" );
809     sal_Int32 nPanelCount = dumpDec< sal_Int32 >( "panel-count" );
810     mxOut->resetItemIndex();
811     for( sal_Int32 nPanelIndex = 0; (nPanelIndex < nPanelCount) && !mxStrm->isEof(); ++nPanelIndex )
812     {
813         writeEmptyItem( "#panel" );
814         IndentGuard aIndGuard( mxOut );
815         dumpHex< sal_uInt32 >( "panel-flags", "COMCTL-STATUSBAR-PANELFLAGS" );
816         dumpDec< sal_Int32 >( "current-width", "CONV-HMM-TO-CM" );
817         dumpDec< sal_Int32 >( "minimal-width", "CONV-HMM-TO-CM" );
818         sal_uInt32 nTextFlags = dumpHex< sal_uInt32 >( "text-flags", "COMCTL-STATUSBAR-TEXTFLAGS" );
819         if( nTextFlags & 0x01 ) dumpUniString32( "text" );
820         if( nTextFlags & 0x02 ) dumpUniString32( "vis-text" );
821         if( nTextFlags & 0x04 ) dumpUniString32( "key" );
822         if( nTextFlags & 0x08 ) dumpUniString32( "tag" );
823         if( nTextFlags & 0x10 ) dumpUniString32( "tooltip" );
824     }
825 }
826 
implDumpCommonTrailing()827 void ComCtlStatusBarObject::implDumpCommonTrailing()
828 {
829     sal_Int32 nImageCount = dumpDec< sal_Int32 >( "image-count" );
830     mxOut->resetItemIndex();
831     for( sal_Int32 nImageIndex = 0; (nImageIndex < nImageCount) && !mxStrm->isEof(); ++nImageIndex )
832     {
833         writeEmptyItem( "#image" );
834         IndentGuard aIndGuard( mxOut );
835         dumpDec< sal_Int32 >( "panel-index" );
836         StdPicObject( *this ).dump();
837     }
838 }
839 
construct(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName,const String & rPropNameList,bool b64BitPropFlags)840 void AxPropertyObjectBase::construct( const ObjectBase& rParent,
841         const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName, const String& rPropNameList, bool b64BitPropFlags )
842 {
843     OleInputObjectBase::construct( rParent, rxStrm, rSysFileName );
844     constructAxPropObj( rPropNameList, b64BitPropFlags );
845 }
846 
construct(const InputObjectBase & rParent,const String & rPropNameList,bool b64BitPropFlags)847 void AxPropertyObjectBase::construct( const InputObjectBase& rParent,
848         const String& rPropNameList, bool b64BitPropFlags )
849 {
850     OleInputObjectBase::construct( rParent );
851     constructAxPropObj( rPropNameList, b64BitPropFlags );
852 }
853 
implIsValid() const854 bool AxPropertyObjectBase::implIsValid() const
855 {
856     return OleInputObjectBase::implIsValid() && mxStrm->isSeekable();
857 }
858 
implDump()859 void AxPropertyObjectBase::implDump()
860 {
861     mbValid = true;
862     // header
863     setAlignAnchor();
864     dumpVersion();
865     sal_uInt16 nSize = dumpDec< sal_uInt16 >( "size" );
866     mnPropertiesEnd = mxStrm->tell() + nSize;
867     // property flags
868     maLargeProps.clear();
869     maStreamProps.clear();
870     mnPropFlags = dumpHex< sal_Int64, sal_uInt32 >( mb64BitPropFlags, "properties", mxPropNames );
871     mnCurrProp = 0;
872     // properties
873     dumpShortProperties();
874     dumpLargeProperties();
875     setAlignAnchor();
876     if( ensureValid() )
877         implDumpExtended();
878 }
879 
implDumpShortProperties()880 void AxPropertyObjectBase::implDumpShortProperties()
881 {
882 }
883 
implDumpExtended()884 void AxPropertyObjectBase::implDumpExtended()
885 {
886 }
887 
ensureValid(bool bCondition)888 bool AxPropertyObjectBase::ensureValid( bool bCondition )
889 {
890     if( mbValid && (!bCondition || mxStrm->isEof()) )
891     {
892         if( !bCondition )
893             writeInfoItem( "state", OOX_DUMP_ERRASCII( "format-error" ) );
894         mbValid = false;
895     }
896     return mbValid;
897 }
898 
setAlignAnchor()899 void AxPropertyObjectBase::setAlignAnchor()
900 {
901     mnPropertiesStart = mxStrm->tell();
902 }
903 
startNextProperty()904 bool AxPropertyObjectBase::startNextProperty()
905 {
906     if( mnCurrProp == 0 ) mnCurrProp = 1; else mnCurrProp <<= 1;
907     bool bHasProp = getFlag( mnPropFlags, mnCurrProp );
908     setFlag( mnPropFlags, mnCurrProp, false );
909     return ensureValid() && bHasProp;
910 }
911 
getPropertyName() const912 OUString AxPropertyObjectBase::getPropertyName() const
913 {
914     return cfg().getName( mxPropNames, mnCurrProp );
915 }
916 
dumpFlagsProperty(sal_uInt32 nDefault,const char * pcNameList)917 sal_uInt32 AxPropertyObjectBase::dumpFlagsProperty( sal_uInt32 nDefault, const char* pcNameList )
918 {
919     if( startNextProperty() )
920     {
921         alignInput< sal_uInt32 >();
922         return dumpHex< sal_uInt32 >( getPropertyName(), pcNameList );
923     }
924     return nDefault;
925 }
926 
dumpColorProperty(sal_uInt32 nDefault)927 sal_uInt32 AxPropertyObjectBase::dumpColorProperty( sal_uInt32 nDefault )
928 {
929     if( startNextProperty() )
930     {
931         alignInput< sal_uInt32 >();
932         return dumpOleColor( getPropertyName() );
933     }
934     return nDefault;
935 }
936 
dumpUnicodeProperty()937 sal_Unicode AxPropertyObjectBase::dumpUnicodeProperty()
938 {
939     if( startNextProperty() )
940     {
941         alignInput< sal_uInt16 >();
942         return dumpUnicode( getPropertyName() );
943     }
944     return '\0';
945 }
946 
dumpUnknownProperty()947 void AxPropertyObjectBase::dumpUnknownProperty()
948 {
949     if( startNextProperty() )
950         ensureValid( false );
951 }
952 
dumpPosProperty()953 void AxPropertyObjectBase::dumpPosProperty()
954 {
955     if( startNextProperty() )
956         maLargeProps.emplace_back( LargeProperty::PROPTYPE_POS, getPropertyName(), 8 );
957 }
958 
dumpSizeProperty()959 void AxPropertyObjectBase::dumpSizeProperty()
960 {
961     if( startNextProperty() )
962         maLargeProps.emplace_back( LargeProperty::PROPTYPE_SIZE, getPropertyName(), 8 );
963 }
964 
dumpGuidProperty(OUString * pValue)965 void AxPropertyObjectBase::dumpGuidProperty( OUString* pValue )
966 {
967     if( startNextProperty() )
968         maLargeProps.emplace_back( LargeProperty::PROPTYPE_GUID, getPropertyName(), 16, pValue );
969 }
970 
dumpStringProperty(OUString * pValue)971 void AxPropertyObjectBase::dumpStringProperty( OUString* pValue )
972 {
973     if( startNextProperty() )
974     {
975         alignInput< sal_uInt32 >();
976         sal_uInt32 nLen = dumpHex< sal_uInt32 >( getPropertyName(), "AX-STRINGLEN" );
977         maLargeProps.emplace_back( LargeProperty::PROPTYPE_STRING, getPropertyName(), nLen, pValue );
978     }
979 }
980 
dumpStringArrayProperty()981 void AxPropertyObjectBase::dumpStringArrayProperty()
982 {
983     if( startNextProperty() )
984     {
985         alignInput< sal_uInt32 >();
986         sal_uInt32 nLen = dumpHex< sal_uInt32 >( getPropertyName(), "CONV-DEC" );
987         maLargeProps.emplace_back( LargeProperty::PROPTYPE_STRINGARRAY, getPropertyName(), nLen );
988     }
989 }
990 
dumpStreamProperty()991 void AxPropertyObjectBase::dumpStreamProperty()
992 {
993     if( startNextProperty() )
994     {
995         alignInput< sal_uInt16 >();
996         sal_uInt16 nData = dumpHex< sal_uInt16 >( getPropertyName() );
997         maStreamProps.emplace_back( getPropertyName(), nData );
998     }
999 }
1000 
dumpEmbeddedFont()1001 void AxPropertyObjectBase::dumpEmbeddedFont()
1002 {
1003     if( ensureValid() )
1004     {
1005         writeEmptyItem( "embedded-fontdata" );
1006         IndentGuard aIndGuard( mxOut );
1007         AxCFontNewObject( *this ).dump();
1008     }
1009 }
1010 
dumpToPosition(sal_Int64 nPos)1011 void AxPropertyObjectBase::dumpToPosition( sal_Int64 nPos )
1012 {
1013     dumpRemainingTo( nPos );
1014     mbValid = true;
1015     ensureValid();
1016 }
1017 
constructAxPropObj(const String & rPropNameList,bool b64BitPropFlags)1018 void AxPropertyObjectBase::constructAxPropObj( const String& rPropNameList, bool b64BitPropFlags )
1019 {
1020     if( OleInputObjectBase::implIsValid() )
1021     {
1022         mxPropNames = cfg().getNameList( rPropNameList );
1023         mb64BitPropFlags = b64BitPropFlags;
1024         mbValid = true;
1025     }
1026 }
1027 
dumpVersion()1028 void AxPropertyObjectBase::dumpVersion()
1029 {
1030     ItemGuard aItem( mxOut, "version" );
1031     sal_uInt8 nMinor = mxStrm->readuChar();
1032     sal_uInt8 nMajor = mxStrm->readuChar();
1033     mxOut->writeDec( nMajor );
1034     mxOut->writeChar( '.' );
1035     mxOut->writeDec( nMinor );
1036 }
1037 
dumpString(const String & rName,sal_uInt32 nSize,bool bArray)1038 OUString AxPropertyObjectBase::dumpString( const String& rName, sal_uInt32 nSize, bool bArray )
1039 {
1040     bool bCompressed = getFlag( nSize, AX_STRING_COMPRESSED );
1041     sal_uInt32 nBufSize = extractValue< sal_uInt32 >( nSize, 0, 31 );
1042     OUString aString = bCompressed ?
1043         dumpCharArray( rName, nBufSize, RTL_TEXTENCODING_ISO_8859_1 ) :
1044         dumpUnicodeArray( rName, bArray ? nBufSize : (nBufSize / 2) );
1045     alignInput< sal_Int32 >();
1046     return aString;
1047 }
1048 
dumpShortProperties()1049 void AxPropertyObjectBase::dumpShortProperties()
1050 {
1051     if( ensureValid() )
1052     {
1053         writeEmptyItem( "short-properties" );
1054         IndentGuard aIndGuard( mxOut );
1055         implDumpShortProperties();
1056         alignInput< sal_uInt32 >();
1057     }
1058 }
1059 
dumpLargeProperties()1060 void AxPropertyObjectBase::dumpLargeProperties()
1061 {
1062     if( ensureValid( mnPropFlags == 0 ) && !maLargeProps.empty() )
1063     {
1064         writeEmptyItem( "large-properties" );
1065         IndentGuard aIndGuard( mxOut );
1066         for (auto const& largeProp : maLargeProps)
1067         {
1068             if (!ensureValid())
1069                 break;
1070             switch( largeProp.mePropType )
1071             {
1072                 case LargeProperty::PROPTYPE_POS:
1073                 {
1074                     MultiItemsGuard aMultiGuard( mxOut );
1075                     writeEmptyItem( largeProp.maItemName );
1076                     dumpDec< sal_Int32 >( "top", "CONV-HMM-TO-CM" );
1077                     dumpDec< sal_Int32 >( "left", "CONV-HMM-TO-CM" );
1078                 }
1079                 break;
1080                 case LargeProperty::PROPTYPE_SIZE:
1081                 {
1082                     MultiItemsGuard aMultiGuard( mxOut );
1083                     writeEmptyItem( largeProp.maItemName );
1084                     dumpDec< sal_Int32 >( "width", "CONV-HMM-TO-CM" );
1085                     dumpDec< sal_Int32 >( "height", "CONV-HMM-TO-CM" );
1086                 }
1087                 break;
1088                 case LargeProperty::PROPTYPE_GUID:
1089                 {
1090                     OUString aGuid = dumpGuid( largeProp.maItemName );
1091                     if( largeProp.mpItemValue )
1092                         *largeProp.mpItemValue = cfg().getStringOption( aGuid, OUString() );
1093                 }
1094                 break;
1095                 case LargeProperty::PROPTYPE_STRING:
1096                 {
1097                     OUString aString = dumpString( largeProp.maItemName, largeProp.mnDataSize, false );
1098                     if( largeProp.mpItemValue )
1099                         *largeProp.mpItemValue = aString;
1100                 }
1101                 break;
1102                 case LargeProperty::PROPTYPE_STRINGARRAY:
1103                 {
1104                     writeEmptyItem( largeProp.maItemName );
1105                     IndentGuard aIndGuard2( mxOut );
1106                     mxOut->resetItemIndex();
1107                     sal_Int64 nEndPos = mxStrm->tell() + largeProp.mnDataSize;
1108                     while( mxStrm->tell() < nEndPos )
1109                     {
1110                         MultiItemsGuard aMultiGuard( mxOut );
1111                         sal_uInt32 nDataSize = dumpHex< sal_uInt32 >( "#flags", "AX-ARRAYSTRINGLEN" );
1112                         dumpString( "string", nDataSize, true );
1113                     }
1114                     dumpToPosition( nEndPos );
1115                 }
1116                 break;
1117             }
1118         }
1119     }
1120     dumpToPosition( mnPropertiesEnd );
1121 
1122     if( !ensureValid() || maStreamProps.empty() )
1123         return;
1124 
1125     writeEmptyItem( "stream-properties" );
1126     IndentGuard aIndGuard( mxOut );
1127     for (auto const& streamProp : maStreamProps)
1128     {
1129         if (!ensureValid())
1130             break;
1131         writeEmptyItem( streamProp.maItemName );
1132         if( ensureValid( streamProp.mnData == 0xFFFF ) )
1133         {
1134             IndentGuard aIndGuard2( mxOut );
1135             OUString aClassName = cfg().getStringOption( dumpGuid(), OUString() );
1136             if ( aClassName == "StdFont" )
1137                 StdFontObject( *this ).dump();
1138             else if ( aClassName == "StdPic" )
1139                 StdPicObject( *this ).dump();
1140             else if ( aClassName == "CFontNew" )
1141                 AxCFontNewObject( *this ).dump();
1142             else
1143                 ensureValid( false );
1144         }
1145     }
1146 }
1147 
AxCFontNewObject(const InputObjectBase & rParent)1148 AxCFontNewObject::AxCFontNewObject( const InputObjectBase& rParent )
1149 {
1150     AxPropertyObjectBase::construct( rParent, "AX-CFONTNEW-PROPERTIES" );
1151 }
1152 
implDumpShortProperties()1153 void AxCFontNewObject::implDumpShortProperties()
1154 {
1155     dumpStringProperty();
1156     dumpFlagsProperty( 0, "AX-CFONTNEW-FLAGS" );
1157     dumpDecProperty< sal_Int32 >( 160 );
1158     dumpDecProperty< sal_Int32 >( 0 );
1159     dumpDecProperty< sal_uInt8 >( WINDOWS_CHARSET_DEFAULT, "CHARSET" );
1160     dumpDecProperty< sal_uInt8 >( 0, "FONT-PITCHFAMILY" );
1161     dumpDecProperty< sal_uInt8 >( 1, "AX-CFONTNEW-ALIGNMENT" );
1162     dumpDecProperty< sal_uInt16 >( 400, "FONT-WEIGHT" );
1163 }
1164 
AxColumnInfoObject(const InputObjectBase & rParent)1165 AxColumnInfoObject::AxColumnInfoObject( const InputObjectBase& rParent )
1166 {
1167     AxPropertyObjectBase::construct( rParent, "AX-COLUMNINFO-PROPERTIES" );
1168 }
1169 
implDumpShortProperties()1170 void AxColumnInfoObject::implDumpShortProperties()
1171 {
1172     dumpDecProperty< sal_Int32 >( -1, "CONV-HMM-TO-CM" );
1173 }
1174 
AxCommandButtonObject(const InputObjectBase & rParent)1175 AxCommandButtonObject::AxCommandButtonObject( const InputObjectBase& rParent )
1176 {
1177     AxPropertyObjectBase::construct( rParent, "AX-COMMANDBUTTON-PROPERTIES" );
1178 }
1179 
implDumpShortProperties()1180 void AxCommandButtonObject::implDumpShortProperties()
1181 {
1182     dumpColorProperty( 0x80000012 );
1183     dumpColorProperty( 0x80000008 );
1184     dumpFlagsProperty( 0x0000001B );
1185     dumpStringProperty();
1186     dumpImagePosProperty();
1187     dumpSizeProperty();
1188     dumpMousePtrProperty();
1189     dumpStreamProperty();
1190     dumpUnicodeProperty();
1191     dumpBoolProperty();
1192     dumpStreamProperty();
1193 }
1194 
implDumpExtended()1195 void AxCommandButtonObject::implDumpExtended()
1196 {
1197     dumpEmbeddedFont();
1198 }
1199 
AxMorphControlObject(const InputObjectBase & rParent)1200 AxMorphControlObject::AxMorphControlObject( const InputObjectBase& rParent )
1201 {
1202     AxPropertyObjectBase::construct( rParent, "AX-MORPH-PROPERTIES", true );
1203 }
1204 
implDumpShortProperties()1205 void AxMorphControlObject::implDumpShortProperties()
1206 {
1207     dumpFlagsProperty( 0x2C80081B );
1208     dumpColorProperty( 0x80000005 );
1209     dumpColorProperty( 0x80000008 );
1210     dumpDecProperty< sal_uInt32 >( 0 );
1211     dumpBorderStyleProperty< sal_uInt8 >( 0 );
1212     dumpDecProperty< sal_uInt8 >( 0, "AX-MORPH-SCROLLBARS" );
1213     mnCtrlType = dumpDecProperty< sal_uInt8 >( 1, "AX-MORPH-CONTROLTYPE" );
1214     dumpMousePtrProperty();
1215     dumpSizeProperty();
1216     dumpUnicodeProperty();
1217     dumpDecProperty< sal_uInt32 >( 0, "CONV-HMM-TO-CM" );
1218     dumpDecProperty< sal_uInt16 >( 1, "AX-MORPH-BOUNDCOLUMN" );
1219     dumpDecProperty< sal_Int16 >( -1, "AX-MORPH-TEXTCOLUMN" );
1220     dumpDecProperty< sal_Int16 >( 1, "AX-MORPH-COLUMNCOUNT" );
1221     dumpDecProperty< sal_uInt16 >( 8 );
1222     mnColInfoCount = dumpDecProperty< sal_uInt16 >( 1 );
1223     dumpDecProperty< sal_uInt8 >( 2, "AX-MORPH-MATCHENTRYTYPE" );
1224     dumpDecProperty< sal_uInt8 >( 0, "AX-MORPH-LISTSTYLE" );
1225     dumpDecProperty< sal_uInt8 >( 0, "AX-MORPH-SHOWDROPDOWNMODE" );
1226     dumpUnknownProperty();
1227     dumpDecProperty< sal_uInt8 >( 1, "AX-MORPH-DROPDOWNSTYLE" );
1228     dumpDecProperty< sal_uInt8 >( 0, "AX-MORPH-SELECTIONTYPE" );
1229     dumpStringProperty();
1230     dumpStringProperty();
1231     dumpImagePosProperty();
1232     dumpColorProperty( 0x80000006 );
1233     dumpSpecialEffectProperty< sal_uInt32 >( 2 );
1234     dumpStreamProperty();
1235     dumpStreamProperty();
1236     dumpUnicodeProperty();
1237     dumpUnknownProperty();
1238     dumpBoolProperty();
1239     dumpStringProperty();
1240 }
1241 
implDumpExtended()1242 void AxMorphControlObject::implDumpExtended()
1243 {
1244     dumpEmbeddedFont();
1245     dumpColumnInfos();
1246 }
1247 
dumpColumnInfos()1248 void AxMorphControlObject::dumpColumnInfos()
1249 {
1250     if( ensureValid() && (mnColInfoCount > 0) && ((mnCtrlType == 2) || (mnCtrlType == 3)) )
1251     {
1252         mxOut->resetItemIndex();
1253         for( sal_uInt16 nIdx = 0; ensureValid() && (nIdx < mnColInfoCount); ++nIdx )
1254         {
1255             writeEmptyItem( "#column-info" );
1256             IndentGuard aIndGuard( mxOut );
1257             AxColumnInfoObject( *this ).dump();
1258         }
1259     }
1260 }
1261 
AxLabelObject(const InputObjectBase & rParent)1262 AxLabelObject::AxLabelObject( const InputObjectBase& rParent )
1263 {
1264     AxPropertyObjectBase::construct( rParent, "AX-LABEL-PROPERTIES" );
1265 }
1266 
implDumpShortProperties()1267 void AxLabelObject::implDumpShortProperties()
1268 {
1269     dumpColorProperty( 0x80000012 );
1270     dumpColorProperty( 0x8000000F );
1271     dumpFlagsProperty( 0x0080001B );
1272     dumpStringProperty();
1273     dumpImagePosProperty();
1274     dumpSizeProperty();
1275     dumpMousePtrProperty();
1276     dumpColorProperty( 0x80000006 );
1277     dumpBorderStyleProperty< sal_uInt16 >( 0 );
1278     dumpSpecialEffectProperty< sal_uInt16 >( 0 );
1279     dumpStreamProperty();
1280     dumpUnicodeProperty();
1281     dumpStreamProperty();
1282 }
1283 
implDumpExtended()1284 void AxLabelObject::implDumpExtended()
1285 {
1286     dumpEmbeddedFont();
1287 }
1288 
AxImageObject(const InputObjectBase & rParent)1289 AxImageObject::AxImageObject( const InputObjectBase& rParent )
1290 {
1291     AxPropertyObjectBase::construct( rParent, "AX-IMAGE-PROPERTIES" );
1292 }
1293 
implDumpShortProperties()1294 void AxImageObject::implDumpShortProperties()
1295 {
1296     dumpUnknownProperty();
1297     dumpUnknownProperty();
1298     dumpBoolProperty();
1299     dumpColorProperty( 0x80000006 );
1300     dumpColorProperty( 0x8000000F );
1301     dumpBorderStyleProperty< sal_uInt8 >( 1 );
1302     dumpMousePtrProperty();
1303     dumpImageSizeModeProperty();
1304     dumpSpecialEffectProperty< sal_uInt8 >( 0 );
1305     dumpSizeProperty();
1306     dumpStreamProperty();
1307     dumpImageAlignProperty();
1308     dumpBoolProperty();
1309     dumpFlagsProperty( 0x0000001B );
1310     dumpStreamProperty();
1311 }
1312 
AxScrollBarObject(const InputObjectBase & rParent)1313 AxScrollBarObject::AxScrollBarObject( const InputObjectBase& rParent )
1314 {
1315     AxPropertyObjectBase::construct( rParent, "AX-SCROLLBAR-PROPERTIES" );
1316 }
1317 
implDumpShortProperties()1318 void AxScrollBarObject::implDumpShortProperties()
1319 {
1320     dumpColorProperty( 0x80000012 );
1321     dumpColorProperty( 0x8000000F );
1322     dumpFlagsProperty( 0x0000001B );
1323     dumpSizeProperty();
1324     dumpMousePtrProperty();
1325     dumpDecProperty< sal_Int32 >( 0 );
1326     dumpDecProperty< sal_Int32 >( 32767 );
1327     dumpDecProperty< sal_Int32 >( 0 );
1328     dumpHexProperty< sal_uInt32 >( 0 );
1329     dumpEnabledProperty();
1330     dumpEnabledProperty();
1331     dumpDecProperty< sal_Int32 >( 1 );
1332     dumpDecProperty< sal_Int32 >( 1 );
1333     dumpOrientationProperty();
1334     dumpDecProperty< sal_Int16 >( -1, "AX-SCROLLBAR-PROPTHUMB" );
1335     dumpDelayProperty();
1336     dumpStreamProperty();
1337 }
1338 
AxSpinButtonObject(const InputObjectBase & rParent)1339 AxSpinButtonObject::AxSpinButtonObject( const InputObjectBase& rParent )
1340 {
1341     AxPropertyObjectBase::construct( rParent, "AX-SPINBUTTON-PROPERTIES" );
1342 }
1343 
implDumpShortProperties()1344 void AxSpinButtonObject::implDumpShortProperties()
1345 {
1346     dumpColorProperty( 0x80000012 );
1347     dumpColorProperty( 0x8000000F );
1348     dumpFlagsProperty( 0x0000001B );
1349     dumpSizeProperty();
1350     dumpHexProperty< sal_uInt32 >( 0 );
1351     dumpDecProperty< sal_Int32 >( 0 );
1352     dumpDecProperty< sal_Int32 >( 100 );
1353     dumpDecProperty< sal_Int32 >( 0 );
1354     dumpEnabledProperty();
1355     dumpEnabledProperty();
1356     dumpDecProperty< sal_Int32 >( 1 );
1357     dumpOrientationProperty();
1358     dumpDelayProperty();
1359     dumpStreamProperty();
1360     dumpMousePtrProperty();
1361 }
1362 
AxTabStripObject(const InputObjectBase & rParent)1363 AxTabStripObject::AxTabStripObject( const InputObjectBase& rParent )
1364 {
1365     AxPropertyObjectBase::construct( rParent, "AX-TABSTRIP-PROPERTIES" );
1366 }
1367 
implDumpShortProperties()1368 void AxTabStripObject::implDumpShortProperties()
1369 {
1370     dumpDecProperty< sal_Int32 >( -1 );
1371     dumpColorProperty( 0x8000000F );
1372     dumpColorProperty( 0x80000012 );
1373     dumpUnknownProperty();
1374     dumpSizeProperty();
1375     dumpStringArrayProperty();
1376     dumpMousePtrProperty();
1377     dumpUnknownProperty();
1378     dumpDecProperty< sal_uInt32 >( 0, "AX-TABSTRIP-ORIENTATION" );
1379     dumpDecProperty< sal_uInt32 >( 0, "AX-TABSTRIP-TABSTYLE" );
1380     dumpBoolProperty();
1381     dumpHmmProperty();
1382     dumpHmmProperty();
1383     dumpBoolProperty();
1384     dumpUnknownProperty();
1385     dumpStringArrayProperty();
1386     dumpUnknownProperty();
1387     dumpStringArrayProperty();
1388     dumpFlagsProperty( 0x0000001B );
1389     dumpBoolProperty();
1390     dumpDecProperty< sal_uInt32 >( 0 );
1391     dumpStringArrayProperty();
1392     mnTabFlagCount = dumpDecProperty< sal_Int32 >( 0 );
1393     dumpStringArrayProperty();
1394     dumpStreamProperty();
1395 }
1396 
implDumpExtended()1397 void AxTabStripObject::implDumpExtended()
1398 {
1399     dumpEmbeddedFont();
1400     if( mnTabFlagCount > 0 )
1401     {
1402         writeEmptyItem( "tab-flags" );
1403         IndentGuard aIndGuard( mxOut );
1404         mxOut->resetItemIndex();
1405         for( sal_Int32 nIdx = 0; ensureValid() && (nIdx < mnTabFlagCount); ++nIdx )
1406             dumpHex< sal_uInt32 >( "#flags", "AX-TABSTRIP-FLAGS" );
1407     }
1408 }
1409 
FormControlStreamObject(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName,const OUString * pProgId)1410 FormControlStreamObject::FormControlStreamObject( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName, const OUString* pProgId )
1411 {
1412     construct( rParent, rxStrm, rSysFileName );
1413     constructFormCtrlStrmObj( pProgId );
1414 }
1415 
FormControlStreamObject(const OutputObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString * pProgId)1416 FormControlStreamObject::FormControlStreamObject( const OutputObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString* pProgId )
1417 {
1418     construct( rParent, rxStrm );
1419     constructFormCtrlStrmObj( pProgId );
1420 }
1421 
implDump()1422 void FormControlStreamObject::implDump()
1423 {
1424     if( mbReadGuid )
1425         maProgId = cfg().getStringOption( dumpGuid(), OUString() );
1426 
1427     if( !maProgId.isEmpty() && !mxStrm->isEof() )
1428     {
1429         if ( maProgId == "Forms.CommandButton.1" )
1430             AxCommandButtonObject( *this ).dump();
1431         else if( maProgId ==  "Forms.TextBox.1" ||
1432                  maProgId ==  "Forms.ListBox.1" ||
1433                  maProgId ==  "Forms.ComboBox.1" ||
1434                  maProgId ==  "Forms.CheckBox.1" ||
1435                  maProgId ==  "Forms.OptionButton.1" ||
1436                  maProgId ==  "Forms.ToggleButton.1" ||
1437                  maProgId ==  "RefEdit.Ctrl" )
1438             AxMorphControlObject( *this ).dump();
1439         else if ( maProgId == "Forms.Label.1" )
1440             AxLabelObject( *this ).dump();
1441         else if ( maProgId == "Forms.Image.1" )
1442             AxImageObject( *this ).dump();
1443         else if ( maProgId == "Forms.ScrollBar.1" )
1444             AxScrollBarObject( *this ).dump();
1445         else if ( maProgId == "Forms.SpinButton.1" )
1446             AxSpinButtonObject( *this ).dump();
1447         else if ( maProgId == "Forms.TabStrip.1" )
1448             AxTabStripObject( *this ).dump();
1449         else if ( maProgId == "MSComCtl2.FlatScrollBar.2" )
1450             ComCtlScrollBarObject( *this, 6 ).dump();
1451         else if ( maProgId == "COMCTL.ProgCtrl.1" )
1452             ComCtlProgressBarObject( *this, 5 ).dump();
1453         else if ( maProgId == "MSComctlLib.ProgCtrl.2" )
1454             ComCtlProgressBarObject( *this, 6 ).dump();
1455         else if ( maProgId == "COMCTL.Slider.1" )
1456             ComCtlSliderObject( *this, 5 ).dump();
1457         else if ( maProgId == "MSComctlLib.Slider.2" )
1458             ComCtlSliderObject( *this, 6 ).dump();
1459         else if ( maProgId == "ComCtl2.UpDown.1" )
1460             ComCtlUpDownObject( *this, 5 ).dump();
1461         else if ( maProgId == "MSComCtl2.UpDown.2" )
1462             ComCtlUpDownObject( *this, 6 ).dump();
1463         else if ( maProgId == "COMCTL.ImageListCtrl.1" )
1464             ComCtlImageListObject( *this, 5 ).dump();
1465         else if ( maProgId == "MSComctlLib.ImageListCtrl.2" )
1466             ComCtlImageListObject( *this, 6 ).dump();
1467         else if ( maProgId == "COMCTL.TabStrip.1" )
1468             ComCtlTabStripObject( *this, 5 ).dump();
1469         else if ( maProgId == "MSComctlLib.TabStrip.2" )
1470             ComCtlTabStripObject( *this, 6 ).dump();
1471         else if ( maProgId == "COMCTL.TreeCtrl.1" )
1472             ComCtlTreeViewObject( *this, 5 ).dump();
1473         else if ( maProgId == "MSComctlLib.TreeCtrl.2" )
1474             ComCtlTreeViewObject( *this, 6 ).dump();
1475         else if ( maProgId == "COMCTL.SBarCtrl.1" )
1476             ComCtlStatusBarObject( *this, 5 ).dump();
1477         else if ( maProgId == "StdPic" )
1478             StdPicObject( *this ).dump();
1479     }
1480     dumpRemainingStream();
1481 }
1482 
constructFormCtrlStrmObj(const OUString * pProgId)1483 void FormControlStreamObject::constructFormCtrlStrmObj( const OUString* pProgId )
1484 {
1485     mbReadGuid = pProgId == nullptr;
1486     if( pProgId )
1487         maProgId = *pProgId;
1488 }
1489 
VbaFormClassInfoObject(const InputObjectBase & rParent,VbaFormSharedData & rFormData)1490 VbaFormClassInfoObject::VbaFormClassInfoObject( const InputObjectBase& rParent, VbaFormSharedData& rFormData ) :
1491     mrFormData( rFormData )
1492 {
1493     AxPropertyObjectBase::construct( rParent, "VBA-CLASSINFO-PROPERTIES" );
1494 }
1495 
implDumpShortProperties()1496 void VbaFormClassInfoObject::implDumpShortProperties()
1497 {
1498     mrFormData.maClassInfoProgIds.emplace_back( );
1499     dumpGuidProperty( &mrFormData.maClassInfoProgIds.back() );
1500     dumpGuidProperty();
1501     dumpUnknownProperty();
1502     dumpGuidProperty();
1503     dumpFlagsProperty( 0, "VBA-CLASSINFO-FLAGS" );
1504     dumpDecProperty< sal_uInt32 >( 0 );
1505     dumpDecProperty< sal_Int32 >( -1 );
1506     dumpDecProperty< sal_uInt16 >( 0 );
1507     dumpDecProperty< sal_uInt16 >( 0 );
1508     dumpDecProperty< sal_uInt16 >( 0, "OLEPROP-TYPE" );
1509     dumpDecProperty< sal_uInt16 >( 0 );
1510     dumpDecProperty< sal_uInt16 >( 0 );
1511     dumpDecProperty< sal_uInt16 >( 0, "OLEPROP-TYPE" );
1512     dumpDecProperty< sal_Int32 >( -1 );
1513     dumpDecProperty< sal_uInt16 >( 0 );
1514 }
1515 
1516 namespace {
1517 
1518 const sal_uInt32 VBA_FORMSITE_OBJSTREAM         = 0x0010;
1519 
1520 const sal_uInt16 VBA_FORMSITE_CLASSTABLEINDEX   = 0x8000;
1521 const sal_uInt16 VBA_FORMSITE_CLASSTABLEMASK    = 0x7FFF;
1522 
1523 } // namespace
1524 
VbaFormSiteObject(const InputObjectBase & rParent,VbaFormSharedData & rFormData)1525 VbaFormSiteObject::VbaFormSiteObject( const InputObjectBase& rParent, VbaFormSharedData& rFormData ) :
1526     mrFormData( rFormData )
1527 {
1528     AxPropertyObjectBase::construct( rParent, "VBA-FORMSITE-PROPERTIES" );
1529 }
1530 
implDumpShortProperties()1531 void VbaFormSiteObject::implDumpShortProperties()
1532 {
1533     VbaFormSiteInfo aSiteInfo;
1534     dumpStringProperty();
1535     dumpStringProperty();
1536     sal_Int32 nId = dumpDecProperty< sal_Int32 >( 0 );
1537     dumpDecProperty< sal_Int32 >( 0 );
1538     sal_uInt32 nFlags = dumpFlagsProperty( 0x00000033, "VBA-FORMSITE-FLAGS" );
1539     sal_uInt32 nLength = dumpDecProperty< sal_uInt32 >( 0 );
1540     dumpDecProperty< sal_Int16 >( -1 );
1541     sal_uInt16 nClassId = dumpHexProperty< sal_uInt16 >( 0x7FFF, "VBA-FORMSITE-CLASSIDCACHE" );
1542     dumpPosProperty();
1543     dumpDecProperty< sal_uInt16 >( 0 );
1544     dumpUnknownProperty();
1545     dumpStringProperty();
1546     dumpStringProperty();
1547     dumpStringProperty();
1548     dumpStringProperty();
1549 
1550     sal_uInt16 nIndex = nClassId & VBA_FORMSITE_CLASSTABLEMASK;
1551     if( getFlag( nClassId, VBA_FORMSITE_CLASSTABLEINDEX ) )
1552     {
1553         if( nIndex < mrFormData.maClassInfoProgIds.size() )
1554             aSiteInfo.maProgId = mrFormData.maClassInfoProgIds[ nIndex ];
1555     }
1556     else
1557     {
1558         if( cfg().hasName( "VBA-FORMSITE-CLASSNAMES", nIndex ) )
1559             aSiteInfo.maProgId = cfg().getName( "VBA-FORMSITE-CLASSNAMES", nIndex );
1560     }
1561     aSiteInfo.mnId = nId;
1562     aSiteInfo.mnLength = nLength;
1563     aSiteInfo.mbInStream = getFlag( nFlags, VBA_FORMSITE_OBJSTREAM );
1564 
1565     mrFormData.maSiteInfos.push_back( aSiteInfo );
1566 }
1567 
VbaFormDesignExtObject(const InputObjectBase & rParent)1568 VbaFormDesignExtObject::VbaFormDesignExtObject( const InputObjectBase& rParent )
1569 {
1570     AxPropertyObjectBase::construct( rParent, "VBA-FORMDESIGNEXT-PROPERTIES" );
1571 }
1572 
implDumpShortProperties()1573 void VbaFormDesignExtObject::implDumpShortProperties()
1574 {
1575     dumpFlagsProperty( 0x00015F55, "VBA-FORMDESIGNEXT-FLAGS" );
1576     dumpHmmProperty();
1577     dumpHmmProperty();
1578     dumpDecProperty< sal_Int8 >( 0, "VBA-FORMDESIGNEXT-CLICKCTRLMODE" );
1579     dumpDecProperty< sal_Int8 >( 0, "VBA-FORMDESIGNEXT-DBLCLICKCTRLMODE" );
1580 }
1581 
1582 namespace {
1583 
1584 const sal_uInt32 AX_FORM_HASDESIGNEXTENDER      = 0x00004000;
1585 const sal_uInt32 AX_FORM_SKIPCLASSTABLE         = 0x00008000;
1586 
1587 const sal_uInt8 AX_FORM_SITECOUNTTYPE_COUNT     = 0x80;
1588 const sal_uInt8 AX_FORM_SITECOUNTTYPE_MASK      = 0x7F;
1589 
1590 } // namespace
1591 
VbaFStreamObject(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName,VbaFormSharedData & rFormData)1592 VbaFStreamObject::VbaFStreamObject( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName, VbaFormSharedData& rFormData ) :
1593     mrFormData( rFormData )
1594 {
1595     AxPropertyObjectBase::construct( rParent, rxStrm, rSysFileName, "VBA-FORM-PROPERTIES" );
1596 }
1597 
implDumpShortProperties()1598 void VbaFStreamObject::implDumpShortProperties()
1599 {
1600     dumpUnknownProperty();
1601     dumpColorProperty( 0x8000000F );
1602     dumpColorProperty( 0x80000012 );
1603     dumpDecProperty< sal_uInt32 >( 0 );
1604     dumpUnknownProperty();
1605     dumpUnknownProperty();
1606     mnFlags = dumpFlagsProperty( 0x00000004, "VBA-FORM-FLAGS" );
1607     dumpBorderStyleProperty< sal_uInt8 >( 0 );
1608     dumpMousePtrProperty();
1609     dumpHexProperty< sal_uInt8 >( 0x0C, "VBA-FORM-SCROLLBARS" );
1610     dumpSizeProperty();
1611     dumpSizeProperty();
1612     dumpPosProperty();
1613     dumpDecProperty< sal_uInt32 >( 0 );
1614     dumpUnknownProperty();
1615     dumpStreamProperty();
1616     dumpDecProperty< sal_uInt8 >( 0, "VBA-FORM-CYCLE" );
1617     dumpSpecialEffectProperty< sal_uInt8 >( 0 );
1618     dumpColorProperty( 0x80000012 );
1619     dumpStringProperty();
1620     dumpStreamProperty();
1621     dumpStreamProperty();
1622     dumpDecProperty< sal_Int32 >( 100, "CONV-PERCENT" );
1623     dumpImageAlignProperty();
1624     dumpBoolProperty();
1625     dumpImageSizeModeProperty();
1626     dumpDecProperty< sal_uInt32 >( 0 );
1627     dumpDecProperty< sal_uInt32 >( 0 );
1628 }
1629 
implDumpExtended()1630 void VbaFStreamObject::implDumpExtended()
1631 {
1632     dumpClassInfos();
1633     dumpSiteData();
1634     dumpDesignExtender();
1635     dumpRemainingStream();
1636 }
1637 
dumpClassInfos()1638 void VbaFStreamObject::dumpClassInfos()
1639 {
1640     if( ensureValid() && !getFlag( mnFlags, AX_FORM_SKIPCLASSTABLE ) )
1641     {
1642         mxOut->emptyLine();
1643         sal_uInt16 nCount = dumpDec< sal_uInt16 >( "class-info-count" );
1644         mxOut->resetItemIndex();
1645         for( sal_uInt16 nIdx = 0; ensureValid() && (nIdx < nCount); ++nIdx )
1646         {
1647             writeEmptyItem( "#class-info" );
1648             IndentGuard aIndGuard( mxOut );
1649             VbaFormClassInfoObject( *this, mrFormData ).dump();
1650         }
1651     }
1652 }
1653 
dumpFormSites(sal_uInt32 nCount)1654 void VbaFStreamObject::dumpFormSites( sal_uInt32 nCount )
1655 {
1656     mxOut->resetItemIndex();
1657     for( sal_uInt32 nIdx = 0; ensureValid() && (nIdx < nCount); ++nIdx )
1658     {
1659         mxOut->emptyLine();
1660         writeEmptyItem( "#form-site" );
1661         IndentGuard aIndGuard( mxOut );
1662         VbaFormSiteObject( *this, mrFormData ).dump();
1663     }
1664 }
1665 
dumpSiteData()1666 void VbaFStreamObject::dumpSiteData()
1667 {
1668     if( !ensureValid() )
1669         return;
1670 
1671     mxOut->emptyLine();
1672     setAlignAnchor();
1673     sal_uInt32 nSiteCount = dumpDec< sal_uInt32 >( "site-count" );
1674     sal_uInt32 nSiteLength = dumpDec< sal_uInt32 >( "site-data-size" );
1675     sal_Int64 nEndPos = mxStrm->tell() + nSiteLength;
1676     if( !ensureValid( nEndPos <= mxStrm->size() ) )
1677         return;
1678 
1679     mxOut->resetItemIndex();
1680     sal_uInt32 nSiteIdx = 0;
1681     while( ensureValid() && (nSiteIdx < nSiteCount) )
1682     {
1683         mxOut->emptyLine();
1684         writeEmptyItem( "#site-info" );
1685         IndentGuard aIndGuard( mxOut );
1686         dumpDec< sal_uInt8 >( "depth" );
1687         sal_uInt8 nTypeCount = dumpHex< sal_uInt8 >( "type-count", "VBA-FORM-SITE-TYPECOUNT" );
1688         if( getFlag( nTypeCount, AX_FORM_SITECOUNTTYPE_COUNT ) )
1689         {
1690             dumpDec< sal_uInt8 >( "repeated-type" );
1691             nSiteIdx += (nTypeCount & AX_FORM_SITECOUNTTYPE_MASK);
1692         }
1693         else
1694         {
1695             ++nSiteIdx;
1696         }
1697     }
1698     alignInput< sal_uInt32 >();
1699     dumpFormSites( nSiteCount );
1700     dumpToPosition( nEndPos );
1701 }
1702 
dumpDesignExtender()1703 void VbaFStreamObject::dumpDesignExtender()
1704 {
1705     if( ensureValid() && getFlag( mnFlags, AX_FORM_HASDESIGNEXTENDER ) )
1706     {
1707         mxOut->emptyLine();
1708         writeEmptyItem( "design-extender" );
1709         IndentGuard aIndGuard( mxOut );
1710         VbaFormDesignExtObject( *this ).dump();
1711     }
1712 }
1713 
VbaOStreamObject(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName,VbaFormSharedData & rFormData)1714 VbaOStreamObject::VbaOStreamObject( const ObjectBase& rParent,
1715         const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName, VbaFormSharedData& rFormData ) :
1716     mrFormData( rFormData )
1717 {
1718     OleInputObjectBase::construct( rParent, rxStrm, rSysFileName );
1719 }
1720 
implDump()1721 void VbaOStreamObject::implDump()
1722 {
1723     for (auto const& siteInfo : mrFormData.maSiteInfos)
1724     {
1725         if (mxStrm->isEof())
1726             break;
1727         if( (siteInfo.mbInStream) && (siteInfo.mnLength > 0) )
1728         {
1729             mxOut->emptyLine();
1730             writeDecItem( "control-id", siteInfo.mnId );
1731             writeInfoItem( "prog-id", siteInfo.maProgId );
1732             IndentGuard aIndGuard( mxOut );
1733             BinaryInputStreamRef xRelStrm( std::make_shared<RelativeInputStream>( *mxStrm, siteInfo.mnLength ) );
1734             FormControlStreamObject( *this, xRelStrm, &siteInfo.maProgId ).dump();
1735         }
1736     }
1737     dumpRemainingStream();
1738 }
1739 
VbaPageObject(const InputObjectBase & rParent)1740 VbaPageObject::VbaPageObject( const InputObjectBase& rParent )
1741 {
1742     AxPropertyObjectBase::construct( rParent, "VBA-PAGE-PROPERTIES" );
1743 }
1744 
implDumpShortProperties()1745 void VbaPageObject::implDumpShortProperties()
1746 {
1747     dumpUnknownProperty();
1748     dumpDecProperty< sal_uInt32 >( 0, "VBA-PAGE-TRANSITIONEFFECT" );
1749     dumpDecProperty< sal_uInt32 >( 0, "AX-CONV-MS" );
1750 }
1751 
VbaMultiPageObject(const InputObjectBase & rParent)1752 VbaMultiPageObject::VbaMultiPageObject( const InputObjectBase& rParent )
1753 {
1754     AxPropertyObjectBase::construct( rParent, "VBA-MULTIPAGE-PROPERTIES" );
1755 }
1756 
implDumpShortProperties()1757 void VbaMultiPageObject::implDumpShortProperties()
1758 {
1759     dumpUnknownProperty();
1760     mnPageCount = dumpDecProperty< sal_Int32 >( 0 );
1761     dumpDecProperty< sal_Int32 >( 0 );
1762     dumpBoolProperty();
1763 }
1764 
implDumpExtended()1765 void VbaMultiPageObject::implDumpExtended()
1766 {
1767     if( ensureValid() && (mnPageCount > 0) )
1768     {
1769         writeEmptyItem( "page-ids" );
1770         IndentGuard aIndGuard( mxOut );
1771         mxOut->resetItemIndex();
1772         for( sal_Int32 nIdx = 0; ensureValid() && (nIdx < mnPageCount); ++nIdx )
1773             dumpDec< sal_Int32 >( "#id" );
1774     }
1775 }
1776 
VbaXStreamObject(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName,VbaFormSharedData & rFormData)1777 VbaXStreamObject::VbaXStreamObject( const ObjectBase& rParent,
1778         const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName, VbaFormSharedData& rFormData ) :
1779     mrFormData( rFormData )
1780 {
1781     InputObjectBase::construct( rParent, rxStrm,  rSysFileName );
1782 }
1783 
implDump()1784 void VbaXStreamObject::implDump()
1785 {
1786     for( size_t nIdx = 0, nCount = mrFormData.maSiteInfos.size(); !mxStrm->isEof() && (nIdx < nCount); ++nIdx )
1787     {
1788         mxOut->emptyLine();
1789         writeEmptyItem( "page" );
1790         IndentGuard aIndGuard( mxOut );
1791         VbaPageObject( *this ).dump();
1792     }
1793     if( !mxStrm->isEof() )
1794     {
1795         mxOut->emptyLine();
1796         writeEmptyItem( "multi-page" );
1797         IndentGuard aIndGuard( mxOut );
1798         VbaMultiPageObject( *this ).dump();
1799     }
1800     dumpRemainingStream();
1801 }
1802 
VbaContainerStorageObject(const ObjectBase & rParent,const StorageRef & rxStrg,const OUString & rSysPath)1803 VbaContainerStorageObject::VbaContainerStorageObject( const ObjectBase& rParent, const StorageRef& rxStrg, const OUString& rSysPath ) :
1804     OleStorageObject( rParent, rxStrg, rSysPath )
1805 {
1806     addPreferredStream( "f" );
1807 }
1808 
implDumpStream(const Reference<XInputStream> & rxStrm,const OUString & rStrgPath,const OUString & rStrmName,const OUString & rSysFileName)1809 void VbaContainerStorageObject::implDumpStream( const Reference< XInputStream >& rxStrm, const OUString& rStrgPath, const OUString& rStrmName, const OUString& rSysFileName )
1810 {
1811     if ( rStrmName == "f" )
1812         VbaFStreamObject( *this, rxStrm, rSysFileName, maFormData ).dump();
1813     else if ( rStrmName == "o" )
1814         VbaOStreamObject( *this, rxStrm, rSysFileName, maFormData ).dump();
1815     else if ( rStrmName == "x" )
1816         VbaXStreamObject( *this, rxStrm, rSysFileName, maFormData ).dump();
1817     else
1818         OleStorageObject::implDumpStream( rxStrm, rStrgPath, rStrmName, rSysFileName );
1819 }
1820 
implDumpStorage(const StorageRef & rxStrg,const OUString & rStrgPath,const OUString & rSysPath)1821 void VbaContainerStorageObject::implDumpStorage( const StorageRef& rxStrg, const OUString& rStrgPath, const OUString& rSysPath )
1822 {
1823     if( isFormStorage( rStrgPath ) )
1824         VbaContainerStorageObject( *this, rxStrg, rSysPath ).dump();
1825     else
1826         OleStorageObject( *this, rxStrg, rSysPath ).dump();
1827 }
1828 
isFormStorage(const OUString & rStrgPath) const1829 bool VbaContainerStorageObject::isFormStorage( const OUString& rStrgPath ) const
1830 {
1831     if( (rStrgPath.getLength() >= 3) && (rStrgPath[ 0 ] == 'i') )
1832     {
1833         OUString aId = rStrgPath.copy( 1 );
1834         if( (aId.getLength() == 2) && (aId[ 0 ] == '0') )
1835             aId = aId.copy( 1 );
1836         sal_Int32 nId = aId.toInt32();
1837         if( (nId > 0) && (std::u16string_view(OUString::number( nId )) == aId) )
1838             for (auto const& siteInfo : maFormData.maSiteInfos)
1839                 if( siteInfo.mnId == nId )
1840                     return true;
1841     }
1842     return false;
1843 }
1844 
VbaSharedData()1845 VbaSharedData::VbaSharedData() :
1846     meTextEnc( RTL_TEXTENCODING_MS_1252 )
1847 {
1848 }
1849 
isModuleStream(const OUString & rStrmName) const1850 bool VbaSharedData::isModuleStream( const OUString& rStrmName ) const
1851 {
1852     return maStrmOffsets.count( rStrmName ) > 0;
1853 }
1854 
getStreamOffset(const OUString & rStrmName) const1855 sal_Int32 VbaSharedData::getStreamOffset( const OUString& rStrmName ) const
1856 {
1857     StreamOffsetMap::const_iterator aIt = maStrmOffsets.find( rStrmName );
1858     return (aIt == maStrmOffsets.end()) ? 0 : aIt->second;
1859 }
1860 
VbaDirStreamObject(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName,VbaSharedData & rVbaData)1861 VbaDirStreamObject::VbaDirStreamObject( const ObjectBase& rParent,
1862         const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName, VbaSharedData& rVbaData ) :
1863     mrVbaData( rVbaData )
1864 {
1865     mxInStrm = rxStrm;
1866     if( mxInStrm )
1867     {
1868         BinaryInputStreamRef xVbaStrm( std::make_shared<::oox::ole::VbaInputStream>( *mxInStrm ) );
1869         SequenceRecordObjectBase::construct( rParent, xVbaStrm, rSysFileName, "VBA-DIR-RECORD-NAMES", "VBA-DIR-SIMPLE-RECORDS" );
1870     }
1871 }
1872 
implIsValid() const1873 bool VbaDirStreamObject::implIsValid() const
1874 {
1875     return mxInStrm && SequenceRecordObjectBase::implIsValid();
1876 }
1877 
implReadRecordHeader(BinaryInputStream & rBaseStrm,sal_Int64 & ornRecId,sal_Int64 & ornRecSize)1878 bool VbaDirStreamObject::implReadRecordHeader( BinaryInputStream& rBaseStrm, sal_Int64& ornRecId, sal_Int64& ornRecSize )
1879 {
1880     ornRecId = rBaseStrm.readuInt16();
1881     ornRecSize = rBaseStrm.readInt32();
1882 
1883     // for no obvious reason, PROJECTVERSION record contains size field of 4, but is 6 bytes long
1884     if( ornRecId == 9 )
1885         ornRecSize = 6;
1886 
1887     return !rBaseStrm.isEof();
1888 }
1889 
implDumpRecordBody()1890 void VbaDirStreamObject::implDumpRecordBody()
1891 {
1892     switch( getRecId() )
1893     {
1894         case 0x0003:
1895             mrVbaData.meTextEnc = rtl_getTextEncodingFromWindowsCodePage( dumpDec< sal_uInt16 >( "codepage", "CODEPAGES" ) );
1896         break;
1897         case 0x0004:
1898             dumpByteString( "name" );
1899         break;
1900         case 0x0005:
1901             dumpByteString( "description" );
1902         break;
1903         case 0x0006:
1904             dumpByteString( "helpfile-path" );
1905         break;
1906         case 0x0009:
1907             dumpDec< sal_uInt32 >( "major" );
1908             dumpDec< sal_uInt16 >( "minor" );
1909         break;
1910         case 0x000C:
1911             dumpByteString( "constants" );
1912         break;
1913         case 0x000D:
1914             dumpByteStringWithLength( "lib-id" );
1915             dumpUnused( 6 );
1916         break;
1917         case 0x000E:
1918             dumpByteStringWithLength( "lib-id-absolute" );
1919             dumpByteStringWithLength( "lib-id-relative" );
1920             dumpDec< sal_uInt32 >( "major" );
1921             dumpDec< sal_uInt16 >( "minor" );
1922         break;
1923         case 0x0016:
1924             dumpByteString( "name" );
1925         break;
1926         case 0x0019:
1927             dumpByteString( "name" );
1928             maCurrStream.clear();
1929             mnCurrOffset = 0;
1930         break;
1931         case 0x001A:
1932             maCurrStream = dumpByteString( "stream-name" );
1933         break;
1934         case 0x001C:
1935             dumpByteString( "description" );
1936         break;
1937         case 0x002B:
1938             if( !maCurrStream.isEmpty() )
1939                 mrVbaData.maStrmOffsets[ maCurrStream ] = mnCurrOffset;
1940             maCurrStream.clear();
1941             mnCurrOffset = 0;
1942         break;
1943         case 0x002F:
1944             dumpByteStringWithLength( "lib-id-twiddled" );
1945             dumpUnused( 6 );
1946         break;
1947         case 0x0030:
1948             dumpByteStringWithLength( "lib-id-extended" );
1949             dumpUnused( 6 );
1950             dumpGuid( "original-typelib" );
1951             dumpDec< sal_uInt32 >( "cookie" );
1952         break;
1953         case 0x0031:
1954             mnCurrOffset = dumpHex< sal_Int32 >( "stream-offset", "CONV-DEC" );
1955         break;
1956         case 0x0032:
1957             dumpUniString( "stream-name" );
1958         break;
1959         case 0x0033:
1960             dumpByteString( "lib-id-original" );
1961         break;
1962         case 0x003C:
1963             dumpUniString( "constants" );
1964         break;
1965         case 0x003D:
1966             dumpByteString( "helpfile-path" );
1967         break;
1968         case 0x003E:
1969             dumpUniString( "name" );
1970         break;
1971         case 0x0040:
1972             dumpUniString( "description" );
1973         break;
1974         case 0x0047:
1975             dumpUniString( "name" );
1976         break;
1977         case 0x0048:
1978             dumpUniString( "description" );
1979         break;
1980     }
1981 }
1982 
dumpByteString(const String & rName)1983 OUString VbaDirStreamObject::dumpByteString( const String& rName )
1984 {
1985     return dumpCharArray( rName, static_cast< sal_Int32 >( getRecSize() ), mrVbaData.meTextEnc );
1986 }
1987 
dumpUniString(const String & rName)1988 OUString VbaDirStreamObject::dumpUniString( const String& rName )
1989 {
1990     return dumpUnicodeArray( rName, static_cast< sal_Int32 >( getRecSize() / 2 ) );
1991 }
1992 
dumpByteStringWithLength(const String & rName)1993 OUString VbaDirStreamObject::dumpByteStringWithLength( const String& rName )
1994 {
1995     return dumpCharArray( rName, mxStrm->readInt32(), mrVbaData.meTextEnc );
1996 }
1997 
VbaModuleStreamObject(const ObjectBase & rParent,const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName,VbaSharedData & rVbaData,sal_Int32 nStrmOffset)1998 VbaModuleStreamObject::VbaModuleStreamObject(
1999         const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm,
2000         const OUString& rSysFileName, VbaSharedData& rVbaData, sal_Int32 nStrmOffset ) :
2001     mrVbaData( rVbaData ),
2002     mnStrmOffset( nStrmOffset )
2003 {
2004     InputObjectBase::construct( rParent, rxStrm, rSysFileName );
2005 }
2006 
implDump()2007 void VbaModuleStreamObject::implDump()
2008 {
2009     dumpBinary( "perf-cache", mnStrmOffset );
2010     mxOut->emptyLine();
2011     writeEmptyItem( "source-code" );
2012     IndentGuard aIndGuard( mxOut );
2013     BinaryInputStreamRef xVbaStrm( std::make_shared<::oox::ole::VbaInputStream>( *mxStrm ) );
2014     TextLineStreamObject( *this, xVbaStrm, mrVbaData.meTextEnc ).dump();
2015 }
2016 
VbaStorageObject(const ObjectBase & rParent,const StorageRef & rxStrg,const OUString & rSysPath,VbaSharedData & rVbaData)2017 VbaStorageObject::VbaStorageObject( const ObjectBase& rParent, const StorageRef& rxStrg, const OUString& rSysPath, VbaSharedData& rVbaData ) :
2018     OleStorageObject( rParent, rxStrg, rSysPath ),
2019     mrVbaData( rVbaData )
2020 {
2021     addPreferredStream( "dir" );
2022 }
2023 
implDumpStream(const Reference<XInputStream> & rxStrm,const OUString & rStrgPath,const OUString & rStrmName,const OUString & rSysFileName)2024 void VbaStorageObject::implDumpStream( const Reference< XInputStream >& rxStrm, const OUString& rStrgPath, const OUString& rStrmName, const OUString& rSysFileName )
2025 {
2026     if( rStrgPath.isEmpty() && rStrmName == "dir" )
2027         VbaDirStreamObject( *this, rxStrm, rSysFileName, mrVbaData ).dump();
2028     else if( mrVbaData.isModuleStream( rStrmName ) )
2029         VbaModuleStreamObject( *this, rxStrm, rSysFileName, mrVbaData, mrVbaData.getStreamOffset( rStrmName ) ).dump();
2030     else
2031         OleStorageObject::implDumpStream( rxStrm, rStrgPath, rStrmName, rSysFileName );
2032 }
2033 
VbaFormStorageObject(const ObjectBase & rParent,const StorageRef & rxStrg,const OUString & rSysPath,VbaSharedData & rVbaData)2034 VbaFormStorageObject::VbaFormStorageObject( const ObjectBase& rParent, const StorageRef& rxStrg, const OUString& rSysPath, VbaSharedData& rVbaData ) :
2035     VbaContainerStorageObject( rParent, rxStrg, rSysPath ),
2036     mrVbaData( rVbaData )
2037 {
2038 }
2039 
implDumpStream(const Reference<XInputStream> & rxStrm,const OUString & rStrgPath,const OUString & rStrmName,const OUString & rSysFileName)2040 void VbaFormStorageObject::implDumpStream( const Reference< XInputStream >& rxStrm, const OUString& rStrgPath, const OUString& rStrmName, const OUString& rSysFileName )
2041 {
2042     if ( rStrmName == "\003VBFrame" )
2043         TextLineStreamObject( *this, rxStrm, mrVbaData.meTextEnc, rSysFileName ).dump();
2044     else
2045         VbaContainerStorageObject::implDumpStream( rxStrm, rStrgPath, rStrmName, rSysFileName );
2046 }
2047 
VbaProjectStorageObject(const ObjectBase & rParent,const StorageRef & rxStrg,const OUString & rSysPath)2048 VbaProjectStorageObject::VbaProjectStorageObject( const ObjectBase& rParent, const StorageRef& rxStrg, const OUString& rSysPath ) :
2049     OleStorageObject( rParent, rxStrg, rSysPath )
2050 {
2051     addPreferredStorage( "VBA" );
2052 }
2053 
implDumpStream(const Reference<XInputStream> & rxStrm,const OUString & rStrgPath,const OUString & rStrmName,const OUString & rSysFileName)2054 void VbaProjectStorageObject::implDumpStream( const Reference< XInputStream >& rxStrm, const OUString& rStrgPath, const OUString& rStrmName, const OUString& rSysFileName )
2055 {
2056     if( rStrgPath.isEmpty() && rStrmName == "PROJECT" )
2057         TextLineStreamObject( *this, rxStrm, maVbaData.meTextEnc, rSysFileName ).dump();
2058     else
2059         OleStorageObject::implDumpStream( rxStrm, rStrgPath, rStrmName, rSysFileName );
2060 }
2061 
implDumpStorage(const StorageRef & rxStrg,const OUString & rStrgPath,const OUString & rSysPath)2062 void VbaProjectStorageObject::implDumpStorage( const StorageRef& rxStrg, const OUString& rStrgPath, const OUString& rSysPath )
2063 {
2064     if ( rStrgPath == "VBA" )
2065         VbaStorageObject( *this, rxStrg, rSysPath, maVbaData ).dump();
2066     else
2067         VbaFormStorageObject( *this, rxStrg, rSysPath, maVbaData ).dump();
2068 }
2069 
ActiveXStorageObject(const ObjectBase & rParent,const StorageRef & rxStrg,const OUString & rSysPath)2070 ActiveXStorageObject::ActiveXStorageObject( const ObjectBase& rParent, const StorageRef& rxStrg, const OUString& rSysPath ) :
2071     VbaContainerStorageObject( rParent, rxStrg, rSysPath )
2072 {
2073 }
2074 
implDumpBaseStream(const BinaryInputStreamRef & rxStrm,const OUString & rSysFileName)2075 void ActiveXStorageObject::implDumpBaseStream( const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName )
2076 {
2077     FormControlStreamObject( *this, rxStrm, rSysFileName ).dump();
2078 }
2079 
2080 } // namespace oox
2081 
2082 #endif
2083 
2084 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
2085