15#include <com/sun/star/beans/NamedValue.hpp>
16#include <com/sun/star/io/XSeekable.hpp>
17#include <com/sun/star/io/XStream.hpp>
18#include <com/sun/star/io/IOException.hpp>
19#include <com/sun/star/uno/XComponentContext.hpp>
20#include <com/sun/star/packages/XPackageEncryption.hpp>
29void lcl_getListOfStreams(
oox::StorageBase* pStorage, std::vector<OUString>& rElementNames)
31 std::vector<OUString> oElementNames;
33 for (
const auto&
sName : oElementNames)
36 if (rSubStorage && rSubStorage->isStorage())
38 lcl_getListOfStreams(rSubStorage.get(), rElementNames);
43 rElementNames.push_back(
sName);
45 rElementNames.push_back(pStorage->
getPath() +
"/" +
sName);
58 , mrOleStorage(rOleStorage)
61 std::vector<OUString> aStreamNames;
65 for (
const auto& sStreamName : aStreamNames)
69 throw io::IOException(
"Cannot open OLE input stream for " + sStreamName +
"!");
73 css::uno::Sequence<sal_Int8> oData;
74 sal_Int32 nStreamSize = aBinaryInputStream.
size();
75 sal_Int32 nReadBytes = aBinaryInputStream.
readData(oData, nStreamSize);
77 if (nStreamSize != nReadBytes)
79 SAL_WARN(
"oox",
"OLE stream invalid content");
80 throw io::IOException(
"OLE stream invalid content for " + sStreamName +
"!");
83 aStreamsData[sStreamName] <<= oData;
101 uno::Reference<io::XInputStream> xDataSpaceMap
103 OUString sDataSpaceName;
105 if (xDataSpaceMap.is())
107 bool bBroken =
false;
110 sal_uInt32 aHeaderLength = aDataSpaceStream.
readuInt32();
112 "DataSpaceMap length != 8 is not supported. Some content may be skipped");
113 sal_uInt32 aEntryCount = aDataSpaceStream.
readuInt32();
115 "DataSpaceMap contains more than one entry. Some content may be skipped");
118 for (sal_uInt32
i = 0;
i < aEntryCount && !bBroken;
i++)
121 aDataSpaceStream.
skip(
sizeof(sal_uInt32));
124 sal_uInt32 aReferenceComponentCount = aDataSpaceStream.
readuInt32();
125 for (sal_uInt32 j = 0; j < aReferenceComponentCount && !bBroken; j++)
129 aDataSpaceStream.
skip(
sizeof(sal_uInt32));
130 sal_uInt32 aReferenceComponentNameLength = aDataSpaceStream.
readuInt32();
132 if (aDataSpaceStream.
getRemaining() < aReferenceComponentNameLength)
138 aDataSpaceStream.
skip((4 - (aReferenceComponentNameLength & 3))
141 bBroken |= aDataSpaceStream.
isEof();
144 sal_uInt32 aDataSpaceNameLength = aDataSpaceStream.
readuInt32();
145 if (aDataSpaceStream.
getRemaining() < aDataSpaceNameLength)
150 sDataSpaceName = aDataSpaceStream.
readUnicodeArray(aDataSpaceNameLength / 2);
151 aDataSpaceStream.
skip((4 - (aDataSpaceNameLength & 3)) & 3);
153 bBroken |= aDataSpaceStream.
isEof();
158 SAL_WARN(
"oox",
"EOF on parsing DataSpaceMapEntry table");
166 SAL_WARN(
"oox",
"Encrypted package does not contain DataSpaceMap");
167 sDataSpaceName =
"StrongEncryptionDataSpace";
172 mxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
174 css::uno::UNO_QUERY);
188 return uno::Sequence<beans::NamedValue>();
195 bool bResult =
false;
204 uno::Reference<io::XInputStream> xEncryptedPackage
208 uno::Reference<io::XOutputStream> xDecryptedPackage = xDocumentStream->getOutputStream();
212 css::uno::Reference<io::XSeekable> xSeekable(xDecryptedPackage, css::uno::UNO_QUERY);
css::uno::Sequence< css::beans::NamedValue > getAsConstNamedValueList() const
sal_Int64 getRemaining() const
Returns the size of the remaining data available in the stream, if stream supports size() and tell(),...
bool isEof() const
Returns true, if the stream position is invalid (EOF).
virtual sal_Int64 size() const override
Returns the size of the stream, if wrapped stream is seekable, otherwise -1.
Base class for storage access implementations.
OUString getPath() const
Returns the full path of this storage.
void getElementNames(::std::vector< OUString > &orElementNames) const
Fills the passed vector with the names of all direct elements of this storage.
css::uno::Reference< css::io::XInputStream > openInputStream(const OUString &rStreamName)
Opens and returns the specified input stream from the storage.
bool isStorage() const
Returns true, if the object represents a valid storage.
StorageRef openSubStorage(const OUString &rStorageName, bool bCreateMissing)
Opens and returns the specified sub storage from the storage.
bool isRootStorage() const
Returns true, if the object represents the root storage.
bool readEncryptionInfo()
bool decrypt(const css::uno::Reference< css::io::XStream > &xDocumentStream)
DocumentDecryption(css::uno::Reference< css::uno::XComponentContext > xContext, oox::ole::OleStorage &rOleStorage)
css::uno::Reference< css::packages::XPackageEncryption > mxPackageEncryption
oox::ole::OleStorage & mrOleStorage
css::uno::Sequence< css::beans::NamedValue > createEncryptionData(const OUString &rPassword)
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::Sequence< css::beans::NamedValue > maStreamsSequence
bool generateEncryptionKey(const OUString &rPassword)
Implements stream access for binary OLE storages.
Sequence< PropertyValue > aArguments
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
std::shared_ptr< StorageBase > StorageRef