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