2001-04-11 03:52:27 -05:00
|
|
|
|
/*************************************************************************
|
|
|
|
|
*
|
2008-04-10 12:04:05 -05:00
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2001-04-11 03:52:27 -05:00
|
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2001-04-11 03:52:27 -05:00
|
|
|
|
*
|
2008-04-10 12:04:05 -05:00
|
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-04-11 03:52:27 -05:00
|
|
|
|
*
|
2008-04-10 12:04:05 -05:00
|
|
|
|
* This file is part of OpenOffice.org.
|
2001-04-11 03:52:27 -05:00
|
|
|
|
*
|
2008-04-10 12:04:05 -05: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.
|
2001-04-11 03:52:27 -05:00
|
|
|
|
*
|
2008-04-10 12:04:05 -05: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).
|
2001-04-11 03:52:27 -05:00
|
|
|
|
*
|
2008-04-10 12:04:05 -05: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.
|
2001-04-11 03:52:27 -05:00
|
|
|
|
*
|
|
|
|
|
************************************************************************/
|
|
|
|
|
|
2006-09-17 05:34:37 -05:00
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
|
#include "precompiled_soltools.hxx"
|
|
|
|
|
|
2001-04-11 03:52:27 -05:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <direct.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#include "ldump.hxx"
|
|
|
|
|
#include "hashtbl.hxx"
|
|
|
|
|
|
2004-08-09 05:23:31 -05:00
|
|
|
|
#define MAXSYM 65536
|
|
|
|
|
#define MAXBASE 98304
|
2001-04-11 03:52:27 -05:00
|
|
|
|
#define MAX_MAN 4096
|
|
|
|
|
|
|
|
|
|
int bFilter = 0;
|
|
|
|
|
int bLdump3 = 0;
|
2004-08-23 03:13:12 -05:00
|
|
|
|
int bUseDirectives = 0;
|
2007-04-26 08:01:35 -05:00
|
|
|
|
int bVerbose = 0;
|
2007-06-27 11:46:28 -05:00
|
|
|
|
int bExportByName = 0;
|
2001-04-11 03:52:27 -05:00
|
|
|
|
|
2006-06-19 23:08:37 -05:00
|
|
|
|
class ExportSet : public HashTable
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ExportSet
|
|
|
|
|
(
|
|
|
|
|
unsigned long lSize,
|
|
|
|
|
double dMaxLoadFactor = HashTable::m_defMaxLoadFactor,
|
|
|
|
|
double dGrowFactor = HashTable::m_defDefGrowFactor
|
|
|
|
|
)
|
|
|
|
|
: HashTable(lSize,false,dMaxLoadFactor,dGrowFactor) {}
|
|
|
|
|
|
|
|
|
|
virtual ~ExportSet() {}
|
|
|
|
|
|
|
|
|
|
LibExport * Find (char * const& Key) const
|
|
|
|
|
{ return (LibExport *) HashTable::Find((char *) Key); }
|
|
|
|
|
|
|
|
|
|
bool Insert (char * const& Key, LibExport * Object)
|
|
|
|
|
{ return HashTable::Insert((char *) Key, (void*) Object); }
|
|
|
|
|
|
|
|
|
|
LibExport * Delete (char * const&Key)
|
|
|
|
|
{ return (LibExport *) HashTable::Delete ((char *) Key); }
|
|
|
|
|
};
|
2001-04-11 03:52:27 -05:00
|
|
|
|
|
2008-03-25 08:07:33 -05:00
|
|
|
|
LibDump::LibDump( char *cFileName, int bExportByName )
|
2001-04-11 03:52:27 -05:00
|
|
|
|
: cBName( NULL ),
|
|
|
|
|
cAPrefix( NULL ),
|
|
|
|
|
cLibName( NULL ),
|
|
|
|
|
cFilterName( NULL ),
|
|
|
|
|
cModName( NULL )
|
|
|
|
|
{
|
|
|
|
|
fprintf( stderr, "LIB-NT File Dumper v4.00 (C) 2000 Sun Microsystems, Inc.\n\n" );
|
|
|
|
|
fprintf( stderr, "%s ", cFileName );
|
|
|
|
|
|
2008-03-25 08:07:33 -05:00
|
|
|
|
bExportName = bExportByName;
|
|
|
|
|
|
2006-09-25 07:23:54 -05:00
|
|
|
|
unsigned long nSlots = 0xfffff;
|
2001-04-11 03:52:27 -05:00
|
|
|
|
pBaseTab = new ExportSet( nSlots );
|
|
|
|
|
pIndexTab = new ExportSet( nSlots );
|
|
|
|
|
pFilterLines = new char * [MAXFILT];
|
|
|
|
|
CheckLibrary(cFileName);
|
|
|
|
|
bBase = 0;
|
|
|
|
|
bAll = false;
|
|
|
|
|
nDefStart = 0;
|
|
|
|
|
nBaseLines = 0;
|
|
|
|
|
nFilterLines = 0;
|
|
|
|
|
bDef = true;
|
|
|
|
|
cAPrefix = new char[ 1 ];
|
|
|
|
|
cAPrefix[ 0 ] = 0;
|
2008-03-25 08:07:33 -05:00
|
|
|
|
if (!bExportName)
|
|
|
|
|
CheckDataBase();
|
2001-04-11 03:52:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LibDump::Dump()
|
|
|
|
|
{
|
|
|
|
|
FILE *pList;
|
|
|
|
|
char aBuf[MAX_MAN];
|
|
|
|
|
int nLen;
|
|
|
|
|
char aName[MAX_MAN];
|
|
|
|
|
|
|
|
|
|
pList = fopen( cLibName, "rb");
|
|
|
|
|
if (!pList)
|
|
|
|
|
DumpError(10);
|
|
|
|
|
|
2004-08-23 03:13:12 -05:00
|
|
|
|
// forget about offset when working on linker directives
|
|
|
|
|
if ( !bUseDirectives )
|
|
|
|
|
{
|
|
|
|
|
// calculating offset for name section
|
|
|
|
|
unsigned char TmpBuffer[4];
|
|
|
|
|
fread( TmpBuffer, 1, 4, pList);
|
|
|
|
|
// anzahl bigendian mal laenge + ueberspringen der naechsten laengenangabe
|
2006-09-25 07:23:54 -05:00
|
|
|
|
unsigned long nOffSet = (unsigned long) ( TmpBuffer[2] * 256 + TmpBuffer[3] ) * 4 + 4;
|
|
|
|
|
fseek( pList, (long) nOffSet, 0);
|
2004-08-23 03:13:12 -05:00
|
|
|
|
}
|
2001-04-11 03:52:27 -05:00
|
|
|
|
|
|
|
|
|
char aTmpBuf[4096];
|
2004-08-23 03:13:12 -05:00
|
|
|
|
// reading file containing symbols
|
2001-04-11 03:52:27 -05:00
|
|
|
|
while( !feof( pList ) )
|
|
|
|
|
{
|
2004-08-23 03:13:12 -05:00
|
|
|
|
int i = 0;
|
|
|
|
|
if ( !bUseDirectives )
|
2001-04-11 03:52:27 -05:00
|
|
|
|
{
|
2004-08-23 03:13:12 -05:00
|
|
|
|
// symbol komplett einlesen
|
2006-06-19 23:08:37 -05:00
|
|
|
|
for (;;)
|
2001-04-11 03:52:27 -05:00
|
|
|
|
{
|
2006-06-19 23:08:37 -05:00
|
|
|
|
int c = fgetc( pList );
|
|
|
|
|
if ( c == '\0' )
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-08-23 03:13:12 -05:00
|
|
|
|
if ( ((c >= 33) && (c <= 126)) && ( c!=40 && c!=41) )
|
2006-06-19 23:08:37 -05:00
|
|
|
|
aBuf[i] = static_cast< char >(c);
|
2004-08-23 03:13:12 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
aBuf[0] = '\0';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
// Namen found
|
|
|
|
|
aBuf[i] = '\0';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fgets( aTmpBuf, 4096, pList );
|
|
|
|
|
char * pEnd = 0;
|
|
|
|
|
char *pFound = 0;
|
|
|
|
|
aBuf[0] = '\0';
|
|
|
|
|
pFound = strchr( aTmpBuf, 'E' );
|
|
|
|
|
while ( pFound )
|
|
|
|
|
{
|
|
|
|
|
if ( strncmp( "EXPORT:", pFound, 7) == 0 )
|
|
|
|
|
{
|
|
|
|
|
pFound += 7;
|
|
|
|
|
pEnd = strchr( pFound, ',');
|
|
|
|
|
if ( pEnd )
|
|
|
|
|
*pEnd = '\0';
|
|
|
|
|
strncpy( aBuf, pFound, strlen( pFound));
|
|
|
|
|
aBuf[ strlen( pFound) ] = '\0';
|
|
|
|
|
// fprintf( stderr, "\n--- %s\n", aBuf);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pFound++;
|
|
|
|
|
pFound = strchr( pFound, 'E' );
|
|
|
|
|
}
|
2001-04-11 03:52:27 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-19 23:08:37 -05:00
|
|
|
|
if ((aBuf[0] =='?') || !strncmp(aBuf, "__CT",4))
|
2001-04-11 03:52:27 -05:00
|
|
|
|
{
|
2006-09-25 07:23:54 -05:00
|
|
|
|
nLen = (int) strlen(aBuf);
|
2001-04-11 03:52:27 -05:00
|
|
|
|
memset( aName, 0, sizeof( aName ) );
|
|
|
|
|
int nName = 0;
|
|
|
|
|
for( i = 0; i < nLen; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( (aBuf[i] != '\n') && (aBuf[i] != '\r') )
|
|
|
|
|
{
|
|
|
|
|
aName[nName] = aBuf[i];
|
|
|
|
|
nName++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// und raus damit
|
2007-06-27 11:46:28 -05:00
|
|
|
|
PrintSym( aName, bExportByName );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
}
|
|
|
|
|
else if ( bAll == true )
|
|
|
|
|
{
|
2006-09-25 07:23:54 -05:00
|
|
|
|
int nPreLen = (int) strlen( cAPrefix );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
|
2006-09-25 07:23:54 -05:00
|
|
|
|
nLen = (int) strlen(aBuf);
|
2001-04-11 03:52:27 -05:00
|
|
|
|
memset( aName, 0, sizeof( aName ) );
|
|
|
|
|
int nName = 0;
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < nLen; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( (aBuf[i] != '\n') && (aBuf[i] != '\r') )
|
|
|
|
|
{
|
|
|
|
|
aName[nName] = aBuf[i];
|
|
|
|
|
nName++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//fprintf( stderr, "Gefundenen Prefix : %s %d \n", aTmpBuf, nPreLen );
|
|
|
|
|
// den ersten _ raus
|
2006-09-25 07:23:54 -05:00
|
|
|
|
nLen = (int) strlen(aName);
|
2001-04-11 03:52:27 -05:00
|
|
|
|
if (aName[0] == '_')
|
|
|
|
|
strcpy( aBuf , &aName[1] );
|
2006-09-25 07:23:54 -05:00
|
|
|
|
strncpy ( aTmpBuf, aBuf, (size_t) nPreLen );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
aTmpBuf[nPreLen] = '\0';
|
|
|
|
|
if ( !strcmp( aTmpBuf, cAPrefix ))
|
|
|
|
|
{
|
|
|
|
|
if ( bLdump3 ) {
|
|
|
|
|
int nChar = '@';
|
|
|
|
|
char *pNeu = strchr( aBuf, nChar );
|
|
|
|
|
int nPos = pNeu - aBuf + 1;
|
|
|
|
|
if ( nPos > 0 )
|
|
|
|
|
{
|
|
|
|
|
char aOldBuf[MAX_MAN];
|
|
|
|
|
strcpy( aOldBuf, aBuf );
|
|
|
|
|
char pChar[MAX_MAN];
|
2006-09-25 07:23:54 -05:00
|
|
|
|
strncpy( pChar, aBuf, (size_t) (nPos -1) );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
pChar[nPos-1] = '\0';
|
|
|
|
|
strcpy( aBuf, pChar );
|
|
|
|
|
strcat( aBuf, "=" );
|
|
|
|
|
strcat( aBuf, aOldBuf );
|
|
|
|
|
strcpy( pChar, "" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// und raus damit
|
2007-06-27 11:46:28 -05:00
|
|
|
|
PrintSym( aBuf, true );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(pList);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LibDump::ReadFilter( char * cFilterName )
|
|
|
|
|
{
|
|
|
|
|
FILE* pfFilter = 0;
|
|
|
|
|
char aBuf[MAX_MAN];
|
|
|
|
|
char* pStr;
|
|
|
|
|
int nLen;
|
|
|
|
|
|
|
|
|
|
pfFilter = fopen( cFilterName, "r" );
|
|
|
|
|
|
|
|
|
|
if ( !pfFilter )
|
|
|
|
|
{
|
|
|
|
|
::bFilter = 0;
|
|
|
|
|
DumpError( 500 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while( fgets( aBuf, MAX_MAN, pfFilter ) != 0 )
|
|
|
|
|
{
|
2006-09-25 07:23:54 -05:00
|
|
|
|
nLen = (int) strlen(aBuf);
|
|
|
|
|
pStr = new char[(unsigned int) nLen];
|
2001-04-11 03:52:27 -05:00
|
|
|
|
if ( !pStr )
|
|
|
|
|
DumpError( 98 );
|
2006-09-25 07:23:54 -05:00
|
|
|
|
memcpy( pStr, aBuf, (unsigned int) nLen );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
if ( *(pStr+nLen-1) == '\n' )
|
|
|
|
|
*(pStr+nLen-1) = '\0';
|
|
|
|
|
pFilterLines[nFilterLines] = pStr;
|
|
|
|
|
nFilterLines++;
|
|
|
|
|
if ( nFilterLines >= MAXFILT )
|
|
|
|
|
DumpError( 510 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose( pfFilter );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LibDump::PrintSym(char *pName, bool bName )
|
|
|
|
|
{
|
|
|
|
|
LibExport *pData;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Filter auswerten
|
|
|
|
|
if ( Filter( pName ) )
|
|
|
|
|
{
|
|
|
|
|
if ( strlen( pName ) > 3 )
|
|
|
|
|
{
|
|
|
|
|
if ( bDef )
|
|
|
|
|
{
|
|
|
|
|
if (!bBase)
|
2008-03-25 08:07:33 -05:00
|
|
|
|
if (bExportName) {
|
|
|
|
|
fprintf( stdout, "\t%s\n", pName );
|
|
|
|
|
} else {
|
2001-04-11 03:52:27 -05:00
|
|
|
|
fprintf( stdout, "\t%s\t\t@%lu\n", pName, nDefStart );
|
2008-03-25 08:07:33 -05:00
|
|
|
|
}
|
2001-04-11 03:52:27 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pData = pBaseTab->Find( pName );
|
|
|
|
|
if ( pData )
|
|
|
|
|
{
|
|
|
|
|
pData->bExport = true;
|
|
|
|
|
if ( bName )
|
|
|
|
|
pData->bByName = true;
|
|
|
|
|
else
|
|
|
|
|
pData->bByName = false;
|
2007-04-26 08:01:35 -05:00
|
|
|
|
if ( bVerbose )
|
|
|
|
|
fprintf(stderr,".");
|
2001-04-11 03:52:27 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// neuen Export eintragen
|
|
|
|
|
pData = new LibExport;
|
|
|
|
|
pData->cExportName = new char[ strlen( pName ) + 1 ];
|
|
|
|
|
strcpy( pData->cExportName, pName );
|
|
|
|
|
pData->nOrdinal = nBaseLines++;
|
|
|
|
|
pData->bExport = true;
|
|
|
|
|
if ( bName )
|
|
|
|
|
pData->bByName = true;
|
|
|
|
|
else
|
|
|
|
|
pData->bByName = false;
|
|
|
|
|
pBaseTab->Insert( pData->cExportName, pData );
|
|
|
|
|
char *cBuffer = new char[ 30 ];
|
|
|
|
|
sprintf( cBuffer, "%lu", pData->nOrdinal );
|
|
|
|
|
pIndexTab->Insert( cBuffer, pData );
|
|
|
|
|
delete [] cBuffer;
|
2007-04-26 08:01:35 -05:00
|
|
|
|
if ( bVerbose )
|
|
|
|
|
fprintf(stderr,"n");
|
2001-04-11 03:52:27 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf( "%s\n", pName );
|
|
|
|
|
nDefStart++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-15 07:30:42 -05:00
|
|
|
|
bool LibDump::IsFromAnonymousNamespace (char *pExportName) {
|
|
|
|
|
char* pattern1 = "@?A0x";
|
|
|
|
|
|
|
|
|
|
if (strstr(pExportName, pattern1)) {
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
2001-04-11 03:52:27 -05:00
|
|
|
|
bool LibDump::Filter(char *pExportName)
|
|
|
|
|
{
|
|
|
|
|
unsigned long i;
|
|
|
|
|
char pTest[256];
|
|
|
|
|
|
2007-10-15 07:30:42 -05:00
|
|
|
|
// filter out symbols from anonymous namespaces
|
|
|
|
|
if (IsFromAnonymousNamespace (pExportName))
|
|
|
|
|
return false;
|
|
|
|
|
|
2001-04-11 03:52:27 -05:00
|
|
|
|
// Kein Filter gesetzt
|
|
|
|
|
if ( ::bFilter == 0 )
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
for ( i=0; i<nFilterLines; i++ )
|
|
|
|
|
{
|
|
|
|
|
//Zum vergleichen mu<6D> das Plus abgeschnitteb werden
|
|
|
|
|
if(pFilterLines[i][0] != '+')
|
|
|
|
|
{
|
|
|
|
|
if ( strstr( pExportName, pFilterLines[i]))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strcpy(pTest,&pFilterLines[i][1]);
|
|
|
|
|
if ( strstr( pExportName, pTest))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LibDump::SetFilter(char * cFilterName)
|
|
|
|
|
{
|
|
|
|
|
ReadFilter( cFilterName );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LibDump::CheckLibrary(char * cName)
|
|
|
|
|
{
|
|
|
|
|
delete [] cLibName;
|
|
|
|
|
cLibName = new char[ strlen( cName ) + 1 ];
|
|
|
|
|
strcpy( cLibName, cName );
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LibDump::ReadDataBase()
|
|
|
|
|
{
|
|
|
|
|
FILE* pfBase = 0;
|
|
|
|
|
char aBuf[MAX_MAN];
|
|
|
|
|
char* pStr;
|
2005-01-14 04:36:32 -06:00
|
|
|
|
char cBuffer[ 30 ];
|
2001-04-11 03:52:27 -05:00
|
|
|
|
int nLen;
|
|
|
|
|
LibExport *pData;
|
|
|
|
|
|
|
|
|
|
pfBase = fopen( cBName, "r" );
|
|
|
|
|
|
|
|
|
|
if ( !pfBase )
|
|
|
|
|
{
|
|
|
|
|
bBase = 0;
|
|
|
|
|
DumpError( 600 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bRet = true;
|
|
|
|
|
while( fgets( aBuf, MAX_MAN, pfBase ) != 0 )
|
|
|
|
|
{
|
2006-09-25 07:23:54 -05:00
|
|
|
|
nLen = (int) strlen(aBuf);
|
|
|
|
|
pStr = new char[(unsigned int) nLen];
|
2001-04-11 03:52:27 -05:00
|
|
|
|
if ( !pStr )
|
|
|
|
|
DumpError( 98 );
|
2006-09-25 07:23:54 -05:00
|
|
|
|
memcpy( pStr, aBuf, (size_t) nLen );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
if ( *(pStr+nLen-1) == '\n' )
|
|
|
|
|
*(pStr+nLen-1) = '\0';
|
|
|
|
|
pData = new LibExport;
|
2005-01-14 04:36:32 -06:00
|
|
|
|
pData->cExportName = pStr;
|
2001-04-11 03:52:27 -05:00
|
|
|
|
pData->nOrdinal = nBaseLines;
|
|
|
|
|
pData->bExport=false;
|
|
|
|
|
|
|
|
|
|
if (pBaseTab->Insert(pData->cExportName, pData ) == NULL)
|
|
|
|
|
bRet = false;
|
2006-09-25 07:23:54 -05:00
|
|
|
|
ltoa( (long) pData->nOrdinal, cBuffer, 10 );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
if (pIndexTab->Insert( cBuffer, pData ) == NULL)
|
|
|
|
|
bRet = false;
|
|
|
|
|
nBaseLines++;
|
|
|
|
|
if ( nBaseLines >= MAXBASE )
|
|
|
|
|
DumpError( 610 );
|
|
|
|
|
}
|
|
|
|
|
fclose( pfBase );
|
|
|
|
|
return bRet;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-19 23:08:37 -05:00
|
|
|
|
class ExportSetIter : public HashTableIterator
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ExportSetIter(HashTable const& aTable)
|
|
|
|
|
: HashTableIterator(aTable) {}
|
|
|
|
|
|
|
|
|
|
LibExport * GetFirst()
|
|
|
|
|
{ return (LibExport *)HashTableIterator::GetFirst(); }
|
|
|
|
|
LibExport * GetNext()
|
|
|
|
|
{ return (LibExport *)HashTableIterator::GetNext(); }
|
|
|
|
|
LibExport * GetLast()
|
|
|
|
|
{ return (LibExport *)HashTableIterator::GetLast(); }
|
|
|
|
|
LibExport * GetPrev()
|
|
|
|
|
{ return (LibExport *)HashTableIterator::GetPrev(); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void operator =(ExportSetIter &); // not defined
|
|
|
|
|
};
|
2001-04-11 03:52:27 -05:00
|
|
|
|
|
|
|
|
|
bool LibDump::PrintDataBase()
|
|
|
|
|
{
|
2008-03-25 08:07:33 -05:00
|
|
|
|
if (bExportName)
|
|
|
|
|
return true;
|
2001-04-11 03:52:27 -05:00
|
|
|
|
FILE *pFp;
|
|
|
|
|
pFp = fopen (cBName,"w+");
|
|
|
|
|
if (!pFp)
|
2003-03-18 05:47:38 -06:00
|
|
|
|
fprintf( stderr, "Error opening DataBase File\n" );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
|
|
|
|
|
LibExport *pData;
|
|
|
|
|
for ( unsigned long i=0; i < nBaseLines+10; i++ )
|
|
|
|
|
{
|
|
|
|
|
char * cBuffer = new char[ 30 ];
|
|
|
|
|
sprintf( cBuffer, "%lu", i );
|
|
|
|
|
pData = pIndexTab->Find( cBuffer );
|
|
|
|
|
delete [] cBuffer;
|
|
|
|
|
if ( pData )
|
|
|
|
|
fprintf(pFp,"%s\n",pData->cExportName);
|
|
|
|
|
}
|
|
|
|
|
fclose(pFp);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LibDump::PrintDefFile()
|
|
|
|
|
{
|
|
|
|
|
#ifdef FAST
|
|
|
|
|
ExportSetIter aIterator( *pBaseTab );
|
|
|
|
|
for ( LibExport *pData = aIterator.GetFirst(); pData != NULL;
|
|
|
|
|
pData = aIterator.GetNext() )
|
|
|
|
|
{
|
|
|
|
|
if ( pData->bExport )
|
|
|
|
|
{
|
|
|
|
|
if ( pData->bByName )
|
|
|
|
|
{
|
2008-03-25 08:07:33 -05:00
|
|
|
|
fprintf(stdout,"\t%s\n",
|
|
|
|
|
pData->sExportName.GetBuffer());
|
2001-04-11 03:52:27 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-06-27 11:46:28 -05:00
|
|
|
|
fprintf(stdout,"\t%s\t\t@%d NONAME\n",
|
2001-04-11 03:52:27 -05:00
|
|
|
|
pData->sExportName.GetBuffer(), pData->nOrdinal+nBegin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
// sortiert nach Ordinals;
|
|
|
|
|
LibExport *pData;
|
|
|
|
|
for ( unsigned long i=0; i<nBaseLines+1; i++)
|
|
|
|
|
{
|
|
|
|
|
char * cBuffer = new char[ 30 ];
|
|
|
|
|
sprintf( cBuffer, "%lu", i );
|
|
|
|
|
pData = pIndexTab->Find( cBuffer );
|
|
|
|
|
delete [] cBuffer;
|
|
|
|
|
if ( pData )
|
|
|
|
|
if ( pData->bExport )
|
|
|
|
|
{
|
|
|
|
|
if ( pData->bByName )
|
|
|
|
|
{
|
|
|
|
|
if ( strlen( pData->cExportName ))
|
2008-03-25 08:07:33 -05:00
|
|
|
|
fprintf(stdout,"\t%s\n",
|
|
|
|
|
pData->cExportName);
|
2001-04-11 03:52:27 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( strlen( pData->cExportName ))
|
2007-06-27 11:46:28 -05:00
|
|
|
|
fprintf(stdout,"\t%s\t\t@%d NONAME\n",
|
2001-04-11 03:52:27 -05:00
|
|
|
|
pData->cExportName, pData->nOrdinal+nBegin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LibDump::CheckDataBase()
|
|
|
|
|
{
|
|
|
|
|
// existiert eine Datenbasis ?
|
|
|
|
|
if (!bBase)
|
|
|
|
|
{
|
|
|
|
|
cBName = new char[ 2048 ];
|
|
|
|
|
char *pTmp = "defs\\";
|
|
|
|
|
|
|
|
|
|
FILE *fp;
|
2007-09-20 09:59:43 -05:00
|
|
|
|
#ifdef OS2
|
|
|
|
|
_mkdir ("defs", 0777);
|
|
|
|
|
#else
|
2001-04-11 03:52:27 -05:00
|
|
|
|
_mkdir ("defs");
|
2007-09-20 09:59:43 -05:00
|
|
|
|
#endif
|
2001-04-11 03:52:27 -05:00
|
|
|
|
strcpy(cBName,pTmp);
|
2007-09-20 09:59:43 -05:00
|
|
|
|
#ifdef OS2
|
|
|
|
|
strcat(cBName,"gcc");
|
|
|
|
|
#else
|
2001-04-11 03:52:27 -05:00
|
|
|
|
strcat(cBName,getenv ("COMP_ENV"));
|
2007-09-20 09:59:43 -05:00
|
|
|
|
#endif
|
2001-04-11 03:52:27 -05:00
|
|
|
|
|
|
|
|
|
fp = fopen (cBName,"r");
|
|
|
|
|
if (fp)
|
|
|
|
|
{
|
|
|
|
|
bBase = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fp = fopen (cBName,"w+");
|
|
|
|
|
bBase = true;
|
|
|
|
|
}
|
|
|
|
|
fclose (fp);
|
|
|
|
|
}
|
|
|
|
|
// lese Datenbasis !
|
|
|
|
|
if (bBase)
|
|
|
|
|
{
|
|
|
|
|
ReadDataBase();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LibDump::~LibDump()
|
|
|
|
|
{
|
|
|
|
|
delete [] cBName;
|
|
|
|
|
delete [] cAPrefix;
|
|
|
|
|
// delete [] cLibName;
|
|
|
|
|
delete [] cFilterName;
|
|
|
|
|
delete [] cModName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LibDump::SetCExport( char* pName )
|
|
|
|
|
{
|
|
|
|
|
delete [] cAPrefix;
|
|
|
|
|
cAPrefix = new char[ strlen( pName ) + 1 ];
|
|
|
|
|
strcpy( cAPrefix, pName );bAll = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//******************************************************************
|
|
|
|
|
//* Error() - Gibt Fehlermeldumg aus
|
|
|
|
|
//******************************************************************
|
|
|
|
|
|
2006-06-19 23:08:37 -05:00
|
|
|
|
void LibDump::DumpError( unsigned long n )
|
2001-04-11 03:52:27 -05:00
|
|
|
|
{
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
switch (n)
|
|
|
|
|
{
|
|
|
|
|
case 1: p = "Input error in library file"; break;
|
|
|
|
|
case 2: p = "Position error in library file (no THEADR set)"; break;
|
|
|
|
|
case 3: p = "Overflow of symbol table"; break;
|
|
|
|
|
#ifdef WNT
|
|
|
|
|
case 10: p = "EXP file not found"; break;
|
|
|
|
|
case 11: p = "No valid EXP file"; break;
|
|
|
|
|
#else
|
|
|
|
|
case 10: p = "Library file not found"; break;
|
|
|
|
|
case 11: p = "No valid library file"; break;
|
|
|
|
|
#endif
|
|
|
|
|
case 98: p = "Out of memory"; break;
|
2007-06-27 11:46:28 -05:00
|
|
|
|
case 99: p = "LDUMP [-LD3] [-D] [-N] [-A] [-E nn] [-F name] Filename[.LIB]\n"
|
2001-04-11 03:52:27 -05:00
|
|
|
|
"-LD3 : Supports feature set of ldump3 (default: ldump/ldump2)\n"
|
|
|
|
|
"-A : all symbols (default: only C++)\n"
|
|
|
|
|
"-E nn : gerenration of export table beginning with number nn\n"
|
2004-08-23 03:13:12 -05:00
|
|
|
|
"-F name: Filter file\n"
|
2007-04-26 08:01:35 -05:00
|
|
|
|
"-D : file contains \"dumpbin\" directives\n"
|
2007-06-27 11:46:28 -05:00
|
|
|
|
"-N : export by name\n"
|
2007-04-26 08:01:35 -05:00
|
|
|
|
"-V : be verbose\n"; break;
|
2001-04-11 03:52:27 -05:00
|
|
|
|
case 500: p = "Unable to open filter file\n"; break;
|
|
|
|
|
case 510: p = "Overflow of filter table\n"; break;
|
|
|
|
|
case 600: p = "Unable to open base database file\n"; break;
|
|
|
|
|
case 610: p = "Overflow in base database table\n"; break;
|
|
|
|
|
default: p = "Unspecified error";
|
|
|
|
|
}
|
2003-03-18 05:47:38 -06:00
|
|
|
|
fprintf( stdout, "%s\n", p );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
|
Test Funktionen
|
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
2006-06-19 23:08:37 -05:00
|
|
|
|
void usage()
|
2001-04-11 03:52:27 -05:00
|
|
|
|
{
|
|
|
|
|
LibDump::DumpError(99);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define STATE_NON 0x0000
|
|
|
|
|
#define STATE_BEGIN 0x0001
|
|
|
|
|
#define STATE_FILTER 0x0002
|
|
|
|
|
#define STATE_CEXPORT 0x0003
|
|
|
|
|
|
2007-09-20 09:59:43 -05:00
|
|
|
|
int
|
2001-04-11 03:52:27 -05:00
|
|
|
|
#ifdef WNT
|
2007-09-20 09:59:43 -05:00
|
|
|
|
__cdecl
|
2001-04-11 03:52:27 -05:00
|
|
|
|
#endif
|
|
|
|
|
main( int argc, char **argv )
|
|
|
|
|
{
|
2006-06-19 23:08:37 -05:00
|
|
|
|
char *pLibName = NULL, *pFilterName = NULL, *pCExport= NULL;
|
|
|
|
|
unsigned short nBegin=1;
|
2001-04-11 03:52:27 -05:00
|
|
|
|
|
|
|
|
|
unsigned short nState = STATE_NON;
|
|
|
|
|
|
|
|
|
|
if ( argc == 1 ) {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( int i = 1; i < argc; i++ ) {
|
|
|
|
|
if (( !strcmp( argv[ i ], "-H" )) ||
|
|
|
|
|
( !strcmp( argv[ i ], "-h" )) ||
|
|
|
|
|
( !strcmp( argv[ i ], "-?" )))
|
|
|
|
|
{
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
else if (( !strcmp( argv[ i ], "-LD3" )) ||
|
|
|
|
|
( !strcmp( argv[ i ], "-Ld3" )) ||
|
|
|
|
|
( !strcmp( argv[ i ], "-ld3" )) ||
|
|
|
|
|
( !strcmp( argv[ i ], "-lD3" )))
|
|
|
|
|
{
|
|
|
|
|
if ( nState != STATE_NON ) {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
bLdump3 = 1;
|
|
|
|
|
}
|
|
|
|
|
else if (( !strcmp( argv[ i ], "-E" )) || ( !strcmp( argv[ i ], "-e" ))) {
|
|
|
|
|
if ( nState != STATE_NON ) {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
nState = STATE_BEGIN;
|
|
|
|
|
}
|
|
|
|
|
else if (( !strcmp( argv[ i ], "-F" )) || ( !strcmp( argv[ i ], "-f" ))) {
|
|
|
|
|
if ( nState != STATE_NON ) {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
nState = STATE_FILTER;
|
|
|
|
|
}
|
|
|
|
|
else if (( !strcmp( argv[ i ], "-A" )) || ( !strcmp( argv[ i ], "-a" ))) {
|
|
|
|
|
if ( nState != STATE_NON ) {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
nState = STATE_CEXPORT;
|
|
|
|
|
pCExport = new char[ 1 ];
|
|
|
|
|
pCExport[ 0 ] = 0;
|
|
|
|
|
}
|
2004-08-23 03:13:12 -05:00
|
|
|
|
else if (( !strcmp( argv[ i ], "-D" )) || ( !strcmp( argv[ i ], "-d" ))) {
|
|
|
|
|
if ( nState != STATE_NON ) {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
bUseDirectives = 1;
|
|
|
|
|
}
|
2007-06-27 11:46:28 -05:00
|
|
|
|
else if (( !strcmp( argv[ i ], "-N" )) || ( !strcmp( argv[ i ], "-n" ))) {
|
|
|
|
|
if ( nState != STATE_NON ) {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
bExportByName = 1;
|
|
|
|
|
}
|
2007-04-26 08:01:35 -05:00
|
|
|
|
else if (( !strcmp( argv[ i ], "-V" )) || ( !strcmp( argv[ i ], "-v" ))) {
|
|
|
|
|
if ( nState != STATE_NON ) {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
bVerbose = 1;
|
|
|
|
|
}
|
2001-04-11 03:52:27 -05:00
|
|
|
|
else {
|
|
|
|
|
switch ( nState ) {
|
|
|
|
|
case STATE_BEGIN:
|
2006-06-19 23:08:37 -05:00
|
|
|
|
nBegin = static_cast< unsigned short >(atoi( argv[ i ] ));
|
2001-04-11 03:52:27 -05:00
|
|
|
|
nState = STATE_NON;
|
|
|
|
|
break;
|
|
|
|
|
case STATE_FILTER:
|
|
|
|
|
pFilterName = new char[ strlen( argv[ i ] ) + 1 ];
|
|
|
|
|
strcpy( pFilterName, argv[ i ] );
|
|
|
|
|
bFilter = 1;
|
|
|
|
|
nState = STATE_NON;
|
|
|
|
|
break;
|
|
|
|
|
case STATE_CEXPORT:
|
|
|
|
|
delete [] pCExport;
|
|
|
|
|
pCExport = new char[ strlen( argv[ i ] ) + 1 ];
|
|
|
|
|
strcpy( pCExport, argv[ i ] );
|
|
|
|
|
nState = STATE_NON;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
pLibName = new char[ strlen( argv[ i ] ) + 1 ];
|
|
|
|
|
strcpy( pLibName, argv[ i ] );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !pLibName ) {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-25 08:07:33 -05:00
|
|
|
|
LibDump *pDump = new LibDump( pLibName, bExportByName );
|
2001-04-11 03:52:27 -05:00
|
|
|
|
pDump->SetBeginExport(nBegin);
|
|
|
|
|
if ( bFilter != 0 )
|
|
|
|
|
pDump->SetFilter( pFilterName );
|
|
|
|
|
if ( pCExport )
|
|
|
|
|
pDump->SetCExport( pCExport );
|
|
|
|
|
else {
|
|
|
|
|
char *pEmpty = "";
|
|
|
|
|
pDump->SetCExport( pEmpty );
|
|
|
|
|
}
|
|
|
|
|
pDump->Dump();
|
|
|
|
|
pDump->PrintDefFile();
|
|
|
|
|
pDump->PrintDataBase();
|
|
|
|
|
delete pDump;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|