LibreOffice Module oox (master)  1
vbaexport.hxx
Go to the documentation of this file.
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 
10 #ifndef INCLUDED_OOX_OLE_VBAEXPORT_HXX
11 #define INCLUDED_OOX_OLE_VBAEXPORT_HXX
12 
13 #include <cstddef>
14 
15 #include <com/sun/star/uno/Reference.hxx>
16 #include <oox/dllapi.h>
17 #include <rtl/ustring.hxx>
18 #include <sal/types.h>
19 
20 class SotStorage;
21 class SvStream;
22 class SvMemoryStream;
23 
24 namespace com::sun::star {
25  namespace container { class XNameContainer; }
26  namespace frame { class XModel; }
27  namespace script { class XLibraryContainer; }
28 }
29 
31 {
32 public:
33  VbaExport(css::uno::Reference<css::frame::XModel> const & xModel);
34 
35  void exportVBA(SotStorage* pRootStorage);
36 
37  bool containsVBAProject();
38 
39 private:
40 
41  css::uno::Reference<css::container::XNameContainer>
42  getBasicLibrary() const;
43 
44  css::uno::Reference<css::script::XLibraryContainer>
45  getLibraryContainer() const;
46 
47  OUString getProjectName() const;
48 
49  css::uno::Reference<css::frame::XModel> mxModel;
50 };
51 
53 {
54 public:
55 
56  VBACompressionChunk(SvStream& rCompressedStream, const sal_uInt8* pData, std::size_t nChunkSize);
57 
58  void write();
59 
60 private:
64 
65  // same as DecompressedChunkEnd in the spec
66  std::size_t mnChunkSize;
67 
68  // CompressedCurrent according to the spec
69  sal_uInt64 mnCompressedCurrent;
70 
71  // CompressedEnd according to the spec
72  sal_uInt64 mnCompressedEnd;
73 
74  // DecompressedCurrent according to the spec
76 
77  // DecompressedEnd according to the spec
78  sal_uInt64 mnDecompressedEnd;
79 
80  static void PackCompressedChunkSize(size_t nSize, sal_uInt16& rHeader);
81 
82  static void PackCompressedChunkFlag(bool bCompressed, sal_uInt16& rHeader);
83 
84  static void PackCompressedChunkSignature(sal_uInt16& rHeader);
85 
86  void compressTokenSequence();
87 
88  void compressToken(size_t index, sal_uInt8& nFlagByte);
89 
90  static void SetFlagBit(size_t index, bool bVal, sal_uInt8& rFlag);
91 
92  sal_uInt16 CopyToken(size_t nLength, size_t nOffset);
93 
94  void match(size_t& rLength, size_t& rOffset);
95 
96  void CopyTokenHelp(sal_uInt16& rLengthMask, sal_uInt16& rOffsetMask,
97  sal_uInt16& rBitCount, sal_uInt16& rMaximumLength);
98 
99  void writeRawChunk();
100 
101  sal_uInt16 handleHeader(bool bCompressed);
102 };
103 
105 {
106 public:
107  VBACompression(SvStream& rCompressedStream,
108  SvMemoryStream& rUncompressedStream);
109 
110  void write();
111 
112 private:
115 };
116 
118 {
119 public:
121  const sal_uInt16 nLength,
122  SvStream& rEncryptedData,
123  sal_uInt8 nProjKey);
124 
125  void write();
126 
127  static sal_uInt8 calculateProjKey(const OUString& rString);
128 
129 private:
130  const sal_uInt8* mpData; // an array of bytes to be obfuscated
131  const sal_uInt16 mnLength; // the length of Data
132  SvStream& mrEncryptedData; // Encrypted Data Structure
133  sal_uInt8 mnUnencryptedByte1; // the last unencrypted byte read or written
134  sal_uInt8 mnEncryptedByte1; // the last encrypted byte read or written
135  sal_uInt8 mnEncryptedByte2; // the next-to-last encrypted byte read or written
136  sal_Unicode mnProjKey; // a project-specific encryption key
137  sal_uInt8 mnIgnoredLength; // the length in bytes of IgnoredEnc
138 
139  sal_uInt8 mnSeed; // the seed value
140  sal_uInt8 mnVersionEnc; // the version encoding
141 
142  void writeSeed();
143  void writeVersionEnc();
144  void writeProjKeyEnc();
145  void writeIgnoredEnc();
146  void writeDataLengthEnc();
147  void writeDataEnc();
148 };
149 
150 #endif
151 
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_uInt16 mnLength
Definition: vbaexport.hxx:131
void CopyTokenHelp(sal_uInt16 &rLengthMask, sal_uInt16 &rOffsetMask, sal_uInt16 &rBitCount, sal_uInt16 &rMaximumLength)
Definition: vbaexport.cxx:300
std::unique_ptr< ContentProperties > pData
static void PackCompressedChunkFlag(bool bCompressed, sal_uInt16 &rHeader)
Definition: vbaexport.cxx:168
sal_Int16 script
sal_Unicode mnProjKey
Definition: vbaexport.hxx:136
SvStream & mrCompressedStream
Definition: vbaexport.hxx:61
exports com.sun.star. container
sal_uInt16 sal_Unicode
sal_uInt8 mnUnencryptedByte1
Definition: vbaexport.hxx:133
std::size_t mnChunkSize
Definition: vbaexport.hxx:66
exports com.sun.star. frame
sal_uInt64 mnDecompressedEnd
Definition: vbaexport.hxx:78
const sal_uInt8 * mpUncompressedData
Definition: vbaexport.hxx:62
sal_uInt8 mnVersionEnc
Definition: vbaexport.hxx:140
css::uno::Reference< css::frame::XModel > mxModel
Definition: vbaexport.hxx:49
sal_uInt8 * mpCompressedChunkStream
Definition: vbaexport.hxx:63
sal_uInt8 mnIgnoredLength
Definition: vbaexport.hxx:137
SvStream & mrCompressedStream
Definition: vbaexport.hxx:113
SvStream & mrEncryptedData
Definition: vbaexport.hxx:132
static void PackCompressedChunkSignature(sal_uInt16 &rHeader)
Definition: vbaexport.cxx:176
static void SetFlagBit(size_t index, bool bVal, sal_uInt8 &rFlag)
Definition: vbaexport.cxx:236
sal_uInt64 mnCompressedEnd
Definition: vbaexport.hxx:72
void match(size_t &rLength, size_t &rOffset)
Definition: vbaexport.cxx:259
sal_uInt64 mnCompressedCurrent
Definition: vbaexport.hxx:69
sal_uInt8 mnEncryptedByte1
Definition: vbaexport.hxx:134
void compressTokenSequence()
Definition: vbaexport.cxx:183
unsigned char sal_uInt8
sal_uInt64 mnDecompressedCurrent
Definition: vbaexport.hxx:75
sal_uInt8 mnEncryptedByte2
Definition: vbaexport.hxx:135
const sal_uInt8 * mpData
Definition: vbaexport.hxx:130
SvMemoryStream & mrUncompressedStream
Definition: vbaexport.hxx:114
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
sal_uInt16 CopyToken(size_t nLength, size_t nOffset)
Definition: vbaexport.cxx:244
Reference< XModel > xModel
sal_Int32 nLength
sal_uInt8 mnSeed
Definition: vbaexport.hxx:139
sal_uInt16 handleHeader(bool bCompressed)
Definition: vbaexport.cxx:108
void compressToken(size_t index, sal_uInt8 &nFlagByte)
Definition: vbaexport.cxx:200
VBACompressionChunk(SvStream &rCompressedStream, const sal_uInt8 *pData, std::size_t nChunkSize)
Definition: vbaexport.cxx:90
static void PackCompressedChunkSize(size_t nSize, sal_uInt16 &rHeader)
Definition: vbaexport.cxx:160