Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / oox / ole / vbaexport.hxx
blob8d96c0e7a27787affb83ee41d15a89f9f8a6073f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #ifndef INCLUDED_OOX_OLE_VBAEXPORT_HXX
11 #define INCLUDED_OOX_OLE_VBAEXPORT_HXX
13 #include <cstddef>
15 #include <com/sun/star/uno/Reference.hxx>
16 #include <oox/dllapi.h>
17 #include <rtl/ustring.hxx>
18 #include <sal/types.h>
20 class SotStorage;
21 class SvStream;
22 class SvMemoryStream;
24 namespace com { namespace sun { namespace star {
25 namespace container { class XNameContainer; }
26 namespace frame { class XModel; }
27 namespace script { class XLibraryContainer; }
28 } } }
30 class OOX_DLLPUBLIC VbaExport
32 public:
33 VbaExport(css::uno::Reference<css::frame::XModel> const & xModel);
35 void exportVBA(SotStorage* pRootStorage);
37 bool containsVBAProject();
39 private:
41 css::uno::Reference<css::container::XNameContainer>
42 getBasicLibrary();
44 css::uno::Reference<css::script::XLibraryContainer>
45 getLibraryContainer();
47 OUString getProjectName();
49 css::uno::Reference<css::frame::XModel> mxModel;
52 class VBACompressionChunk
54 public:
56 VBACompressionChunk(SvStream& rCompressedStream, const sal_uInt8* pData, std::size_t nChunkSize);
58 void write();
60 private:
61 SvStream& mrCompressedStream;
62 const sal_uInt8* mpUncompressedData;
63 sal_uInt8* mpCompressedChunkStream;
65 // same as DecompressedChunkEnd in the spec
66 std::size_t mnChunkSize;
68 // CompressedCurrent according to the spec
69 sal_uInt64 mnCompressedCurrent;
71 // CompressedEnd according to the spec
72 sal_uInt64 mnCompressedEnd;
74 // DecompressedCurrent according to the spec
75 sal_uInt64 mnDecompressedCurrent;
77 // DecompressedEnd according to the spec
78 sal_uInt64 mnDecompressedEnd;
80 static void PackCompressedChunkSize(size_t nSize, sal_uInt16& rHeader);
82 static void PackCompressedChunkFlag(bool bCompressed, sal_uInt16& rHeader);
84 static void PackCompressedChunkSignature(sal_uInt16& rHeader);
86 void compressTokenSequence();
88 void compressToken(size_t index, sal_uInt8& nFlagByte);
90 static void SetFlagBit(size_t index, bool bVal, sal_uInt8& rFlag);
92 sal_uInt16 CopyToken(size_t nLength, size_t nOffset);
94 void match(size_t& rLength, size_t& rOffset);
96 void CopyTokenHelp(sal_uInt16& rLengthMask, sal_uInt16& rOffsetMask,
97 sal_uInt16& rBitCount, sal_uInt16& rMaximumLength);
99 void writeRawChunk();
101 sal_uInt16 handleHeader(bool bCompressed);
104 class OOX_DLLPUBLIC VBACompression
106 public:
107 VBACompression(SvStream& rCompressedStream,
108 SvMemoryStream& rUncompressedStream);
110 void write();
112 private:
113 SvStream& mrCompressedStream;
114 SvMemoryStream& mrUncompressedStream;
117 class OOX_DLLPUBLIC VBAEncryption
119 public:
120 VBAEncryption(const sal_uInt8* pData,
121 const sal_uInt16 nLength,
122 SvStream& rEncryptedData,
123 sal_uInt8 nProjKey);
125 void write();
127 static sal_uInt8 calculateProjKey(const OUString& rString);
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
139 sal_uInt8 mnSeed; // the seed value
140 sal_uInt8 mnVersionEnc; // the version encoding
142 void writeSeed();
143 void writeVersionEnc();
144 void writeProjKeyEnc();
145 void writeIgnoredEnc();
146 void writeDataLengthEnc();
147 void writeDataEnc();
150 #endif
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */