[Libreoffice-commits] core.git: 3 commits - oox/source

Rosemary rosemaryseb8 at gmail.com
Fri Oct 9 09:59:23 PDT 2015


 oox/source/ole/vbaexport.cxx |   94 ++++++++++++++++++-------------------------
 1 file changed, 40 insertions(+), 54 deletions(-)

New commits:
commit adf8def2b09c0276f0ce836b58d7a3aa722eee15
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Oct 9 13:18:59 2015 +0200

    remove redundant code
    
    - Use the existing createHexStringFromDigit()
        to export hex digits as strings
    
    - The parameters offset and stream name
        are not required
    
    Change-Id: If9aab7816efb81655c40a11743e8951ab0b26e1d

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index fae6e80..6252165 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -72,23 +72,40 @@ void exportUTF16String(SvStream& rStrm, const OUString& rString)
     }
 }
 
-void exportHexString(SvStream& rStrm, const sal_uInt8 nByte)
+bool isWorkbook(css::uno::Reference<css::uno::XInterface> xInterface)
+{
+    css::uno::Reference<ooo::vba::excel::XWorkbook> xWorkbook(xInterface, css::uno::UNO_QUERY);
+    return xWorkbook.is();
+}
+
+OUString createHexStringFromDigit(sal_uInt8 nDigit)
+{
+    OUString aString = OUString::number( nDigit, 16 );
+    if(aString.getLength() == 1)
+        aString = OUString::number(0) + aString;
+    return aString.toAsciiUpperCase();
+}
+
+OUString createGuidStringFromInt(sal_uInt8 nGuid[16])
 {
-    sal_uInt8 nNibble = (nByte & 0xF0) >> 4;
-    for(sal_uInt8 i = 0; i < 2; i++)
+    OUStringBuffer aBuffer;
+    aBuffer.append('{');
+    for(size_t i = 0; i < 16; ++i)
     {
-        if(nNibble > 9)
-            rStrm.WriteUInt8(nNibble + 55);
-        else
-            rStrm.WriteUInt8(nNibble + 48);
-        nNibble = nByte & 0xF;
+        aBuffer.append(createHexStringFromDigit(nGuid[i]));
+        if(i == 3|| i == 5 || i == 7 || i == 9 )
+            aBuffer.append('-');
     }
+    aBuffer.append('}');
+    OUString aString = aBuffer.makeStringAndClear();
+    return aString.toAsciiUpperCase();
 }
 
-bool isWorkbook(css::uno::Reference<css::uno::XInterface> xInterface)
+OUString generateGUIDString()
 {
-    css::uno::Reference<ooo::vba::excel::XWorkbook> xWorkbook(xInterface, css::uno::UNO_QUERY);
-    return xWorkbook.is();
+    sal_uInt8 nGuid[16];
+    rtl_createUuid(nGuid, NULL, true);
+    return createGuidStringFromInt(nGuid);
 }
 
 }
