20#include <com/sun/star/beans/XPropertySet.hpp>
21#include <com/sun/star/script/XLibraryContainer.hpp>
22#include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
23#include <com/sun/star/script/vba/XVBACompatibility.hpp>
24#include <com/sun/star/frame/XModel.hpp>
26#include <ooo/vba/excel/XWorkbook.hpp>
29#include <oox/token/properties.hxx>
35#include <rtl/tencinfo.h>
36#include <osl/thread.h>
38#define VBA_EXPORT_DEBUG 0
39#define VBA_USE_ORIGINAL_WM_STREAM 0
40#define VBA_USE_ORIGINAL_DIR_STREAM 0
41#define VBA_USE_ORIGINAL_PROJECT_STREAM 0
42#define VBA_USE_ORIGINAL_VBA_PROJECT 0
47#define VBA_ENCRYPTION 1
51void exportString(
SvStream&
rStrm, std::u16string_view rString,
52 const rtl_TextEncoding eTextEncoding)
58void exportUTF16String(
SvStream&
rStrm,
const OUString& rString)
60 sal_Int32
n = rString.getLength();
62 for (sal_Int32
i = 0;
i <
n; ++
i)
69bool isWorkbook(
const css::uno::Reference<css::uno::XInterface>& xInterface)
71 css::uno::Reference<ooo::vba::excel::XWorkbook> xWorkbook(xInterface, css::uno::UNO_QUERY);
72 return xWorkbook.is();
75OUString createHexStringFromDigit(
sal_uInt8 nDigit)
77 OUString aString = OUString::number( nDigit, 16 );
78 if(aString.getLength() == 1)
79 aString = OUString::number(0) + aString;
80 return aString.toAsciiUpperCase();
86 : mrCompressedStream(rCompressedStream)
87 , mpUncompressedData(
pData)
88 , mpCompressedChunkStream(nullptr)
89 , mnChunkSize(nChunkSize)
90 , mnCompressedCurrent(0)
92 , mnDecompressedCurrent(0)
93 , mnDecompressedEnd(0)
99 pBuffer[
nPos] = nVal & 0xFF;
100 pBuffer[
nPos+1] = (nVal & 0xFF00) >> 8;
107 sal_uInt16 nHeader = 0;
148 setUInt16(pCompressedChunkStream, 0, nHeader);
157 sal_uInt16 nTemp1 = rHeader & 0xF000;
158 sal_uInt16 nTemp2 = nSize - 3;
159 rHeader = nTemp1 | nTemp2;
165 sal_uInt16 nTemp1 = rHeader & 0x7FFF;
166 sal_uInt16 nTemp2 =
static_cast<sal_uInt16
>(bCompressed) << 15;
167 rHeader = nTemp1 | nTemp2;
173 sal_Int32 nTemp = rHeader & 0x8FFFF;
174 rHeader = nTemp | 0x3000;
233 size_t nTemp1 =
static_cast<int>(bVal) <<
index;
235 rFlag = nTemp2 | nTemp1;
241 sal_uInt16 nLengthMask = 0;
242 sal_uInt16 nOffsetMask = 0;
244 sal_uInt16 nMaxLength;
246 sal_uInt16 nTemp1 = nOffset -1;
248 sal_uInt16 nTemp3 =
nLength - 3;
249 sal_uInt16
nToken = (nTemp1 << nTemp2) | nTemp3;
258 sal_Int32 nBestCandidate = nCandidate;
259 while (nCandidate >= 0)
261 sal_Int32 nC = nCandidate;
274 nBestCandidate = nCandidate;
281 sal_uInt16 nMaximumLength = 0;
282 sal_uInt16 nLengthMask, nOffsetMask,
nBitCount;
284 rLength = std::min<sal_uInt16>(nMaximumLength, nBestLen);
296 sal_uInt16& rBitCount, sal_uInt16& rMaximumLength)
299 assert(nDifference <= 4096);
300 assert(nDifference >= 1);
301 if (nDifference >= 2049)
303 else if (nDifference >= 1025)
305 else if (nDifference >= 513)
307 else if (nDifference >= 257)
309 else if (nDifference >= 129)
311 else if (nDifference >= 65)
313 else if (nDifference >= 33)
315 else if (nDifference >= 17)
319 rLengthMask = 0xffff >> rBitCount;
320 rOffsetMask = ~rLengthMask;
321 rMaximumLength = rLengthMask + 3;
331 for (
size_t i = 0;
i < nPadding; ++
i)
339 mrCompressedStream(rCompressedStream),
340 mrUncompressedStream(rUncompressedStream)
349 bool bStreamNotEnded =
true;
352 std::size_t nRemainingSize = nSize;
353 while(bStreamNotEnded)
355 std::size_t nChunkSize = std::min<size_t>(nRemainingSize, 4096);
360 nRemainingSize -= nChunkSize;
361 bStreamNotEnded = nRemainingSize != 0;
370 const rtl_TextEncoding eTextEncoding)
373 ,mrEncryptedData(rEncryptedData)
374 ,mnUnencryptedByte1(0)
381 ,meTextEncoding(eTextEncoding)
383 std::random_device rd;
384 std::mt19937 gen(rd());
385 std::uniform_int_distribution<> dis(0, 255);
404 sal_Int32
n = rProjectKey.getLength();
406 for (sal_Int32
i = 0;
i <
n; ++
i)
485void writePROJECTSYSKIND(
SvStream& rStrm)
493void writePROJECTLCID(
SvStream& rStrm)
501void writePROJECTLCIDINVOKE(
SvStream& rStrm)
509void writePROJECTCODEPAGE(
SvStream& rStrm,
const rtl_TextEncoding eTextEncoding)
517void writePROJECTNAME(
SvStream& rStrm, std::u16string_view name,
const rtl_TextEncoding eTextEncoding)
520 size_t sizeOfProjectName =
name.size();
522 exportString(rStrm, name, eTextEncoding);
526void writePROJECTDOCSTRING(
SvStream& rStrm)
535void writePROJECTHELPFILEPATH(
SvStream& rStrm)
544void writePROJECTHELPCONTEXT(
SvStream& rStrm)
552void writePROJECTLIBFLAGS(
SvStream& rStrm)
560void writePROJECTVERSION(
SvStream& rStrm)
569void writePROJECTCONSTANTS(
SvStream& rStrm)
578void writePROJECTINFORMATION(
SvStream& rStrm, std::u16string_view projectName,
579 const rtl_TextEncoding eTextEncoding)
581 writePROJECTSYSKIND(rStrm);
582 writePROJECTLCID(rStrm);
583 writePROJECTLCIDINVOKE(rStrm);
584 writePROJECTCODEPAGE(rStrm, eTextEncoding);
585 writePROJECTNAME(rStrm, projectName, eTextEncoding);
586 writePROJECTDOCSTRING(rStrm);
587 writePROJECTHELPFILEPATH(rStrm);
588 writePROJECTHELPCONTEXT(rStrm);
589 writePROJECTLIBFLAGS(rStrm);
590 writePROJECTVERSION(rStrm);
591 writePROJECTCONSTANTS(rStrm);
595void writeREFERENCENAME(
SvStream& rStrm,
const OUString& name,
const rtl_TextEncoding eTextEncoding)
600 exportString(rStrm, name, eTextEncoding);
602 sal_Int32 unicodesize =
size * 2;
604 exportUTF16String(rStrm, name);
608void writeREFERENCEREGISTERED(
SvStream& rStrm, std::u16string_view libid,
609 const rtl_TextEncoding eTextEncoding)
612 size_t sizeOfLibid = libid.size();
613 sal_Int32
size = sizeOfLibid + 10;
616 exportString(rStrm, libid, eTextEncoding);
622void writeREFERENCE(
SvStream& rStrm,
const OUString& name, std::u16string_view libid,
623 const rtl_TextEncoding eTextEncoding)
625 writeREFERENCENAME(rStrm, name, eTextEncoding);
626 writeREFERENCEREGISTERED(rStrm, libid, eTextEncoding);
630void writePROJECTREFERENCES(
SvStream& rStrm,
const rtl_TextEncoding eTextEncoding)
633 writeREFERENCE(rStrm,
"stdole", u
"*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\SysWOW64\\stdole2.tlb#OLE Automation", eTextEncoding);
634 writeREFERENCE(rStrm,
"Office", u
"*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\OFFICE14\\MSO.DLL#Microsoft Office 14.0 Object Library", eTextEncoding);
638void writePROJECTCOOKIE(
SvStream& rStrm)
646void writeMODULENAME(
SvStream& rStrm, std::u16string_view name,
const rtl_TextEncoding eTextEncoding)
649 sal_Int32
n =
name.size();
651 exportString(rStrm, name, eTextEncoding);
655void writeMODULENAMEUNICODE(
SvStream& rStrm,
const OUString& name)
658 sal_Int32
n =
name.getLength() * 2;
660 exportUTF16String(rStrm, name);
664void writeMODULESTREAMNAME(
SvStream& rStrm,
const OUString& streamName,
665 const rtl_TextEncoding eTextEncoding)
668 sal_Int32
n = streamName.getLength();
670 exportString(rStrm, streamName, eTextEncoding);
673 exportUTF16String(rStrm, streamName);
677void writeMODULEDOCSTRING(
SvStream& rStrm)
686void writeMODULEOFFSET(
SvStream& rStrm)
694void writeMODULEHELPCONTEXT(
SvStream& rStrm)
702void writeMODULECOOKIE(
SvStream& rStrm)
710void writeMODULETYPE(
SvStream& rStrm,
const sal_uInt16 type)
720void writePROJECTMODULE(
SvStream& rStrm,
const OUString& name,
const sal_uInt16 type,
721 const rtl_TextEncoding eTextEncoding)
723 writeMODULENAME(rStrm, name, eTextEncoding);
724 writeMODULENAMEUNICODE(rStrm, name);
725 writeMODULESTREAMNAME(rStrm, name, eTextEncoding);
726 writeMODULEDOCSTRING(rStrm);
727 writeMODULEOFFSET(rStrm);
728 writeMODULEHELPCONTEXT(rStrm);
729 writeMODULECOOKIE(rStrm);
730 writeMODULETYPE(rStrm, type);
736void writePROJECTMODULES(
SvStream& rStrm,
737 const css::uno::Reference<css::container::XNameContainer>& xNameContainer,
738 const std::vector<sal_Int32>& rLibraryMap,
739 const rtl_TextEncoding eTextEncoding)
741 const css::uno::Sequence<OUString> aElementNames = xNameContainer->getElementNames();
742 sal_Int32
n = aElementNames.getLength();
743 css::uno::Reference<css::script::vba::XVBAModuleInfo> xModuleInfo(xNameContainer, css::uno::UNO_QUERY);
744 assert(xModuleInfo.is());
751 writePROJECTCOOKIE(rStrm);
753 for (sal_Int32
i = 0;
i <
n; ++
i)
755 const OUString& rModuleName = aElementNames[rLibraryMap[
i]];
756 css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(rModuleName);
757 writePROJECTMODULE(rStrm, rModuleName, aModuleInfo.ModuleType, eTextEncoding);
762void exportDirStream(
SvStream& rStrm,
763 const css::uno::Reference<css::container::XNameContainer>& xNameContainer,
764 const std::vector<sal_Int32>& rLibraryMap,
const OUString& projectName,
765 const rtl_TextEncoding eTextEncoding)
769 writePROJECTINFORMATION(aDirStream, projectName, eTextEncoding);
770 writePROJECTREFERENCES(aDirStream, eTextEncoding);
771 writePROJECTMODULES(aDirStream, xNameContainer, rLibraryMap, eTextEncoding);
772 aDirStream.WriteUInt16(0x0010);
773 aDirStream.WriteUInt32(0x00000000);
776 static constexpr OUStringLiteral aDirFileName(u
"/tmp/vba_dir_out.bin");
777 SvFileStream aDirStreamDebug(aDirFileName, StreamMode::READWRITE);
779 aDirStreamDebug.WriteStream(aDirStream);
783 aCompression.write();
787void exportModuleStream(
SvStream& rStrm,
const OUString& rSourceCode,
const OUString& aElementName,
788 css::script::ModuleInfo
const& rInfo,
const rtl_TextEncoding eTextEncoding)
792 exportString(aModuleStream, Concat2View(
"Attribute VB_Name = \"" + aElementName +
"\"\r\n"), eTextEncoding);
793 if (rInfo.ModuleType == 4)
795 if (isWorkbook(rInfo.ModuleObject))
796 exportString(aModuleStream, u
"Attribute VB_Base = \"0{00020819-0000-0000-C000-000000000046}\"\r\n", eTextEncoding);
798 exportString(aModuleStream, u
"Attribute VB_Base = \"0{00020820-0000-0000-C000-000000000046}\"\r\n", eTextEncoding);
800 exportString(aModuleStream, u
"Attribute VB_GlobalNameSpace = False\r\n", eTextEncoding);
801 exportString(aModuleStream, u
"Attribute VB_Creatable = False\r\n", eTextEncoding);
802 exportString(aModuleStream, u
"Attribute VB_PredeclaredId = True\r\n", eTextEncoding);
803 exportString(aModuleStream, u
"Attribute VB_Exposed = True\r\n", eTextEncoding);
804 exportString(aModuleStream, u
"Attribute VB_TemplateDerived = False\r\n", eTextEncoding);
805 exportString(aModuleStream, u
"Attribute VB_Customizable = True\r\n", eTextEncoding);
807 OUString aSourceCode = rSourceCode.replaceFirst(
"Option VBASupport 1\n",
"");
808 const sal_Int32
nPos = aSourceCode.indexOf(
"Rem Attribute VBA_ModuleType=");
809 const sal_Int32 nEndPos =
nPos != -1 ? aSourceCode.indexOf(
"\n", nPos) : -1;
810 if (nPos != -1 && nEndPos != -1)
811 aSourceCode = aSourceCode.replaceAt(nPos, nEndPos - nPos+1, u
"");
812 aSourceCode = aSourceCode.replaceAll(
"\n",
"\r\n");
813 exportString(aModuleStream, aSourceCode, eTextEncoding);
816 OUString aModuleFileName(
"/tmp/vba_" + aElementName +
"_out.bin");
817 SvFileStream aModuleStreamDebug(aModuleFileName, StreamMode::READWRITE);
818 aModuleStream.Seek(0);
819 aModuleStreamDebug.WriteStream(aModuleStream);
823 aCompression.write();
827void exportVBAProjectStream(
SvStream& rStrm)
836void exportPROJECTStream(
SvStream& rStrm,
837 const css::uno::Reference<css::container::XNameContainer>& xNameContainer,
838 const OUString& projectName,
const std::vector<sal_Int32>& rLibraryMap,
839 const rtl_TextEncoding eTextEncoding)
841 const css::uno::Sequence<OUString> aElementNames = xNameContainer->getElementNames();
842 sal_Int32
n = aElementNames.getLength();
843 css::uno::Reference<css::script::vba::XVBAModuleInfo> xModuleInfo(xNameContainer, css::uno::UNO_QUERY);
844 assert(xModuleInfo.is());
849 exportString(rStrm, u
"ID=\"", eTextEncoding);
852 exportString(rStrm, aProjectID, eTextEncoding);
853 exportString(rStrm, u
"\"\r\n", eTextEncoding);
856 for (sal_Int32
i = 0;
i <
n; ++
i)
858 const OUString& rModuleName = aElementNames[rLibraryMap[
i]];
859 css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(rModuleName);
860 if(aModuleInfo.ModuleType == 1)
862 exportString(rStrm, Concat2View(
"Module=" + rModuleName +
"\r\n"),
865 else if(aModuleInfo.ModuleType == 4)
868 Concat2View(
"Document=" + rModuleName +
"/&H00000000\r\n"),
874 exportString(rStrm, Concat2View(
"Name=\"" + projectName +
"\"\r\n"), eTextEncoding);
877 exportString(rStrm, u
"HelpContextID=\"0\"\r\n", eTextEncoding);
880 exportString(rStrm, u
"VersionCompatible32=\"393222000\"\r\n", eTextEncoding);
884 exportString(rStrm, u
"CMG=\"", eTextEncoding);
886 aProtectedStream.WriteUInt32(0x00000000);
889 VBAEncryption aProtectionState(pData, 4, rStrm, nProjKey, eTextEncoding);
890 aProtectionState.write();
891 exportString(rStrm, u
"\"\r\n", eTextEncoding);
893 exportString(rStrm,
"CMG=\"BEBC9256EEAAA8AEA8AEA8AEA8AE\"\r\n", eTextEncoding);
898 exportString(rStrm, u
"DPB=\"", eTextEncoding);
899 aProtectedStream.Seek(0);
900 aProtectedStream.WriteUInt8(0x00);
901 pData =
static_cast<const sal_uInt8*
>(aProtectedStream.GetData());
902 VBAEncryption aProjectPassword(pData, 1, rStrm, nProjKey, eTextEncoding);
903 aProjectPassword.write();
904 exportString(rStrm, u
"\"\r\n", eTextEncoding);
906 exportString(rStrm,
"DPB=\"7C7E5014B0D3B1D3B1D3\"\r\n", eTextEncoding);
911 exportString(rStrm, u
"GC=\"", eTextEncoding);
912 aProtectedStream.Seek(0);
913 aProtectedStream.WriteUInt8(0xFF);
914 pData =
static_cast<const sal_uInt8*
>(aProtectedStream.GetData());
915 VBAEncryption aVisibilityState(pData, 1, rStrm, nProjKey, eTextEncoding);
916 aVisibilityState.write();
917 exportString(rStrm, u
"\"\r\n\r\n", eTextEncoding);
919 exportString(rStrm,
"GC=\"3A3816DAD5DBD5DB2A\"\r\n\r\n", eTextEncoding);
924 u
"[Host Extender Info]\r\n"
925 "&H00000001={3832D640-CF90-11CF-8E43-00A0C911005A};VBE;&H00000000\r\n\r\n",
929 exportString(rStrm, u
"[Workspace]\r\n", eTextEncoding);
930 for (sal_Int32
i = 0;
i <
n; ++
i)
932 const OUString& rModuleName = aElementNames[rLibraryMap[
i]];
933 css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(rModuleName);
934 if(aModuleInfo.ModuleType == 1)
936 exportString(rStrm, Concat2View(rModuleName +
"=25, 25, 1439, 639, \r\n"),
941 exportString(rStrm, Concat2View(rModuleName +
"=0, 0, 0, 0, C\r\n"),
948void writeNAMEMAP(
SvStream& rStrm,
const css::uno::Sequence<OUString>& rElementNames,
949 const std::vector<sal_Int32>& rLibraryMap,
const rtl_TextEncoding eTextEncoding)
951 int n = rElementNames.getLength();
952 for(sal_Int32
i = 0;
i <
n; ++
i)
954 const OUString& rModuleName = rElementNames[rLibraryMap[
i]];
955 exportString(rStrm, rModuleName, eTextEncoding);
957 exportUTF16String(rStrm, rModuleName);
963void exportPROJECTwmStream(
SvStream& rStrm,
const css::uno::Sequence<OUString>& rElementNames,
964 const std::vector<sal_Int32>& rLibraryMap,
const rtl_TextEncoding eTextEncoding)
966 writeNAMEMAP(rStrm, rElementNames, rLibraryMap, eTextEncoding);
970void getCorrectExportOrder(
const css::uno::Reference<css::container::XNameContainer>& xNameContainer, std::vector<sal_Int32>& rLibraryMap)
972 const css::uno::Sequence<OUString> aElementNames = xNameContainer->getElementNames();
973 sal_Int32
n = aElementNames.getLength();
974 css::uno::Reference<css::script::vba::XVBAModuleInfo> xModuleInfo(xNameContainer, css::uno::UNO_QUERY);
976 sal_Int32 nCurrentId = 0;
978 for (sal_Int32
i = 0;
i <
n; ++
i)
980 css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(aElementNames[
i]);
981 if (aModuleInfo.ModuleType != 4)
983 rLibraryMap[nCurrentId] =
i;
988 sal_Int32 nWorkbookIndex = -1;
990 for (sal_Int32
i = 0;
i <
n; ++
i)
992 css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(aElementNames[
i]);
993 bool bWorkbook = isWorkbook(aModuleInfo.ModuleObject);
997 rLibraryMap[nCurrentId] =
i;
1003 for (sal_Int32
i = 0;
i <
n; ++
i)
1005 if (
i == nWorkbookIndex)
1008 css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(aElementNames[
i]);
1009 if (aModuleInfo.ModuleType == 4)
1011 rLibraryMap[nCurrentId] =
i;
1019#if VBA_USE_ORIGINAL_WM_STREAM || VBA_USE_ORIGINAL_DIR_STREAM \
1020 || VBA_USE_ORIGINAL_PROJECT_STREAM || VBA_USE_ORIGINAL_VBA_PROJECT \
1021 || VBA_USE_ORIGINAL_DIR_STREAM
1022void addFileStreamToSotStream(
const OUString& rPath,
SotStorageStream& rStream)
1024 SvFileStream aFileStream(rPath, StreamMode::READWRITE);
1025 rStream.WriteStream(aFileStream);
1031 css::uno::Reference<css::container::XNameContainer> xNameContainer =
getBasicLibrary();
1032 if (!xNameContainer.is()) {
1035 const css::uno::Sequence<OUString> aElementNames = xNameContainer->getElementNames();
1036 sal_Int32
n = aElementNames.getLength();
1039 std::vector<sal_Int32> aLibraryMap(
n, 0);
1040 getCorrectExportOrder(xNameContainer, aLibraryMap);
1052#if VBA_USE_ORIGINAL_WM_STREAM
1053 OUString aProjectwmPath =
"/home/moggi/Documents/testfiles/vba/PROJECTwm";
1054 addFileStreamToSotStream(aProjectwmPath, *pPROJECTwmStream);
1056 exportPROJECTwmStream(*pPROJECTwmStream, aElementNames, aLibraryMap, eTextEncoding);
1059#if VBA_USE_ORIGINAL_DIR_STREAM
1060 OUString aDirPath =
"/home/moggi/Documents/testfiles/vba/VBA/dir";
1061 addFileStreamToSotStream(aDirPath, *pDirStream);
1063 exportDirStream(*pDirStream, xNameContainer, aLibraryMap,
getProjectName(), eTextEncoding);
1066#if VBA_USE_ORIGINAL_PROJECT_STREAM
1067 OUString aProjectPath =
"/home/moggi/Documents/testfiles/vba/PROJECT";
1068 addFileStreamToSotStream(aProjectPath, *pPROJECTStream);
1070 exportPROJECTStream(*pPROJECTStream, xNameContainer,
getProjectName(), aLibraryMap,
1074#if VBA_USE_ORIGINAL_VBA_PROJECT
1075 OUString a_VBA_ProjectPath =
"/home/moggi/Documents/testfiles/vba/VBA/_VBA_PROJECT";
1076 addFileStreamToSotStream(a_VBA_ProjectPath, *pVBAProjectStream);
1078 exportVBAProjectStream(*pVBAProjectStream);
1081#if VBA_USE_ORIGINAL_DIR_STREAM
1082 OUString aModule1Path =
"/home/moggi/Documents/testfiles/vba/VBA/Module1";
1083 OUString aSheet1Path =
"/home/moggi/Documents/testfiles/vba/VBA/Sheet1";
1084 OUString aSheet2Path =
"/home/moggi/Documents/testfiles/vba/VBA/Sheet2";
1085 OUString aSheet3Path =
"/home/moggi/Documents/testfiles/vba/VBA/Sheet3";
1086 OUString aWorkbookPath =
"/home/moggi/Documents/testfiles/vba/VBA/ThisWorkbook";
1092 addFileStreamToSotStream(aModule1Path, *pModule1Stream);
1093 addFileStreamToSotStream(aSheet1Path, *pSheet1Stream);
1094 addFileStreamToSotStream(aSheet2Path, *pSheet2Stream);
1095 addFileStreamToSotStream(aSheet3Path, *pSheet3Stream);
1096 addFileStreamToSotStream(aWorkbookPath, *pWorkbookStream);
1098 pModule1Stream->Commit();
1099 pSheet1Stream->Commit();
1100 pSheet2Stream->Commit();
1101 pSheet3Stream->Commit();
1102 pWorkbookStream->Commit();
1105 css::uno::Reference<css::script::vba::XVBAModuleInfo> xModuleInfo(xNameContainer, css::uno::UNO_QUERY);
1106 for (sal_Int32
i = 0;
i <
n; ++
i)
1108 const OUString& rModuleName = aElementNames[aLibraryMap[
i]];
1110 css::uno::Any aCode = xNameContainer->getByName(rModuleName);
1111 css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(rModuleName);
1112 OUString aSourceCode;
1113 aCode >>= aSourceCode;
1114 exportModuleStream(*pModuleStream, aSourceCode, rModuleName, aModuleInfo, eTextEncoding);
1115 pModuleStream->Commit();
1120 pVBAProjectStream->Commit();
1122 pDirStream->Commit();
1123 xVBAStream->Commit();
1124 pPROJECTStream->Commit();
1125 pPROJECTwmStream->Commit();
1132 css::uno::Reference<css::script::XLibraryContainer> xLibContainer(aDocProp.
getAnyProperty(oox::PROP_BasicLibraries), css::uno::UNO_QUERY);
1134 return xLibContainer;
1139 css::uno::Reference<css::container::XNameContainer> xLibrary;
1142 css::uno::Reference<css::script::XLibraryContainer> xLibContainer =
getLibraryContainer();
1144 xLibrary.set( xLibContainer->getByName(aProjectName), css::uno::UNO_QUERY_THROW );
1155 css::uno::Reference<css::script::XLibraryContainer> xLibContainer =
getLibraryContainer();
1156 if (!xLibContainer.is())
1159 css::uno::Reference<css::script::vba::XVBACompatibility> xVbaCompatibility (xLibContainer, css::uno::UNO_QUERY);
1160 if (!xVbaCompatibility.is())
1163 bool bVBACompatibility = xVbaCompatibility->getVBACompatibilityMode();
1165 return bVBACompatibility;
1170 css::uno::Reference<css::script::vba::XVBACompatibility> xVbaCompatibility(
getLibraryContainer(), css::uno::UNO_QUERY);
1171 if (xVbaCompatibility.is())
1172 return xVbaCompatibility->getProjectName();
1179 rtl_TextEncoding aTextEncoding = osl_getThreadTextEncoding();
1181 css::uno::UNO_QUERY);
1185 xProps->getPropertyValue(
"VBATextEncoding") >>= aTextEncoding;
1187 catch (
const css::uno::Exception&)
1191 return aTextEncoding;
css::uno::Reference< css::frame::XModel2 > mxModel
tools::SvRef< SotStorageStream > OpenSotStream(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE)
SotStorage * OpenSotStorage(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE, bool transacted=true)
std::size_t GetEndOfData() const
SvStream & WriteUnicode(sal_Unicode)
std::size_t WriteBytes(const void *pData, std::size_t nSize)
SvStream & WriteUInt16(sal_uInt16 nUInt16)
SvStream & WriteOString(std::string_view rStr)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
SvStream & WriteUInt8(sal_uInt8 nuInt8)
sal_uInt64 Seek(sal_uInt64 nPos)
void compressToken(size_t index, sal_uInt8 &nFlagByte)
sal_uInt64 mnDecompressedEnd
VBACompressionChunk(SvStream &rCompressedStream, const sal_uInt8 *pData, std::size_t nChunkSize)
void CopyTokenHelp(sal_uInt16 &rLengthMask, sal_uInt16 &rOffsetMask, sal_uInt16 &rBitCount, sal_uInt16 &rMaximumLength)
static void PackCompressedChunkSignature(sal_uInt16 &rHeader)
sal_uInt16 CopyToken(size_t nLength, size_t nOffset)
const sal_uInt8 * mpUncompressedData
void match(size_t &rLength, size_t &rOffset)
SvStream & mrCompressedStream
static void SetFlagBit(size_t index, bool bVal, sal_uInt8 &rFlag)
sal_uInt64 mnCompressedEnd
sal_uInt16 handleHeader(bool bCompressed)
sal_uInt64 mnCompressedCurrent
sal_uInt8 * mpCompressedChunkStream
static void PackCompressedChunkFlag(bool bCompressed, sal_uInt16 &rHeader)
static void PackCompressedChunkSize(size_t nSize, sal_uInt16 &rHeader)
void compressTokenSequence()
sal_uInt64 mnDecompressedCurrent
SvStream & mrCompressedStream
SvMemoryStream & mrUncompressedStream
VBACompression(SvStream &rCompressedStream, SvMemoryStream &rUncompressedStream)
SvStream & mrEncryptedData
sal_uInt8 mnEncryptedByte2
void writeDataLengthEnc()
sal_uInt8 mnEncryptedByte1
sal_uInt8 mnIgnoredLength
const sal_uInt16 mnLength
VBAEncryption(const sal_uInt8 *pData, const sal_uInt16 nLength, SvStream &rEncryptedData, sal_uInt8 nProjKey, rtl_TextEncoding eTextEncoding)
static sal_uInt8 calculateProjKey(const OUString &rString)
rtl_TextEncoding meTextEncoding
sal_uInt8 mnUnencryptedByte1
css::uno::Reference< css::script::XLibraryContainer > getLibraryContainer() const
rtl_TextEncoding getVBATextEncoding() const
bool containsVBAProject()
css::uno::Reference< css::container::XNameContainer > getBasicLibrary() const
void exportVBA(SotStorage *pRootStorage)
VbaExport(css::uno::Reference< css::frame::XModel > xModel)
OUString getProjectName() const
css::uno::Reference< css::frame::XModel > mxModel
A wrapper for a UNO property set.
css::uno::Any getAnyProperty(sal_Int32 nPropId) const
Gets the specified property from the property set.
std::unique_ptr< sal_Int32[]> pData
OString generateGUIDString()
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Reference< XModel > xModel
static void setUInt16(sal_uInt8 *pBuffer, size_t nPos, sal_uInt16 nVal)