2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-17 12:30:48 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
#include <tools/stream.hxx>
|
2001-08-07 10:20:11 +00:00
|
|
|
#include <tools/tenccvt.hxx>
|
2013-07-01 10:33:48 -05:00
|
|
|
#include <osl/thread.h>
|
2018-07-08 15:01:23 +02:00
|
|
|
#include <sal/log.hxx>
|
2007-06-27 13:18:06 +00:00
|
|
|
#include <basic/sbx.hxx>
|
2017-10-09 17:04:39 +03:00
|
|
|
#include <sb.hxx>
|
2020-02-07 11:26:22 +02:00
|
|
|
#include <sbxprop.hxx>
|
2013-10-22 15:58:57 +03:00
|
|
|
#include <string.h>
|
2017-10-09 17:04:39 +03:00
|
|
|
#include <image.hxx>
|
2006-11-01 15:13:02 +00:00
|
|
|
#include <codegen.hxx>
|
2015-06-15 17:58:15 +09:00
|
|
|
#include <memory>
|
2014-07-16 17:41:15 +09:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiImage::SbiImage()
|
|
|
|
{
|
2015-02-27 11:22:50 +02:00
|
|
|
nFlags = SbiImageFlags::NONE;
|
2006-11-03 06:39:47 +00:00
|
|
|
nStringSize= 0;
|
|
|
|
nCodeSize = 0;
|
2006-11-01 15:13:02 +00:00
|
|
|
nLegacyCodeSize =
|
2000-09-18 15:18:56 +00:00
|
|
|
nDimBase = 0;
|
|
|
|
bInit =
|
2012-08-12 09:07:20 +09:00
|
|
|
bError = false;
|
2012-08-15 09:44:54 +09:00
|
|
|
bFirstInit = true;
|
2011-11-24 12:06:54 +01:00
|
|
|
eCharSet = osl_getThreadTextEncoding();
|
2013-10-05 16:44:30 +01:00
|
|
|
nStringIdx = 0;
|
|
|
|
nStringOff = 0;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SbiImage::~SbiImage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SbiImage::Clear()
|
|
|
|
{
|
2018-04-25 14:51:38 +02:00
|
|
|
mvStringOffsets.clear();
|
2018-04-29 18:40:45 +02:00
|
|
|
pStrings.reset();
|
|
|
|
pCode.reset();
|
|
|
|
pLegacyPCode.reset();
|
2015-02-27 11:22:50 +02:00
|
|
|
nFlags = SbiImageFlags::NONE;
|
2006-11-03 06:39:47 +00:00
|
|
|
nStringSize= 0;
|
2006-11-01 15:13:02 +00:00
|
|
|
nLegacyCodeSize = 0;
|
2000-09-18 15:18:56 +00:00
|
|
|
nCodeSize = 0;
|
2011-11-24 12:06:54 +01:00
|
|
|
eCharSet = osl_getThreadTextEncoding();
|
2000-09-18 15:18:56 +00:00
|
|
|
nDimBase = 0;
|
2012-08-12 09:07:20 +09:00
|
|
|
bError = false;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 19:13:19 +02:00
|
|
|
static bool SbiGood( SvStream const & r )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2017-11-22 10:02:51 +00:00
|
|
|
return r.good();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Open Record
|
2018-09-15 19:13:19 +02:00
|
|
|
static sal_uInt64 SbiOpenRecord( SvStream& r, FileOffset nSignature, sal_uInt16 nElem )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2015-12-31 10:58:37 +01:00
|
|
|
sal_uInt64 nPos = r.Tell();
|
2016-02-24 14:43:38 +01:00
|
|
|
r.WriteUInt16( static_cast<sal_uInt16>( nSignature ) )
|
|
|
|
.WriteInt32( 0 ).WriteUInt16( nElem );
|
2000-09-18 15:18:56 +00:00
|
|
|
return nPos;
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Close Record
|
2018-09-15 19:13:19 +02:00
|
|
|
static void SbiCloseRecord( SvStream& r, sal_uInt64 nOff )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2015-12-31 10:58:37 +01:00
|
|
|
sal_uInt64 nPos = r.Tell();
|
2000-09-18 15:18:56 +00:00
|
|
|
r.Seek( nOff + 2 );
|
2015-01-16 08:07:06 +02:00
|
|
|
r.WriteInt32(nPos - nOff - 8 );
|
2000-09-18 15:18:56 +00:00
|
|
|
r.Seek( nPos );
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:25:15 +02:00
|
|
|
constexpr sal_uInt32 nUnicodeDataMagicNumber = 0x556E6920; // "Uni " BE
|
2020-01-01 13:54:05 +03:00
|
|
|
|
|
|
|
static bool GetToUnicodePoolData(SvStream& r, sal_uInt64 nLen, sal_uInt64 nNext)
|
|
|
|
{
|
|
|
|
const auto nPos = r.Tell();
|
|
|
|
// Check space for legacy data, magic number and Unicode data
|
|
|
|
bool bResult = nPos + nLen + sizeof(sal_uInt32) + nLen * sizeof(sal_Unicode) <= nNext;
|
|
|
|
if (bResult)
|
|
|
|
{
|
|
|
|
r.SeekRel(nLen); // Skip legacy data
|
|
|
|
sal_uInt32 nMagic = 0;
|
|
|
|
r.ReadUInt32(nMagic);
|
|
|
|
if (nMagic != nUnicodeDataMagicNumber)
|
|
|
|
{
|
|
|
|
r.Seek(nPos); // return
|
|
|
|
bResult = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
2012-08-15 09:44:54 +09:00
|
|
|
bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
|
2006-11-01 15:13:02 +00:00
|
|
|
{
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt16 nSign, nCount;
|
|
|
|
sal_uInt32 nLen, nOff;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
Clear();
|
2009-04-25 00:18:20 +00:00
|
|
|
// Read Master-Record
|
2014-02-05 10:41:04 +02:00
|
|
|
r.ReadUInt16( nSign ).ReadUInt32( nLen ).ReadUInt16( nCount );
|
2015-12-31 10:58:37 +01:00
|
|
|
sal_uInt64 nLast = r.Tell() + nLen;
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt32 nCharSet; // System charset
|
|
|
|
sal_uInt32 lDimBase;
|
|
|
|
sal_uInt16 nReserved1;
|
|
|
|
sal_uInt32 nReserved2;
|
|
|
|
sal_uInt32 nReserved3;
|
2012-09-07 04:59:11 +09:00
|
|
|
bool bBadVer = false;
|
2016-02-24 14:43:38 +01:00
|
|
|
if( nSign == static_cast<sal_uInt16>( FileOffset::Module ) )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2015-02-27 11:22:50 +02:00
|
|
|
sal_uInt16 nTmpFlags;
|
2014-02-05 10:41:04 +02:00
|
|
|
r.ReadUInt32( nVersion ).ReadUInt32( nCharSet ).ReadUInt32( lDimBase )
|
2015-02-27 11:22:50 +02:00
|
|
|
.ReadUInt16( nTmpFlags ).ReadUInt16( nReserved1 ).ReadUInt32( nReserved2 ).ReadUInt32( nReserved3 );
|
|
|
|
nFlags = static_cast<SbiImageFlags>(nTmpFlags);
|
2013-07-01 10:33:48 -05:00
|
|
|
eCharSet = nCharSet;
|
2001-08-07 10:20:11 +00:00
|
|
|
eCharSet = GetSOLoadTextEncoding( eCharSet );
|
2012-09-07 04:59:11 +09:00
|
|
|
bBadVer = ( nVersion > B_CURVERSION );
|
2018-01-12 20:29:14 +01:00
|
|
|
nDimBase = static_cast<sal_uInt16>(lDimBase);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2006-11-01 15:13:02 +00:00
|
|
|
bool bLegacy = ( nVersion < B_EXT_IMG_VERSION );
|
|
|
|
|
2015-12-31 10:58:37 +01:00
|
|
|
sal_uInt64 nNext;
|
2000-09-18 15:18:56 +00:00
|
|
|
while( ( nNext = r.Tell() ) < nLast )
|
|
|
|
{
|
|
|
|
|
2014-02-05 10:41:04 +02:00
|
|
|
r.ReadUInt16( nSign ).ReadUInt32( nLen ).ReadUInt16( nCount );
|
2000-09-18 15:18:56 +00:00
|
|
|
nNext += nLen + 8;
|
2017-06-05 15:02:51 +02:00
|
|
|
if( r.GetError() == ERRCODE_NONE )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2016-02-24 14:43:38 +01:00
|
|
|
switch( static_cast<FileOffset>( nSign ) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2016-02-24 14:43:38 +01:00
|
|
|
case FileOffset::Name:
|
2012-01-06 08:50:03 +00:00
|
|
|
aName = r.ReadUniOrByteString(eCharSet);
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
2016-02-24 14:43:38 +01:00
|
|
|
case FileOffset::Comment:
|
2012-01-06 08:50:03 +00:00
|
|
|
aComment = r.ReadUniOrByteString(eCharSet );
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
2016-02-24 14:43:38 +01:00
|
|
|
case FileOffset::Source:
|
2003-04-23 15:55:53 +00:00
|
|
|
{
|
2012-01-06 08:50:03 +00:00
|
|
|
aOUSource = r.ReadUniOrByteString(eCharSet);
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
2003-04-23 15:55:53 +00:00
|
|
|
}
|
2016-02-24 14:43:38 +01:00
|
|
|
case FileOffset::ExtSource:
|
2005-05-18 12:07:10 +00:00
|
|
|
{
|
2014-11-05 16:33:55 +00:00
|
|
|
//assuming an empty string with just the lead 32bit/16bit len indicator
|
|
|
|
const size_t nMinStringSize = (eCharSet == RTL_TEXTENCODING_UNICODE) ? 4 : 2;
|
2015-12-31 10:58:37 +01:00
|
|
|
const sal_uInt64 nMaxStrings = r.remainingSize() / nMinStringSize;
|
2014-11-05 16:33:55 +00:00
|
|
|
if (nCount > nMaxStrings)
|
|
|
|
{
|
|
|
|
SAL_WARN("basic", "Parsing error: " << nMaxStrings <<
|
|
|
|
" max possible entries, but " << nCount << " claimed, truncating");
|
|
|
|
nCount = nMaxStrings;
|
|
|
|
}
|
|
|
|
for( sal_uInt16 j = 0; j < nCount; ++j)
|
2005-05-18 12:07:10 +00:00
|
|
|
{
|
2012-11-06 23:34:23 -06:00
|
|
|
aOUSource += r.ReadUniOrByteString(eCharSet);
|
2005-05-18 12:07:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-02-24 14:43:38 +01:00
|
|
|
case FileOffset::PCode:
|
2000-09-18 15:18:56 +00:00
|
|
|
if( bBadVer ) break;
|
2018-04-29 18:40:45 +02:00
|
|
|
pCode.reset(new char[ nLen ]);
|
2006-11-01 15:13:02 +00:00
|
|
|
nCodeSize = nLen;
|
2018-04-29 18:40:45 +02:00
|
|
|
r.ReadBytes(pCode.get(), nCodeSize);
|
2006-11-01 15:13:02 +00:00
|
|
|
if ( bLegacy )
|
|
|
|
{
|
2018-01-12 20:29:14 +01:00
|
|
|
nLegacyCodeSize = static_cast<sal_uInt16>(nCodeSize);
|
2018-04-29 18:40:45 +02:00
|
|
|
pLegacyPCode = std::move(pCode);
|
2006-11-01 15:13:02 +00:00
|
|
|
|
2018-04-29 18:40:45 +02:00
|
|
|
PCodeBuffConvertor< sal_uInt16, sal_uInt32 > aLegacyToNew( reinterpret_cast<sal_uInt8*>(pLegacyPCode.get()), nLegacyCodeSize );
|
2006-11-01 15:13:02 +00:00
|
|
|
aLegacyToNew.convert();
|
2018-04-29 18:40:45 +02:00
|
|
|
pCode.reset(reinterpret_cast<char*>(aLegacyToNew.GetBuffer()));
|
2006-11-01 15:13:02 +00:00
|
|
|
nCodeSize = aLegacyToNew.GetSize();
|
|
|
|
// we don't release the legacy buffer
|
2017-11-13 00:20:20 +01:00
|
|
|
// right now, that's because the module
|
2006-11-01 15:13:02 +00:00
|
|
|
// needs it to fix up the method
|
|
|
|
// nStart members. When that is done
|
|
|
|
// the module can release the buffer
|
|
|
|
// or it can wait until this routine
|
|
|
|
// is called again or when this class // destructs all of which will trigger
|
|
|
|
// release of the buffer.
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
2016-02-24 14:43:38 +01:00
|
|
|
case FileOffset::Publics:
|
|
|
|
case FileOffset::PoolDir:
|
|
|
|
case FileOffset::SymPool:
|
|
|
|
case FileOffset::LineRanges:
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
2016-02-24 14:43:38 +01:00
|
|
|
case FileOffset::StringPool:
|
2014-11-14 10:19:24 +00:00
|
|
|
{
|
2020-01-01 13:54:05 +03:00
|
|
|
// the data layout is: nCount of 32-bit offsets into both legacy 1-byte char stream
|
|
|
|
// and resulting char buffer (1:1 correspondence assumed; 16 of 32 bits used);
|
|
|
|
// 32-bit length N of following 1-byte char stream (16 bits used); N bytes of 1-byte
|
|
|
|
// char stream; then optional magic number and stream of N sal_Unicode characters.
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
if( bBadVer ) break;
|
2014-11-14 10:19:24 +00:00
|
|
|
//assuming an empty string with just the lead 32bit len indicator
|
2015-12-31 10:58:37 +01:00
|
|
|
const sal_uInt64 nMinStringSize = 4;
|
|
|
|
const sal_uInt64 nMaxStrings = r.remainingSize() / nMinStringSize;
|
2014-11-14 10:19:24 +00:00
|
|
|
if (nCount > nMaxStrings)
|
|
|
|
{
|
|
|
|
SAL_WARN("basic", "Parsing error: " << nMaxStrings <<
|
|
|
|
" max possible entries, but " << nCount << " claimed, truncating");
|
|
|
|
nCount = nMaxStrings;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
MakeStrings( nCount );
|
2018-04-25 14:51:38 +02:00
|
|
|
for( size_t i = 0; i < mvStringOffsets.size() && SbiGood( r ); i++ )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2014-02-05 10:41:04 +02:00
|
|
|
r.ReadUInt32( nOff );
|
2018-04-25 14:51:38 +02:00
|
|
|
mvStringOffsets[ i ] = static_cast<sal_uInt16>(nOff);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2014-02-05 10:41:04 +02:00
|
|
|
r.ReadUInt32( nLen );
|
2000-09-18 15:18:56 +00:00
|
|
|
if( SbiGood( r ) )
|
|
|
|
{
|
2018-04-29 18:40:45 +02:00
|
|
|
pStrings.reset(new sal_Unicode[ nLen ]);
|
2018-01-12 20:29:14 +01:00
|
|
|
nStringSize = static_cast<sal_uInt16>(nLen);
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2020-01-01 13:54:05 +03:00
|
|
|
if (GetToUnicodePoolData(r, nLen, nNext))
|
|
|
|
{
|
|
|
|
OUString s = read_uInt16s_ToOUString(r, nLen);
|
|
|
|
memcpy(pStrings.get(), s.getStr(), s.getLength() * sizeof(sal_Unicode));
|
|
|
|
}
|
|
|
|
else
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2020-01-01 13:54:05 +03:00
|
|
|
std::unique_ptr<char[]> pByteStrings(new char[nLen]);
|
|
|
|
r.ReadBytes(pByteStrings.get(), nLen);
|
|
|
|
for (size_t j = 0; j < mvStringOffsets.size(); j++)
|
|
|
|
{
|
|
|
|
sal_uInt16 nOff2 = static_cast<sal_uInt16>(mvStringOffsets[j]);
|
|
|
|
OUString aStr(pByteStrings.get() + nOff2, strlen(pByteStrings.get() + nOff2), eCharSet);
|
|
|
|
memcpy(pStrings.get() + nOff2, aStr.getStr(), (aStr.getLength() + 1) * sizeof(sal_Unicode));
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
|
|
|
break;
|
2014-11-14 10:19:24 +00:00
|
|
|
}
|
2016-02-24 14:43:38 +01:00
|
|
|
case FileOffset::UserTypes:
|
2015-08-23 12:52:52 +01:00
|
|
|
{
|
|
|
|
//assuming an empty string with just the lead 32bit/16bit len indicator
|
|
|
|
const size_t nMinStringSize = (eCharSet == RTL_TEXTENCODING_UNICODE) ? 4 : 2;
|
2015-12-31 10:58:37 +01:00
|
|
|
const sal_uInt64 nMinRecordSize = nMinStringSize + sizeof(sal_Int16);
|
|
|
|
const sal_uInt64 nMaxRecords = r.remainingSize() / nMinRecordSize;
|
New identifier for save/open macro with user defined types
no version bump but B_USERTYPE defined
fix test from commit de26ef85 that should be nMaxRecords
tested full round trip on password protected document (ie. use binary storage)
master --(0)--> master --(1)--> libreoffice 4.4 --(2)--> master --(3)--> master
(0) in master, User type supported, big module supported
(1) in libreoffice 4.4, user type not supported, big module supported, no loss of code
(2) in master, user type not supported, big module not found, no loss of code
it is OK as libreoffice 4.4 saves to LegacyVersion
(3) in master, User type supported, big module supported (all is restored)
it is OK as module was saved with CURRENT_VERSION (see sbxmod.cxx)
Change-Id: I237cf7de70adf1a755be1bc30987b21c43b6ab35
Reviewed-on: https://gerrit.libreoffice.org/17871
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
2015-08-19 17:58:12 +02:00
|
|
|
if (nCount > nMaxRecords)
|
2015-08-23 12:52:52 +01:00
|
|
|
{
|
|
|
|
SAL_WARN("basic", "Parsing error: " << nMaxRecords <<
|
|
|
|
" max possible entries, but " << nCount << " claimed, truncating");
|
|
|
|
nCount = nMaxRecords;
|
|
|
|
}
|
2015-08-17 13:28:16 +02:00
|
|
|
|
|
|
|
// User defined types
|
|
|
|
for (sal_uInt16 i = 0; i < nCount; i++)
|
|
|
|
{
|
|
|
|
OUString aTypeName = r.ReadUniOrByteString(eCharSet);
|
|
|
|
|
2015-09-01 09:25:54 +01:00
|
|
|
sal_uInt16 nTypeMembers;
|
|
|
|
r.ReadUInt16(nTypeMembers);
|
|
|
|
|
2015-12-31 10:58:37 +01:00
|
|
|
const sal_uInt64 nMaxTypeMembers = r.remainingSize() / 8;
|
2015-09-01 09:25:54 +01:00
|
|
|
if (nTypeMembers > nMaxTypeMembers)
|
|
|
|
{
|
|
|
|
SAL_WARN("basic", "Parsing error: " << nMaxTypeMembers <<
|
|
|
|
" max possible entries, but " << nTypeMembers << " claimed, truncating");
|
|
|
|
nTypeMembers = nMaxTypeMembers;
|
|
|
|
}
|
2015-08-17 13:28:16 +02:00
|
|
|
|
|
|
|
SbxObject *pType = new SbxObject(aTypeName);
|
|
|
|
SbxArray *pTypeMembers = pType->GetProperties();
|
|
|
|
|
|
|
|
for (sal_uInt16 j = 0; j < nTypeMembers; j++)
|
|
|
|
{
|
|
|
|
OUString aMemberName = r.ReadUniOrByteString(eCharSet);
|
|
|
|
|
|
|
|
sal_Int16 aIntMemberType;
|
|
|
|
r.ReadInt16(aIntMemberType);
|
|
|
|
SbxDataType aMemberType = static_cast< SbxDataType > ( aIntMemberType );
|
|
|
|
|
|
|
|
SbxProperty *pTypeElem = new SbxProperty( aMemberName, aMemberType );
|
|
|
|
|
|
|
|
sal_uInt32 aIntFlag;
|
|
|
|
r.ReadUInt32(aIntFlag);
|
|
|
|
SbxFlagBits nElemFlags = static_cast< SbxFlagBits > ( aIntFlag );
|
|
|
|
|
|
|
|
pTypeElem->SetFlags(nElemFlags);
|
|
|
|
|
|
|
|
sal_Int16 hasObject;
|
|
|
|
r.ReadInt16(hasObject);
|
|
|
|
|
|
|
|
if (hasObject == 1)
|
|
|
|
{
|
|
|
|
if(aMemberType == SbxOBJECT)
|
|
|
|
{
|
|
|
|
// nested user defined types
|
|
|
|
// declared before use, so it is ok to reference it by name on load
|
|
|
|
OUString aNestedTypeName = r.ReadUniOrByteString(eCharSet);
|
2016-05-21 16:22:07 +02:00
|
|
|
SbxObject* pNestedTypeObj = static_cast< SbxObject* >( rTypes->Find( aNestedTypeName, SbxClassType::Object ) );
|
2015-08-17 13:28:16 +02:00
|
|
|
if (pNestedTypeObj)
|
|
|
|
{
|
|
|
|
SbxObject* pCloneObj = cloneTypeObjectImpl( *pNestedTypeObj );
|
|
|
|
pTypeElem->PutObject( pCloneObj );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// an array
|
|
|
|
SbxDimArray* pArray = new SbxDimArray();
|
|
|
|
|
|
|
|
sal_Int16 isFixedSize;
|
|
|
|
r.ReadInt16(isFixedSize);
|
|
|
|
if (isFixedSize == 1)
|
|
|
|
pArray->setHasFixedSize( true );
|
|
|
|
|
|
|
|
sal_Int32 nDims;
|
|
|
|
r.ReadInt32(nDims);
|
|
|
|
for (sal_Int32 d = 0; d < nDims; d++)
|
|
|
|
{
|
|
|
|
sal_Int32 lBound;
|
|
|
|
sal_Int32 uBound;
|
|
|
|
r.ReadInt32(lBound).ReadInt32(uBound);
|
|
|
|
pArray->unoAddDim32(lBound, uBound);
|
|
|
|
}
|
|
|
|
|
|
|
|
pTypeElem->PutObject( pArray );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-09 13:06:03 +03:00
|
|
|
pTypeMembers->Insert32( pTypeElem, pTypeMembers->Count32() );
|
2015-08-17 13:28:16 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-21 16:22:07 +02:00
|
|
|
pType->Remove( "Name", SbxClassType::DontCare );
|
|
|
|
pType->Remove( "Parent", SbxClassType::DontCare );
|
2015-08-17 13:28:16 +02:00
|
|
|
|
|
|
|
AddType(pType);
|
|
|
|
}
|
|
|
|
break;
|
2015-08-23 12:52:52 +01:00
|
|
|
}
|
2016-02-24 14:43:38 +01:00
|
|
|
case FileOffset::ModEnd:
|
2000-09-18 15:18:56 +00:00
|
|
|
goto done;
|
|
|
|
default:
|
|
|
|
break;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
else
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2000-09-18 15:18:56 +00:00
|
|
|
break;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
r.Seek( nNext );
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
r.Seek( nLast );
|
|
|
|
if( !SbiGood( r ) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2012-08-12 09:07:20 +09:00
|
|
|
bError = true;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2012-08-15 09:44:54 +09:00
|
|
|
return !bError;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2012-08-15 09:44:54 +09:00
|
|
|
bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-11-01 15:13:02 +00:00
|
|
|
bool bLegacy = ( nVer < B_EXT_IMG_VERSION );
|
|
|
|
|
|
|
|
// detect if old code exceeds legacy limits
|
|
|
|
// if so, then disallow save
|
|
|
|
if ( bLegacy && ExceedsLegacyLimits() )
|
|
|
|
{
|
|
|
|
SbiImage aEmptyImg;
|
|
|
|
aEmptyImg.aName = aName;
|
|
|
|
aEmptyImg.Save( r, B_LEGACYVERSION );
|
2012-08-15 09:44:54 +09:00
|
|
|
return true;
|
2006-11-01 15:13:02 +00:00
|
|
|
}
|
2009-04-25 00:18:20 +00:00
|
|
|
// First of all the header
|
2016-02-24 14:43:38 +01:00
|
|
|
sal_uInt64 nStart = SbiOpenRecord( r, FileOffset::Module, 1 );
|
2015-12-31 10:58:37 +01:00
|
|
|
sal_uInt64 nPos;
|
2001-08-07 10:20:11 +00:00
|
|
|
|
|
|
|
eCharSet = GetSOStoreTextEncoding( eCharSet );
|
2006-11-01 15:13:02 +00:00
|
|
|
if ( bLegacy )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2014-09-25 20:16:26 +02:00
|
|
|
r.WriteInt32( B_LEGACYVERSION );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2006-11-01 15:13:02 +00:00
|
|
|
else
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2014-09-25 20:16:26 +02:00
|
|
|
r.WriteInt32( B_CURVERSION );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2014-09-25 20:16:26 +02:00
|
|
|
r .WriteInt32( eCharSet )
|
|
|
|
.WriteInt32( nDimBase )
|
2015-02-27 11:22:50 +02:00
|
|
|
.WriteInt16( static_cast<sal_uInt16>(nFlags) )
|
2015-01-16 08:07:06 +02:00
|
|
|
.WriteInt16( 0 )
|
2014-09-25 20:16:26 +02:00
|
|
|
.WriteInt32( 0 )
|
|
|
|
.WriteInt32( 0 );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
// Name?
|
2012-11-06 23:34:23 -06:00
|
|
|
if( !aName.isEmpty() && SbiGood( r ) )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2016-02-24 14:43:38 +01:00
|
|
|
nPos = SbiOpenRecord( r, FileOffset::Name, 1 );
|
2011-12-21 10:45:54 +00:00
|
|
|
r.WriteUniOrByteString( aName, eCharSet );
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiCloseRecord( r, nPos );
|
|
|
|
}
|
2009-04-25 00:18:20 +00:00
|
|
|
// Comment?
|
2012-11-06 23:34:23 -06:00
|
|
|
if( !aComment.isEmpty() && SbiGood( r ) )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2016-02-24 14:43:38 +01:00
|
|
|
nPos = SbiOpenRecord( r, FileOffset::Comment, 1 );
|
2011-12-21 10:45:54 +00:00
|
|
|
r.WriteUniOrByteString( aComment, eCharSet );
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiCloseRecord( r, nPos );
|
|
|
|
}
|
|
|
|
// Source?
|
2011-12-10 13:35:14 -02:00
|
|
|
if( !aOUSource.isEmpty() && SbiGood( r ) )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2016-02-24 14:43:38 +01:00
|
|
|
nPos = SbiOpenRecord( r, FileOffset::Source, 1 );
|
2013-07-01 10:33:48 -05:00
|
|
|
r.WriteUniOrByteString( aOUSource, eCharSet );
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiCloseRecord( r, nPos );
|
|
|
|
}
|
2009-04-25 00:18:20 +00:00
|
|
|
// Binary data?
|
2000-09-18 15:18:56 +00:00
|
|
|
if( pCode && SbiGood( r ) )
|
|
|
|
{
|
2016-02-24 14:43:38 +01:00
|
|
|
nPos = SbiOpenRecord( r, FileOffset::PCode, 1 );
|
2006-11-01 15:13:02 +00:00
|
|
|
if ( bLegacy )
|
|
|
|
{
|
2018-04-29 18:40:45 +02:00
|
|
|
PCodeBuffConvertor< sal_uInt32, sal_uInt16 > aNewToLegacy( reinterpret_cast<sal_uInt8*>(pCode.get()), nCodeSize );
|
2006-11-01 15:13:02 +00:00
|
|
|
aNewToLegacy.convert();
|
2018-04-29 18:40:45 +02:00
|
|
|
pLegacyPCode.reset(reinterpret_cast<char*>(aNewToLegacy.GetBuffer()));
|
2006-11-01 15:13:02 +00:00
|
|
|
nLegacyCodeSize = aNewToLegacy.GetSize();
|
2018-04-29 18:40:45 +02:00
|
|
|
r.WriteBytes(pLegacyPCode.get(), nLegacyCodeSize);
|
2006-11-01 15:13:02 +00:00
|
|
|
}
|
|
|
|
else
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2018-04-29 18:40:45 +02:00
|
|
|
r.WriteBytes(pCode.get(), nCodeSize);
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiCloseRecord( r, nPos );
|
|
|
|
}
|
|
|
|
// String-Pool?
|
2018-04-25 14:51:38 +02:00
|
|
|
if( !mvStringOffsets.empty() )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2018-04-25 14:51:38 +02:00
|
|
|
nPos = SbiOpenRecord( r, FileOffset::StringPool, mvStringOffsets.size() );
|
2009-04-25 00:18:20 +00:00
|
|
|
// For every String:
|
2011-01-10 14:40:57 +01:00
|
|
|
// sal_uInt32 Offset of the Strings in the Stringblock
|
2018-04-25 14:51:38 +02:00
|
|
|
for( size_t i = 0; i < mvStringOffsets.size() && SbiGood( r ); i++ )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2018-04-25 14:51:38 +02:00
|
|
|
r.WriteUInt32( mvStringOffsets[ i ] );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2009-04-25 00:18:20 +00:00
|
|
|
// Then the String-Block
|
2015-06-15 17:58:15 +09:00
|
|
|
std::unique_ptr<char[]> pByteStrings(new char[ nStringSize ]);
|
2018-04-25 14:51:38 +02:00
|
|
|
for( size_t i = 0; i < mvStringOffsets.size(); i++ )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2018-04-25 14:51:38 +02:00
|
|
|
sal_uInt16 nOff = static_cast<sal_uInt16>(mvStringOffsets[ i ]);
|
2018-04-29 18:40:45 +02:00
|
|
|
OString aStr(OUStringToOString(OUString(pStrings.get() + nOff), eCharSet));
|
2014-07-16 17:41:15 +09:00
|
|
|
memcpy( pByteStrings.get() + nOff, aStr.getStr(), (aStr.getLength() + 1) * sizeof( char ) );
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2014-09-25 20:19:30 +02:00
|
|
|
r.WriteUInt32( nStringSize );
|
2016-06-03 14:45:59 +02:00
|
|
|
r.WriteBytes(pByteStrings.get(), nStringSize);
|
2014-07-16 17:41:15 +09:00
|
|
|
pByteStrings.reset();
|
2020-01-01 13:54:05 +03:00
|
|
|
|
|
|
|
// Now write magic number and store the same data in UTF-16; this is backward compatible:
|
|
|
|
// old readers will not read this data after having read legacy data, and will proceed
|
|
|
|
// straight to the end of the record. So no version restriction here.
|
|
|
|
r.WriteUInt32(nUnicodeDataMagicNumber);
|
|
|
|
write_uInt16s_FromOUString(r, OUString(pStrings.get(), nStringSize));
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiCloseRecord( r, nPos );
|
|
|
|
}
|
2015-08-17 13:28:16 +02:00
|
|
|
// User defined types
|
2017-01-25 12:03:58 +02:00
|
|
|
if ( rTypes.is() )
|
2015-08-17 13:28:16 +02:00
|
|
|
{
|
2019-12-09 13:06:03 +03:00
|
|
|
sal_uInt32 nTypes = rTypes->Count32();
|
|
|
|
assert(nTypes <= std::numeric_limits<sal_uInt16>::max());
|
2015-08-18 13:40:42 +02:00
|
|
|
if (nTypes > 0 )
|
2015-08-17 13:28:16 +02:00
|
|
|
{
|
2019-12-09 13:06:03 +03:00
|
|
|
nPos = SbiOpenRecord( r, FileOffset::UserTypes, sal::static_int_cast<sal_uInt16>(nTypes) );
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2019-12-09 13:06:03 +03:00
|
|
|
for (sal_uInt32 i = 0; i < nTypes; i++)
|
2015-08-18 13:40:42 +02:00
|
|
|
{
|
2019-12-09 13:06:03 +03:00
|
|
|
SbxObject* pType = static_cast< SbxObject* > ( rTypes->Get32(i) );
|
2015-08-18 13:40:42 +02:00
|
|
|
OUString aTypeName = pType->GetClassName();
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2015-08-18 13:40:42 +02:00
|
|
|
r.WriteUniOrByteString( aTypeName, eCharSet );
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2015-08-18 13:40:42 +02:00
|
|
|
SbxArray *pTypeMembers = pType->GetProperties();
|
2019-12-09 13:06:03 +03:00
|
|
|
sal_uInt32 nTypeMembers = pTypeMembers->Count32();
|
|
|
|
assert(nTypeMembers <= std::numeric_limits<sal_uInt16>::max());
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2019-12-09 13:06:03 +03:00
|
|
|
r.WriteInt16(sal::static_int_cast<sal_uInt16>(nTypeMembers));
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2019-12-09 13:06:03 +03:00
|
|
|
for (sal_uInt32 j = 0; j < nTypeMembers; j++)
|
2015-08-18 13:40:42 +02:00
|
|
|
{
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2019-12-09 13:06:03 +03:00
|
|
|
SbxProperty* pTypeElem = static_cast< SbxProperty* > ( pTypeMembers->Get32(j) );
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2018-10-23 07:36:33 +02:00
|
|
|
const OUString& aElemName = pTypeElem->GetName();
|
2015-08-18 13:40:42 +02:00
|
|
|
r.WriteUniOrByteString( aElemName, eCharSet );
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2015-08-18 13:40:42 +02:00
|
|
|
SbxDataType dataType = pTypeElem->GetType();
|
|
|
|
r.WriteInt16(dataType);
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2015-08-18 13:40:42 +02:00
|
|
|
SbxFlagBits nElemFlags = pTypeElem->GetFlags();
|
|
|
|
r.WriteUInt32(static_cast< sal_uInt32 > (nElemFlags) );
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2015-08-18 13:40:42 +02:00
|
|
|
SbxBase* pElemObject = pTypeElem->GetObject();
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2015-08-18 13:40:42 +02:00
|
|
|
if (pElemObject)
|
2015-08-17 13:28:16 +02:00
|
|
|
{
|
2015-08-18 13:40:42 +02:00
|
|
|
r.WriteInt16(1); // has elem Object
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2015-08-18 13:40:42 +02:00
|
|
|
if( dataType == SbxOBJECT )
|
|
|
|
{
|
|
|
|
// nested user defined types
|
|
|
|
// declared before use, so it is ok to reference it by name on load
|
|
|
|
SbxObject* pNestedType = static_cast< SbxObject* > ( pElemObject );
|
|
|
|
r.WriteUniOrByteString( pNestedType->GetClassName(), eCharSet );
|
|
|
|
}
|
2015-08-17 13:28:16 +02:00
|
|
|
else
|
2015-08-18 13:40:42 +02:00
|
|
|
{
|
|
|
|
// an array
|
|
|
|
SbxDimArray* pArray = static_cast< SbxDimArray* > ( pElemObject );
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2015-08-18 13:40:42 +02:00
|
|
|
bool bFixedSize = pArray->hasFixedSize();
|
|
|
|
if (bFixedSize)
|
|
|
|
r.WriteInt16(1);
|
|
|
|
else
|
|
|
|
r.WriteInt16(0);
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2019-12-09 13:06:03 +03:00
|
|
|
sal_Int32 nDims = pArray->GetDims32();
|
2015-08-18 13:40:42 +02:00
|
|
|
r.WriteInt32(nDims);
|
|
|
|
|
|
|
|
for (sal_Int32 d = 0; d < nDims; d++)
|
|
|
|
{
|
|
|
|
sal_Int32 lBound;
|
|
|
|
sal_Int32 uBound;
|
|
|
|
pArray->GetDim32(d, lBound, uBound);
|
|
|
|
r.WriteInt32(lBound).WriteInt32(uBound);
|
|
|
|
}
|
2015-08-17 13:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-18 13:40:42 +02:00
|
|
|
else
|
|
|
|
r.WriteInt16(0); // no elem Object
|
2015-08-17 13:28:16 +02:00
|
|
|
|
2015-08-18 13:40:42 +02:00
|
|
|
}
|
2015-08-17 13:28:16 +02:00
|
|
|
}
|
2019-02-08 09:27:38 +02:00
|
|
|
SbiCloseRecord( r, nPos );
|
2015-08-17 13:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-25 00:18:20 +00:00
|
|
|
// Set overall length
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiCloseRecord( r, nStart );
|
|
|
|
if( !SbiGood( r ) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2012-08-12 09:07:20 +09:00
|
|
|
bError = true;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2012-08-15 09:44:54 +09:00
|
|
|
return !bError;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SbiImage::MakeStrings( short nSize )
|
|
|
|
{
|
2006-11-03 06:39:47 +00:00
|
|
|
nStringIdx = 0;
|
|
|
|
nStringOff = 0;
|
2000-09-18 15:18:56 +00:00
|
|
|
nStringSize = 1024;
|
2018-04-29 18:40:45 +02:00
|
|
|
pStrings.reset( new sal_Unicode[ nStringSize ]);
|
2018-04-25 14:51:38 +02:00
|
|
|
mvStringOffsets.resize(nSize);
|
2019-05-27 10:58:19 +02:00
|
|
|
if (nSize != 0) {
|
|
|
|
memset( mvStringOffsets.data(), 0, nSize * sizeof( sal_uInt32 ) );
|
|
|
|
}
|
2018-04-29 18:40:45 +02:00
|
|
|
memset( pStrings.get(), 0, nStringSize * sizeof( sal_Unicode ) );
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Add a string to StringPool. The String buffer is dynamically
|
|
|
|
// growing in 1K-Steps
|
2012-11-06 23:34:23 -06:00
|
|
|
void SbiImage::AddString( const OUString& r )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2018-04-25 14:51:38 +02:00
|
|
|
if( nStringIdx >= short(mvStringOffsets.size()) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2012-08-12 09:07:20 +09:00
|
|
|
bError = true;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2020-04-18 14:35:43 +02:00
|
|
|
if( bError )
|
|
|
|
return;
|
|
|
|
|
|
|
|
sal_Int32 len = r.getLength() + 1;
|
|
|
|
sal_uInt32 needed = nStringOff + len;
|
|
|
|
if( needed > 0xFFFFFF00 )
|
|
|
|
{
|
|
|
|
bError = true; // out of mem!
|
|
|
|
}
|
|
|
|
else if( needed > nStringSize )
|
|
|
|
{
|
|
|
|
sal_uInt32 nNewLen = needed + 1024;
|
|
|
|
nNewLen &= 0xFFFFFC00; // trim to 1K border
|
|
|
|
std::unique_ptr<sal_Unicode[]> p(new sal_Unicode[nNewLen]);
|
|
|
|
memcpy( p.get(), pStrings.get(), nStringSize * sizeof( sal_Unicode ) );
|
|
|
|
pStrings = std::move(p);
|
|
|
|
nStringSize = sal::static_int_cast< sal_uInt16 >(nNewLen);
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
if( !bError )
|
|
|
|
{
|
2020-04-18 14:35:43 +02:00
|
|
|
mvStringOffsets[ nStringIdx++ ] = nStringOff;
|
|
|
|
memcpy( pStrings.get() + nStringOff, r.getStr(), len * sizeof( sal_Unicode ) );
|
|
|
|
nStringOff = nStringOff + len;
|
|
|
|
// Last String? The update the size of the buffer
|
|
|
|
if( nStringIdx >= short(mvStringOffsets.size()) )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2020-04-18 14:35:43 +02:00
|
|
|
nStringSize = nStringOff;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Add code block
|
|
|
|
// The block was fetched by the compiler from class SbBuffer and
|
|
|
|
// is already created with new. Additionally it contains all Integers
|
|
|
|
// in Big Endian format, so can be directly read/written.
|
2018-04-29 18:40:45 +02:00
|
|
|
void SbiImage::AddCode( std::unique_ptr<char[]> p, sal_uInt32 s )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2018-04-29 18:40:45 +02:00
|
|
|
pCode = std::move(p);
|
2000-09-18 15:18:56 +00:00
|
|
|
nCodeSize = s;
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Add user type
|
2017-07-20 10:08:03 +02:00
|
|
|
void SbiImage::AddType(SbxObject const * pObject)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2017-01-25 12:03:58 +02:00
|
|
|
if( !rTypes.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2004-11-15 15:34:02 +00:00
|
|
|
rTypes = new SbxArray;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
SbxObject *pCopyObject = new SbxObject(*pObject);
|
2019-12-09 13:06:03 +03:00
|
|
|
rTypes->Insert32 (pCopyObject,rTypes->Count32());
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2004-11-15 15:34:02 +00:00
|
|
|
void SbiImage::AddEnum(SbxObject* pObject) // Register enum type
|
|
|
|
{
|
2017-01-25 12:03:58 +02:00
|
|
|
if( !rEnums.is() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2004-11-15 15:34:02 +00:00
|
|
|
rEnums = new SbxArray;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2019-12-09 13:06:03 +03:00
|
|
|
rEnums->Insert32( pObject, rEnums->Count32() );
|
2004-11-15 15:34:02 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Note: IDs start with 1
|
2012-11-06 23:34:23 -06:00
|
|
|
OUString SbiImage::GetString( short nId ) const
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2018-04-25 14:51:38 +02:00
|
|
|
if( nId && nId <= short(mvStringOffsets.size()) )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2018-04-25 14:51:38 +02:00
|
|
|
sal_uInt32 nOff = mvStringOffsets[ nId - 1 ];
|
2018-04-29 18:40:45 +02:00
|
|
|
sal_Unicode* pStr = pStrings.get() + nOff;
|
2005-03-29 10:47:59 +00:00
|
|
|
|
|
|
|
// #i42467: Special treatment for vbNullChar
|
|
|
|
if( *pStr == 0 )
|
|
|
|
{
|
2018-04-25 14:51:38 +02:00
|
|
|
sal_uInt32 nNextOff = (nId < short(mvStringOffsets.size())) ? mvStringOffsets[ nId ] : nStringOff;
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt32 nLen = nNextOff - nOff - 1;
|
2005-03-29 10:47:59 +00:00
|
|
|
if( nLen == 1 )
|
|
|
|
{
|
2020-06-26 08:37:08 +02:00
|
|
|
return OUString( u'\0');
|
2005-03-29 10:47:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-11-06 23:34:23 -06:00
|
|
|
{
|
|
|
|
return OUString(pStr);
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2012-11-06 23:34:23 -06:00
|
|
|
return OUString();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 15:36:41 +02:00
|
|
|
const SbxObject* SbiImage::FindType (const OUString& aTypeName) const
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2017-01-25 12:03:58 +02:00
|
|
|
return rTypes.is() ? static_cast<SbxObject*>(rTypes->Find(aTypeName,SbxClassType::Object)) : nullptr;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt16 SbiImage::CalcLegacyOffset( sal_Int32 nOffset )
|
2006-11-01 15:13:02 +00:00
|
|
|
{
|
2018-04-29 18:40:45 +02:00
|
|
|
return SbiCodeGen::calcLegacyOffSet( reinterpret_cast<sal_uInt8*>(pCode.get()), nOffset ) ;
|
2006-11-01 15:13:02 +00:00
|
|
|
}
|
2009-04-25 00:18:20 +00:00
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt32 SbiImage::CalcNewOffset( sal_Int16 nOffset )
|
2006-11-01 15:13:02 +00:00
|
|
|
{
|
2018-04-29 18:40:45 +02:00
|
|
|
return SbiCodeGen::calcNewOffSet( reinterpret_cast<sal_uInt8*>(pLegacyPCode.get()), nOffset ) ;
|
2006-11-01 15:13:02 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
void SbiImage::ReleaseLegacyBuffer()
|
2006-11-01 15:13:02 +00:00
|
|
|
{
|
2018-04-29 18:40:45 +02:00
|
|
|
pLegacyPCode.reset();
|
2006-11-01 15:13:02 +00:00
|
|
|
nLegacyCodeSize = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-15 09:44:54 +09:00
|
|
|
bool SbiImage::ExceedsLegacyLimits()
|
2006-11-01 15:13:02 +00:00
|
|
|
{
|
2016-08-03 10:18:16 +05:30
|
|
|
return ( nStringSize > 0xFF00 ) || ( CalcLegacyOffset( nCodeSize ) > 0xFF00 );
|
2006-11-01 15:13:02 +00:00
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|