2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 10:45:08 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2005-09-29 11:39:45 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2005-09-29 11:39:45 +00:00
|
|
|
*
|
2008-04-11 10:45:08 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 10:45:08 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 10:45:08 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 10:45:08 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-11 10:45:08 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 08:59:37 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_basic.hxx"
|
2000-09-18 15:18:56 +00:00
|
|
|
#include <tools/stream.hxx>
|
2001-08-07 10:20:11 +00:00
|
|
|
#include <tools/tenccvt.hxx>
|
2007-06-27 13:18:06 +00:00
|
|
|
#include <basic/sbx.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
#include "sb.hxx"
|
|
|
|
#include <string.h> // memset() etc
|
|
|
|
#include "image.hxx"
|
2006-11-01 15:13:02 +00:00
|
|
|
#include <codegen.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiImage::SbiImage()
|
|
|
|
{
|
|
|
|
pStringOff = NULL;
|
|
|
|
pStrings = NULL;
|
|
|
|
pCode = NULL;
|
2006-11-01 15:13:02 +00:00
|
|
|
pLegacyPCode = NULL;
|
2006-11-03 06:39:47 +00:00
|
|
|
nFlags = 0;
|
|
|
|
nStrings = 0;
|
|
|
|
nStringSize= 0;
|
|
|
|
nCodeSize = 0;
|
2006-11-01 15:13:02 +00:00
|
|
|
nLegacyCodeSize =
|
2000-09-18 15:18:56 +00:00
|
|
|
nDimBase = 0;
|
|
|
|
bInit =
|
|
|
|
bError = FALSE;
|
2001-09-04 09:14:43 +00:00
|
|
|
bFirstInit = TRUE;
|
2000-09-18 15:18:56 +00:00
|
|
|
eCharSet = gsl_getSystemTextEncoding();
|
|
|
|
}
|
|
|
|
|
|
|
|
SbiImage::~SbiImage()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SbiImage::Clear()
|
|
|
|
{
|
2003-03-18 15:28:40 +00:00
|
|
|
delete[] pStringOff;
|
|
|
|
delete[] pStrings;
|
|
|
|
delete[] pCode;
|
2006-11-01 15:13:02 +00:00
|
|
|
ReleaseLegacyBuffer();
|
2000-09-18 15:18:56 +00:00
|
|
|
pStringOff = NULL;
|
|
|
|
pStrings = NULL;
|
|
|
|
pCode = NULL;
|
2006-11-03 06:39:47 +00:00
|
|
|
nFlags = 0;
|
|
|
|
nStrings = 0;
|
|
|
|
nStringSize= 0;
|
2006-11-01 15:13:02 +00:00
|
|
|
nLegacyCodeSize = 0;
|
2000-09-18 15:18:56 +00:00
|
|
|
nCodeSize = 0;
|
|
|
|
eCharSet = gsl_getSystemTextEncoding();
|
|
|
|
nDimBase = 0;
|
|
|
|
bError = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
2009-04-25 00:18:20 +00:00
|
|
|
* Service-Routines for Load/Store
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
BOOL SbiGood( SvStream& r )
|
|
|
|
{
|
|
|
|
return BOOL( !r.IsEof() && r.GetError() == SVSTREAM_OK );
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Open Record
|
2000-09-18 15:18:56 +00:00
|
|
|
ULONG SbiOpenRecord( SvStream& r, UINT16 nSignature, UINT16 nElem )
|
|
|
|
{
|
|
|
|
ULONG nPos = r.Tell();
|
|
|
|
r << nSignature << (INT32) 0 << nElem;
|
|
|
|
return nPos;
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Close Record
|
2000-09-18 15:18:56 +00:00
|
|
|
void SbiCloseRecord( SvStream& r, ULONG nOff )
|
|
|
|
{
|
|
|
|
ULONG nPos = r.Tell();
|
|
|
|
r.Seek( nOff + 2 );
|
|
|
|
r << (INT32) ( nPos - nOff - 8 );
|
|
|
|
r.Seek( nPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
2009-04-25 00:18:20 +00:00
|
|
|
* Load/Store
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// If the version number does not find, binary parts are omitted, but not
|
|
|
|
// source, comments and name
|
2000-09-18 15:18:56 +00:00
|
|
|
BOOL SbiImage::Load( SvStream& r )
|
|
|
|
{
|
2009-04-25 00:18:20 +00:00
|
|
|
UINT32 nVersion = 0; // Versionsnumber
|
2006-11-01 15:13:02 +00:00
|
|
|
return Load( r, nVersion );
|
|
|
|
}
|
|
|
|
BOOL SbiImage::Load( SvStream& r, UINT32& nVersion )
|
|
|
|
{
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
UINT16 nSign, nCount;
|
|
|
|
UINT32 nLen, nOff;
|
|
|
|
|
|
|
|
Clear();
|
2009-04-25 00:18:20 +00:00
|
|
|
// Read Master-Record
|
2000-09-18 15:18:56 +00:00
|
|
|
r >> nSign >> nLen >> nCount;
|
|
|
|
ULONG nLast = r.Tell() + nLen;
|
2009-04-25 00:18:20 +00:00
|
|
|
UINT32 nCharSet; // System charset
|
2000-09-18 15:18:56 +00:00
|
|
|
UINT32 lDimBase;
|
|
|
|
UINT16 nReserved1;
|
|
|
|
UINT32 nReserved2;
|
|
|
|
UINT32 nReserved3;
|
|
|
|
BOOL bBadVer = FALSE;
|
|
|
|
if( nSign == B_MODULE )
|
|
|
|
{
|
|
|
|
r >> nVersion >> nCharSet >> lDimBase
|
|
|
|
>> nFlags >> nReserved1 >> nReserved2 >> nReserved3;
|
|
|
|
eCharSet = (CharSet) nCharSet;
|
2001-08-07 10:20:11 +00:00
|
|
|
eCharSet = GetSOLoadTextEncoding( eCharSet );
|
2006-11-01 15:13:02 +00:00
|
|
|
bBadVer = BOOL( nVersion > B_CURVERSION );
|
2000-09-18 15:18:56 +00:00
|
|
|
nDimBase = (USHORT) lDimBase;
|
|
|
|
}
|
|
|
|
|
2006-11-01 15:13:02 +00:00
|
|
|
bool bLegacy = ( nVersion < B_EXT_IMG_VERSION );
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
ULONG nNext;
|
|
|
|
while( ( nNext = r.Tell() ) < nLast )
|
|
|
|
{
|
|
|
|
short i;
|
|
|
|
|
|
|
|
r >> nSign >> nLen >> nCount;
|
|
|
|
nNext += nLen + 8;
|
|
|
|
if( r.GetError() == SVSTREAM_OK )
|
|
|
|
switch( nSign )
|
|
|
|
{
|
|
|
|
case B_NAME:
|
|
|
|
r.ReadByteString( aName, eCharSet );
|
|
|
|
//r >> aName;
|
|
|
|
break;
|
|
|
|
case B_COMMENT:
|
|
|
|
r.ReadByteString( aComment, eCharSet );
|
|
|
|
//r >> aComment;
|
|
|
|
break;
|
|
|
|
case B_SOURCE:
|
2003-04-23 15:55:53 +00:00
|
|
|
{
|
|
|
|
String aTmp;
|
|
|
|
r.ReadByteString( aTmp, eCharSet );
|
|
|
|
aOUSource = aTmp;
|
2000-09-18 15:18:56 +00:00
|
|
|
//r >> aSource;
|
|
|
|
break;
|
2003-04-23 15:55:53 +00:00
|
|
|
}
|
2005-05-18 12:07:10 +00:00
|
|
|
#ifdef EXTENDED_BINARY_MODULES
|
|
|
|
case B_EXTSOURCE:
|
|
|
|
{
|
2006-06-19 16:39:15 +00:00
|
|
|
for( UINT16 j = 0 ; j < nCount ; j++ )
|
2005-05-18 12:07:10 +00:00
|
|
|
{
|
|
|
|
String aTmp;
|
|
|
|
r.ReadByteString( aTmp, eCharSet );
|
|
|
|
aOUSource += aTmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2000-09-18 15:18:56 +00:00
|
|
|
case B_PCODE:
|
|
|
|
if( bBadVer ) break;
|
|
|
|
pCode = new char[ nLen ];
|
2006-11-01 15:13:02 +00:00
|
|
|
nCodeSize = nLen;
|
2000-09-18 15:18:56 +00:00
|
|
|
r.Read( pCode, nCodeSize );
|
2006-11-01 15:13:02 +00:00
|
|
|
if ( bLegacy )
|
|
|
|
{
|
|
|
|
ReleaseLegacyBuffer(); // release any previously held buffer
|
2006-11-03 06:39:47 +00:00
|
|
|
nLegacyCodeSize = (UINT16) nCodeSize;
|
2006-11-01 15:13:02 +00:00
|
|
|
pLegacyPCode = pCode;
|
|
|
|
|
|
|
|
PCodeBuffConvertor< UINT16, UINT32 > aLegacyToNew( (BYTE*)pLegacyPCode, nLegacyCodeSize );
|
|
|
|
aLegacyToNew.convert();
|
|
|
|
pCode = (char*)aLegacyToNew.GetBuffer();
|
|
|
|
nCodeSize = aLegacyToNew.GetSize();
|
|
|
|
// we don't release the legacy buffer
|
|
|
|
// right now, thats because the module
|
|
|
|
// 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;
|
|
|
|
case B_PUBLICS:
|
|
|
|
case B_POOLDIR:
|
|
|
|
case B_SYMPOOL:
|
|
|
|
case B_LINERANGES:
|
|
|
|
break;
|
|
|
|
case B_STRINGPOOL:
|
|
|
|
if( bBadVer ) break;
|
|
|
|
MakeStrings( nCount );
|
|
|
|
for( i = 0; i < nStrings && SbiGood( r ); i++ )
|
|
|
|
{
|
|
|
|
r >> nOff;
|
|
|
|
pStringOff[ i ] = (USHORT) nOff;
|
|
|
|
}
|
|
|
|
r >> nLen;
|
|
|
|
if( SbiGood( r ) )
|
|
|
|
{
|
2003-05-22 10:01:17 +00:00
|
|
|
delete [] pStrings;
|
2000-09-18 15:18:56 +00:00
|
|
|
pStrings = new sal_Unicode[ nLen ];
|
|
|
|
nStringSize = (USHORT) nLen;
|
|
|
|
|
|
|
|
char* pByteStrings = new char[ nLen ];
|
|
|
|
r.Read( pByteStrings, nStringSize );
|
2006-06-19 16:39:15 +00:00
|
|
|
for( short j = 0; j < nStrings; j++ )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2006-11-03 06:39:47 +00:00
|
|
|
USHORT nOff2 = (USHORT) pStringOff[ j ];
|
2006-06-19 16:39:15 +00:00
|
|
|
String aStr( pByteStrings + nOff2, eCharSet );
|
|
|
|
memcpy( pStrings + nOff2, aStr.GetBuffer(), (aStr.Len() + 1) * sizeof( sal_Unicode ) );
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2003-03-18 15:28:40 +00:00
|
|
|
delete[] pByteStrings;
|
2000-09-18 15:18:56 +00:00
|
|
|
} break;
|
|
|
|
case B_MODEND:
|
|
|
|
goto done;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
r.Seek( nNext );
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
r.Seek( nLast );
|
|
|
|
//if( eCharSet != ::GetSystemCharSet() )
|
|
|
|
//ConvertStrings();
|
|
|
|
if( !SbiGood( r ) )
|
|
|
|
bError = TRUE;
|
|
|
|
return BOOL( !bError );
|
|
|
|
}
|
|
|
|
|
2006-11-01 15:13:02 +00:00
|
|
|
BOOL SbiImage::Save( SvStream& r, 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 );
|
|
|
|
return TRUE;
|
|
|
|
}
|
2009-04-25 00:18:20 +00:00
|
|
|
// First of all the header
|
2000-09-18 15:18:56 +00:00
|
|
|
ULONG nStart = SbiOpenRecord( r, B_MODULE, 1 );
|
|
|
|
ULONG nPos;
|
2001-08-07 10:20:11 +00:00
|
|
|
|
|
|
|
eCharSet = GetSOStoreTextEncoding( eCharSet );
|
2006-11-01 15:13:02 +00:00
|
|
|
if ( bLegacy )
|
|
|
|
r << (INT32) B_LEGACYVERSION;
|
|
|
|
else
|
|
|
|
r << (INT32) B_CURVERSION;
|
|
|
|
r << (INT32) eCharSet
|
2000-09-18 15:18:56 +00:00
|
|
|
<< (INT32) nDimBase
|
|
|
|
<< (INT16) nFlags
|
|
|
|
<< (INT16) 0
|
|
|
|
<< (INT32) 0
|
|
|
|
<< (INT32) 0;
|
|
|
|
|
|
|
|
// Name?
|
|
|
|
if( aName.Len() && SbiGood( r ) )
|
|
|
|
{
|
|
|
|
nPos = SbiOpenRecord( r, B_NAME, 1 );
|
|
|
|
r.WriteByteString( aName, eCharSet );
|
|
|
|
//r << aName;
|
|
|
|
SbiCloseRecord( r, nPos );
|
|
|
|
}
|
2009-04-25 00:18:20 +00:00
|
|
|
// Comment?
|
2000-09-18 15:18:56 +00:00
|
|
|
if( aComment.Len() && SbiGood( r ) )
|
|
|
|
{
|
|
|
|
nPos = SbiOpenRecord( r, B_COMMENT, 1 );
|
|
|
|
r.WriteByteString( aComment, eCharSet );
|
|
|
|
//r << aComment;
|
|
|
|
SbiCloseRecord( r, nPos );
|
|
|
|
}
|
|
|
|
// Source?
|
2003-04-23 15:55:53 +00:00
|
|
|
if( aOUSource.getLength() && SbiGood( r ) )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
nPos = SbiOpenRecord( r, B_SOURCE, 1 );
|
2003-04-23 15:55:53 +00:00
|
|
|
String aTmp;
|
|
|
|
sal_Int32 nLen = aOUSource.getLength();
|
2005-05-18 12:07:10 +00:00
|
|
|
const sal_Int32 nMaxUnitSize = STRING_MAXLEN - 1;
|
2003-04-23 15:55:53 +00:00
|
|
|
if( nLen > STRING_MAXLEN )
|
2005-05-18 12:07:10 +00:00
|
|
|
aTmp = aOUSource.copy( 0, nMaxUnitSize );
|
2003-04-23 15:55:53 +00:00
|
|
|
else
|
|
|
|
aTmp = aOUSource;
|
|
|
|
r.WriteByteString( aTmp, eCharSet );
|
2000-09-18 15:18:56 +00:00
|
|
|
//r << aSource;
|
|
|
|
SbiCloseRecord( r, nPos );
|
2005-05-18 12:07:10 +00:00
|
|
|
|
|
|
|
#ifdef EXTENDED_BINARY_MODULES
|
|
|
|
if( nLen > STRING_MAXLEN )
|
|
|
|
{
|
|
|
|
sal_Int32 nRemainingLen = nLen - nMaxUnitSize;
|
|
|
|
UINT16 nUnitCount = UINT16( (nRemainingLen + nMaxUnitSize - 1) / nMaxUnitSize );
|
|
|
|
nPos = SbiOpenRecord( r, B_EXTSOURCE, nUnitCount );
|
|
|
|
for( UINT16 i = 0 ; i < nUnitCount ; i++ )
|
|
|
|
{
|
|
|
|
sal_Int32 nCopyLen =
|
|
|
|
(nRemainingLen > nMaxUnitSize) ? nMaxUnitSize : nRemainingLen;
|
2006-06-19 16:39:15 +00:00
|
|
|
String aTmp2 = aOUSource.copy( (i+1) * nMaxUnitSize, nCopyLen );
|
2005-05-18 12:07:10 +00:00
|
|
|
nRemainingLen -= nCopyLen;
|
2006-06-19 16:39:15 +00:00
|
|
|
r.WriteByteString( aTmp2, eCharSet );
|
2005-05-18 12:07:10 +00:00
|
|
|
}
|
|
|
|
SbiCloseRecord( r, nPos );
|
|
|
|
}
|
|
|
|
#endif
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2009-04-25 00:18:20 +00:00
|
|
|
// Binary data?
|
2000-09-18 15:18:56 +00:00
|
|
|
if( pCode && SbiGood( r ) )
|
|
|
|
{
|
|
|
|
nPos = SbiOpenRecord( r, B_PCODE, 1 );
|
2006-11-01 15:13:02 +00:00
|
|
|
if ( bLegacy )
|
|
|
|
{
|
|
|
|
ReleaseLegacyBuffer(); // release any previously held buffer
|
|
|
|
PCodeBuffConvertor< UINT32, UINT16 > aNewToLegacy( (BYTE*)pCode, nCodeSize );
|
|
|
|
aNewToLegacy.convert();
|
|
|
|
pLegacyPCode = (char*)aNewToLegacy.GetBuffer();
|
|
|
|
nLegacyCodeSize = aNewToLegacy.GetSize();
|
|
|
|
r.Write( pLegacyPCode, nLegacyCodeSize );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
r.Write( pCode, nCodeSize );
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiCloseRecord( r, nPos );
|
|
|
|
}
|
|
|
|
// String-Pool?
|
|
|
|
if( nStrings )
|
|
|
|
{
|
|
|
|
nPos = SbiOpenRecord( r, B_STRINGPOOL, nStrings );
|
2009-04-25 00:18:20 +00:00
|
|
|
// For every String:
|
|
|
|
// UINT32 Offset of the Strings in the Stringblock
|
2003-12-01 15:26:51 +00:00
|
|
|
short i;
|
|
|
|
|
|
|
|
for( i = 0; i < nStrings && SbiGood( r ); i++ )
|
2000-09-18 15:18:56 +00:00
|
|
|
r << (UINT32) pStringOff[ i ];
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Then the String-Block
|
2000-09-18 15:18:56 +00:00
|
|
|
char* pByteStrings = new char[ nStringSize ];
|
|
|
|
for( i = 0; i < nStrings; i++ )
|
|
|
|
{
|
2006-11-03 06:39:47 +00:00
|
|
|
USHORT nOff = (USHORT) pStringOff[ i ];
|
2000-09-18 15:18:56 +00:00
|
|
|
ByteString aStr( pStrings + nOff, eCharSet );
|
|
|
|
memcpy( pByteStrings + nOff, aStr.GetBuffer(), (aStr.Len() + 1) * sizeof( char ) );
|
|
|
|
}
|
|
|
|
r << (UINT32) nStringSize;
|
|
|
|
r.Write( pByteStrings, nStringSize );
|
2003-03-18 15:28:40 +00:00
|
|
|
|
|
|
|
delete[] pByteStrings;
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiCloseRecord( r, nPos );
|
|
|
|
}
|
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 ) )
|
|
|
|
bError = TRUE;
|
|
|
|
return BOOL( !bError );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
2009-04-25 00:18:20 +00:00
|
|
|
* Routines called by the compiler
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
void SbiImage::MakeStrings( short nSize )
|
|
|
|
{
|
2006-11-03 06:39:47 +00:00
|
|
|
nStrings = 0;
|
|
|
|
nStringIdx = 0;
|
|
|
|
nStringOff = 0;
|
2000-09-18 15:18:56 +00:00
|
|
|
nStringSize = 1024;
|
|
|
|
pStrings = new sal_Unicode[ nStringSize ];
|
2006-11-01 15:13:02 +00:00
|
|
|
pStringOff = new UINT32[ nSize ];
|
2000-09-18 15:18:56 +00:00
|
|
|
if( pStrings && pStringOff )
|
|
|
|
{
|
|
|
|
nStrings = nSize;
|
2006-11-01 15:13:02 +00:00
|
|
|
memset( pStringOff, 0, nSize * sizeof( UINT32 ) );
|
2000-09-18 15:18:56 +00:00
|
|
|
memset( pStrings, 0, nStringSize * sizeof( sal_Unicode ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bError = TRUE;
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Add a string to StringPool. The String buffer is dynamically
|
|
|
|
// growing in 1K-Steps
|
2000-09-18 15:18:56 +00:00
|
|
|
void SbiImage::AddString( const String& r )
|
|
|
|
{
|
|
|
|
if( nStringIdx >= nStrings )
|
|
|
|
bError = TRUE;
|
|
|
|
if( !bError )
|
|
|
|
{
|
2006-11-01 15:13:02 +00:00
|
|
|
xub_StrLen len = r.Len() + 1;
|
|
|
|
UINT32 needed = nStringOff + len;
|
|
|
|
if( needed > 0xFFFFFF00L )
|
2000-09-18 15:18:56 +00:00
|
|
|
bError = TRUE; // out of mem!
|
2006-11-01 15:13:02 +00:00
|
|
|
else if( needed > nStringSize )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2005-09-29 17:38:33 +00:00
|
|
|
UINT32 nNewLen = needed + 1024;
|
|
|
|
nNewLen &= 0xFFFFFC00; // trim to 1K border
|
2006-11-01 15:13:02 +00:00
|
|
|
if( nNewLen > 0xFFFFFF00L )
|
|
|
|
nNewLen = 0xFFFFFF00L;
|
2005-09-29 17:38:33 +00:00
|
|
|
sal_Unicode* p = NULL;
|
|
|
|
if( (p = new sal_Unicode[ nNewLen ]) != NULL )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
memcpy( p, pStrings, nStringSize * sizeof( sal_Unicode ) );
|
2003-03-18 15:28:40 +00:00
|
|
|
delete[] pStrings;
|
2000-09-18 15:18:56 +00:00
|
|
|
pStrings = p;
|
2006-10-12 13:25:10 +00:00
|
|
|
nStringSize = sal::static_int_cast< UINT16 >(nNewLen);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
bError = TRUE;
|
|
|
|
}
|
|
|
|
if( !bError )
|
|
|
|
{
|
|
|
|
pStringOff[ nStringIdx++ ] = nStringOff;
|
|
|
|
//ByteString aByteStr( r, eCharSet );
|
|
|
|
memcpy( pStrings + nStringOff, r.GetBuffer(), len * sizeof( sal_Unicode ) );
|
2006-10-12 13:25:10 +00:00
|
|
|
nStringOff = nStringOff + len;
|
2009-04-25 00:18:20 +00:00
|
|
|
// Last String? The update the size of the buffer
|
2000-09-18 15:18:56 +00:00
|
|
|
if( nStringIdx >= nStrings )
|
|
|
|
nStringSize = nStringOff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
2006-11-01 15:13:02 +00:00
|
|
|
void SbiImage::AddCode( char* p, UINT32 s )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
pCode = p;
|
|
|
|
nCodeSize = s;
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Add user type
|
|
|
|
void SbiImage::AddType(SbxObject* pObject)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2004-11-15 15:34:02 +00:00
|
|
|
if( !rTypes.Is() )
|
|
|
|
rTypes = new SbxArray;
|
2000-09-18 15:18:56 +00:00
|
|
|
SbxObject *pCopyObject = new SbxObject(*pObject);
|
|
|
|
rTypes->Insert (pCopyObject,rTypes->Count());
|
|
|
|
}
|
|
|
|
|
2004-11-15 15:34:02 +00:00
|
|
|
void SbiImage::AddEnum(SbxObject* pObject) // Register enum type
|
|
|
|
{
|
|
|
|
if( !rEnums.Is() )
|
|
|
|
rEnums = new SbxArray;
|
|
|
|
rEnums->Insert( pObject, rEnums->Count() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2009-04-25 00:18:20 +00:00
|
|
|
* Accessing the image
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
// Note: IDs start with 1
|
2000-09-18 15:18:56 +00:00
|
|
|
String SbiImage::GetString( short nId ) const
|
|
|
|
{
|
|
|
|
if( nId && nId <= nStrings )
|
|
|
|
{
|
2006-11-01 15:13:02 +00:00
|
|
|
UINT32 nOff = pStringOff[ nId - 1 ];
|
2005-03-29 10:47:59 +00:00
|
|
|
sal_Unicode* pStr = pStrings + nOff;
|
|
|
|
|
|
|
|
// #i42467: Special treatment for vbNullChar
|
|
|
|
if( *pStr == 0 )
|
|
|
|
{
|
2006-11-01 15:13:02 +00:00
|
|
|
UINT32 nNextOff = (nId < nStrings) ? pStringOff[ nId ] : nStringOff;
|
|
|
|
UINT32 nLen = nNextOff - nOff - 1;
|
2005-03-29 10:47:59 +00:00
|
|
|
if( nLen == 1 )
|
|
|
|
{
|
|
|
|
// Force length 1 and make char 0 afterwards
|
|
|
|
String aNullCharStr( String::CreateFromAscii( " " ) );
|
|
|
|
aNullCharStr.SetChar( 0, 0 );
|
|
|
|
return aNullCharStr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
String aStr( pStr );
|
|
|
|
return aStr;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
|
|
|
const SbxObject* SbiImage::FindType (String aTypeName) const
|
|
|
|
{
|
2004-11-15 15:34:02 +00:00
|
|
|
return rTypes.Is() ? (SbxObject*)rTypes->Find(aTypeName,SbxCLASS_OBJECT) : NULL;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
UINT16 SbiImage::CalcLegacyOffset( INT32 nOffset )
|
2006-11-01 15:13:02 +00:00
|
|
|
{
|
|
|
|
return SbiCodeGen::calcLegacyOffSet( (BYTE*)pCode, nOffset ) ;
|
|
|
|
}
|
2009-04-25 00:18:20 +00:00
|
|
|
|
|
|
|
UINT32 SbiImage::CalcNewOffset( INT16 nOffset )
|
2006-11-01 15:13:02 +00:00
|
|
|
{
|
|
|
|
return SbiCodeGen::calcNewOffSet( (BYTE*)pLegacyPCode, nOffset ) ;
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
void SbiImage::ReleaseLegacyBuffer()
|
2006-11-01 15:13:02 +00:00
|
|
|
{
|
|
|
|
delete[] pLegacyPCode;
|
|
|
|
pLegacyPCode = NULL;
|
|
|
|
nLegacyCodeSize = 0;
|
|
|
|
}
|
|
|
|
|
2009-04-25 00:18:20 +00:00
|
|
|
BOOL SbiImage::ExceedsLegacyLimits()
|
2006-11-01 15:13:02 +00:00
|
|
|
{
|
|
|
|
if ( ( nStringSize > 0xFF00L ) || ( CalcLegacyOffset( nCodeSize ) > 0xFF00L ) )
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|