@@ -372,7 +389,6 @@ VBAEncryption::VBAEncryption(const sal_uInt8* pData, const sal_uInt16 length, Sv
 {
     if (!pSeed)
     {
-        // mnSeed = 0xBE;
         std::random_device rd;
         std::mt19937 gen(rd());
         std::uniform_int_distribution<> dis(0, 255);
@@ -382,13 +398,13 @@ VBAEncryption::VBAEncryption(const sal_uInt8* pData, const sal_uInt16 length, Sv
 
 void VBAEncryption::writeSeed()
 {
-    exportHexString(mrEncryptedData, mnSeed);
+    exportString(mrEncryptedData, createHexStringFromDigit(mnSeed));
 }
 
 void VBAEncryption::writeVersionEnc()
 {
     mnVersionEnc = mnSeed ^ mnVersion;
-    exportHexString(mrEncryptedData, mnVersionEnc);
+    exportString(mrEncryptedData, createHexStringFromDigit(mnVersionEnc));
 }
 
 sal_uInt8 VBAEncryption::calculateProjKey(const OUString& rProjectKey)
@@ -408,7 +424,7 @@ sal_uInt8 VBAEncryption::calculateProjKey(const OUString& rProjectKey)
 void VBAEncryption::writeProjKeyEnc()
 {
     sal_uInt8 nProjKeyEnc = mnSeed ^ mnProjKey;
-    exportHexString(mrEncryptedData, nProjKeyEnc);
+    exportString(mrEncryptedData, createHexStringFromDigit(nProjKeyEnc));
     mnUnencryptedByte1 = mnProjKey;
     mnEncryptedByte1 = nProjKeyEnc; // ProjKeyEnc
     mnEncryptedByte2 = mnVersionEnc; // VersionEnc
@@ -421,7 +437,7 @@ void VBAEncryption::writeIgnoredEnc()
     {
         sal_uInt8 nTempValue = 0xBE; // Any value can be assigned here
         sal_uInt8 nByteEnc = nTempValue ^ (mnEncryptedByte2 + mnUnencryptedByte1);
-        exportHexString(mrEncryptedData, nByteEnc);
+        exportString(mrEncryptedData, createHexStringFromDigit(nByteEnc));
         mnEncryptedByte2 = mnEncryptedByte1;
         mnEncryptedByte1 = nByteEnc;
         mnUnencryptedByte1 = nTempValue;
@@ -435,7 +451,7 @@ void VBAEncryption::writeDataLengthEnc()
     {
         sal_uInt8 nByte = temp & 0xFF;
         sal_uInt8 nByteEnc = nByte ^ (mnEncryptedByte2 + mnUnencryptedByte1);
-        exportHexString(mrEncryptedData, nByteEnc);
+        exportString(mrEncryptedData, createHexStringFromDigit(nByteEnc));
         mnEncryptedByte2 = mnEncryptedByte1;
         mnEncryptedByte1 = nByteEnc;
         mnUnencryptedByte1 = nByte;
@@ -448,7 +464,7 @@ void VBAEncryption::writeDataEnc()
     for(sal_Int16 i = 0; i < mnLength; i++)
     {
         sal_uInt8 nByteEnc = mpData[i] ^ (mnEncryptedByte2 + mnUnencryptedByte1);
-        exportHexString(mrEncryptedData, nByteEnc);
+        exportString(mrEncryptedData, createHexStringFromDigit(nByteEnc));
         mnEncryptedByte2 = mnEncryptedByte1;
         mnEncryptedByte1 = nByteEnc;
         mnUnencryptedByte1 = mpData[i];
@@ -672,11 +688,11 @@ void writeMODULEDOCSTRING(SvStream& rStrm)
 }
 
 // section 2.3.4.2.3.2.5
-void writeMODULEOFFSET(SvStream& rStrm, sal_uInt32 offset)
+void writeMODULEOFFSET(SvStream& rStrm)
 {
     rStrm.WriteUInt16(0x0031); // id
     rStrm.WriteUInt32(0x00000004); // sizeOfTextOffset
-    rStrm.WriteUInt32(offset); // TextOffset
+    rStrm.WriteUInt32(0x00000000); // TextOffset
 }
 
 // section 2.3.4.2.3.2.6
@@ -706,13 +722,13 @@ void writeMODULETYPE(SvStream& rStrm, const sal_uInt16 type)
 }
 
 // section 2.3.4.2.3.2
-void writePROJECTMODULE(SvStream& rStrm, const OUString& name, const OUString& streamName, sal_uInt32 offset, const sal_uInt16 type)
+void writePROJECTMODULE(SvStream& rStrm, const OUString& name, const sal_uInt16 type)
 {
     writeMODULENAME(rStrm, name);
     writeMODULENAMEUNICODE(rStrm, name);
-    writeMODULESTREAMNAME(rStrm, streamName);
+    writeMODULESTREAMNAME(rStrm, name);
     writeMODULEDOCSTRING(rStrm);
-    writeMODULEOFFSET(rStrm, offset);
+    writeMODULEOFFSET(rStrm);
     writeMODULEHELPCONTEXT(rStrm);
     writeMODULECOOKIE(rStrm);
     writeMODULETYPE(rStrm, type);
@@ -739,7 +755,7 @@ void writePROJECTMODULES(SvStream& rStrm, css::uno::Reference<css::container::XN
     {
         const OUString& rModuleName = aElementNames[rLibrayMap[i]];
         css::script::ModuleInfo aModuleInfo = xModuleInfo->getModuleInfo(rModuleName);
-        writePROJECTMODULE(rStrm, rModuleName, rModuleName, 0x00000000, aModuleInfo.ModuleType);
+        writePROJECTMODULE(rStrm, rModuleName, aModuleInfo.ModuleType);
     }
 }
 
@@ -825,36 +841,6 @@ void exportVBAProjectStream(SvStream& rStrm)
     rStrm.WriteUInt16(0x0000); // Undefined
 }
 
-OUString createHexStringFromDigit(sal_uInt8 nDigit)
-{
-    OUString aString = OUString::number( nDigit, 16 );
-    if(aString.getLength() == 1)
-        aString = OUString::number(0) + aString;
-    return aString.toAsciiUpperCase();
-}
-
-OUString createGuidStringFromInt(sal_uInt8 nGuid[16])
-{
-    OUStringBuffer aBuffer;
-    aBuffer.append('{');
-    for(size_t i = 0; i < 16; ++i)
-    {
-        aBuffer.append(createHexStringFromDigit(nGuid[i]));
-        if(i == 3|| i == 5 || i == 7 || i == 9 )
-            aBuffer.append('-');
-    }
-    aBuffer.append('}');
-    OUString aString = aBuffer.makeStringAndClear();
-    return aString.toAsciiUpperCase();
-}
-
-OUString generateGUIDString()
-{
-    sal_uInt8 nGuid[16];
-    rtl_createUuid(nGuid, NULL, true);
-    return createGuidStringFromInt(nGuid);
-}
-
 // section 2.3.1 PROJECT Stream
 void exportPROJECTStream(SvStream& rStrm, css::uno::Reference<css::container::XNameContainer> xNameContainer,
         const OUString& projectName, const std::vector<sal_Int32>& rLibraryMap)
commit 3bd12cb580c77d3d8f9b1147192644fd6a955885
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Oct 9 13:12:50 2015 +0200

    correct creation of hex string from digit
    
    Change-Id: I891a2a0b3e2194892bd4629c22b823902d18adc2

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index ca0db6c..fae6e80 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -829,7 +829,7 @@ OUString createHexStringFromDigit(sal_uInt8 nDigit)
 {
     OUString aString = OUString::number( nDigit, 16 );
     if(aString.getLength() == 1)
-        aString = aString + OUString::number(0);
+        aString = OUString::number(0) + aString;
     return aString.toAsciiUpperCase();
 }
 
commit bb0c5f767a1e124c1ca24f783676f91749b73e80
Author: Rosemary <rosemaryseb8 at gmail.com>
Date:   Fri Oct 9 13:10:36 2015 +0200

    Convert hex string to upper case
    
    Change-Id: I5ccdfc62a8fd3521b6c4ee0029e70b41aaf4542e

diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index b8c5e84..ca0db6c 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -830,7 +830,7 @@ OUString createHexStringFromDigit(sal_uInt8 nDigit)
     OUString aString = OUString::number( nDigit, 16 );
     if(aString.getLength() == 1)
         aString = aString + OUString::number(0);
-    return aString;
+    return aString.toAsciiUpperCase();
 }
 
 OUString createGuidStringFromInt(sal_uInt8 nGuid[16])


More information about the Libreoffice-commits mailing list