The Gaudi Framework  master (594c33fa)
CLibSymbolInfo Class Reference

#include </builds/gaudi/Gaudi/GaudiKernel/src/Util/LibSymbolInfo.h>

Collaboration diagram for CLibSymbolInfo:

Public Member Functions

 CLibSymbolInfo ()
 
virtual ~CLibSymbolInfo ()
 
BOOL DumpSymbols (LPTSTR lpszLibPathName, std::ostream &pFile)
 
std::string GetLastError () const
 

Protected Member Functions

BOOL Dump (LPTSTR lpszLibPathName, std::ostream &pFile)
 
BOOL IsRegularLibSymbol (PSTR pszSymbolName)
 
BOOL IsFiltedSymbol (std::string &pszSymbolName)
 
DWORD ConvertBigEndian (DWORD bigEndian)
 

Protected Attributes

std::string m_strResultsString
 
std::string m_strErrorMsg
 

Detailed Description

Definition at line 25 of file LibSymbolInfo.h.

Constructor & Destructor Documentation

◆ CLibSymbolInfo()

CLibSymbolInfo::CLibSymbolInfo ( )

Definition at line 31 of file LibSymbolInfo.cpp.

31 {}

◆ ~CLibSymbolInfo()

CLibSymbolInfo::~CLibSymbolInfo ( )
virtual

Definition at line 33 of file LibSymbolInfo.cpp.

33 {}

Member Function Documentation

◆ ConvertBigEndian()

DWORD CLibSymbolInfo::ConvertBigEndian ( DWORD  bigEndian)
protected

Definition at line 168 of file LibSymbolInfo.cpp.

168  {
169  DWORD temp = 0;
170 
171  temp |= bigEndian >> 24;
172  temp |= ( ( bigEndian & 0x00FF0000 ) >> 8 );
173  temp |= ( ( bigEndian & 0x0000FF00 ) << 8 );
174  temp |= ( ( bigEndian & 0x000000FF ) << 24 );
175 
176  return temp;
177 }

◆ Dump()

BOOL CLibSymbolInfo::Dump ( LPTSTR  lpszLibPathName,
std::ostream pFile 
)
protected

Definition at line 70 of file LibSymbolInfo.cpp.

70  {
71  string sBuff;
72  MEMORY_MAPPED_FILE libFile( lpszLibPathName );
73 
74  // Ensure that the file mapping worked
75  if ( FALSE == libFile.IsValid() ) {
76  m_strErrorMsg = "Unable to access file ";
77  m_strErrorMsg += lpszLibPathName;
78  return FALSE;
79  }
80  // All COFF libraries start with the string "!<arch>\n". Verify that this
81  // string is at the beginning of the mapped file
82 
83  PSTR pArchiveStartString = (PSTR)libFile.GetBase();
84 
85  if ( 0 != strncmp( pArchiveStartString, IMAGE_ARCHIVE_START, IMAGE_ARCHIVE_START_SIZE ) ) {
86  m_strErrorMsg.assign( "Not a valid COFF LIB file." );
87  return FALSE;
88  }
89 
90  // Point to the first archive member. This entry contains the LIB symbols,
91  // and immediately follows the archive start string ("!<arch>\n")
92  PIMAGE_ARCHIVE_MEMBER_HEADER pMbrHdr;
93  pMbrHdr = MakePtr( PIMAGE_ARCHIVE_MEMBER_HEADER, pArchiveStartString, IMAGE_ARCHIVE_START_SIZE );
94 
95  // First DWORD after this member header is a symbol count
96  PDWORD pcbSymbols = (PDWORD)( pMbrHdr + 1 ); // Pointer math!
97 
98  // The symbol count is stored in big endian format, so adjust as
99  // appropriate for the target architecture
100  DWORD cSymbols = ConvertBigEndian( *pcbSymbols );
101 
102  // Following the symbol count is an array of offsets to archive members
103  // (essentially, embedded .OBJ files)
104  PDWORD pMemberOffsets = pcbSymbols + 1; // Pointer math!
105 
106  // Following the array of member offsets is an array of offsets to symbol
107  // names.
108  PSTR pszSymbolName = MakePtr( PSTR, pMemberOffsets, 4 * cSymbols );
109 
110  //
111  // Loop through every symbol in the first archive member
112  //
113  for ( unsigned i = 0; i < cSymbols; i++ ) {
114  DWORD offset;
115 
116  // The offsets to the archive member that contains the symbol is stored
117  // in big endian format, so convert it appropriately.
118  offset = ConvertBigEndian( *pMemberOffsets );
119 
120  // Call DisplayLibInfoForSymbol, which figures out what kind of symbol
121  // it is. The "IsRegularLibSymbol" filters out symbols that are
122  // internal to the linking process
123  if ( IsRegularLibSymbol( pszSymbolName ) ) {
124  string symbol( pszSymbolName );
125  if ( IsFiltedSymbol( symbol ) ) { pFile << symbol << endl; }
126  }
127  // Advanced to the next symbol offset and name. The MemberOffsets
128  // array has fixed length entries, while the symbol names are
129  // sequential null-terminated strings
130  pMemberOffsets++;
131  pszSymbolName += strlen( pszSymbolName ) + 1;
132  }
133  return TRUE;
134 }

◆ DumpSymbols()

BOOL CLibSymbolInfo::DumpSymbols ( LPTSTR  lpszLibPathName,
std::ostream pFile 
)

Definition at line 47 of file LibSymbolInfo.cpp.

47  {
48  if ( lpszLibPathName == NULL || pFile.bad() ) {
49  assert( lpszLibPathName != NULL );
50  assert( pFile.good() );
51  m_strErrorMsg.assign( "NULL <lpszLibPathName> or Invalid file handle." );
52  return FALSE;
53  }
54 
55  if ( !Dump( lpszLibPathName, pFile ) ) return FALSE;
56  return TRUE;
57 }

◆ GetLastError()

string CLibSymbolInfo::GetLastError ( ) const

Definition at line 179 of file LibSymbolInfo.cpp.

179 { return m_strErrorMsg; }

◆ IsFiltedSymbol()

BOOL CLibSymbolInfo::IsFiltedSymbol ( std::string pszSymbolName)
protected

Definition at line 152 of file LibSymbolInfo.cpp.

152  {
153  if ( symbolName.compare( 0, 2, "__" ) == 0 ) return FALSE;
154  if ( symbolName.compare( 0, 3, "??_" ) == 0 && symbolName[3] != '0' ) // Keep 'operator/=' [??_0]
155  return FALSE;
156  if ( symbolName[0] == '_' ) {
157  symbolName.erase( 0, 1 ); // C functions ...
158  }
159  // Filter the internal Boost symbols
160  if ( symbolName.find( "detail@boost" ) != string::npos ) return FALSE;
161  if ( symbolName.find( "details@boost" ) != string::npos ) return FALSE;
162  return TRUE;
163 }

◆ IsRegularLibSymbol()

BOOL CLibSymbolInfo::IsRegularLibSymbol ( PSTR  pszSymbolName)
protected

Definition at line 140 of file LibSymbolInfo.cpp.

140  {
141  if ( 0 == strncmp( pszSymbolName, "__IMPORT_DESCRIPTOR_", 20 ) ) return FALSE;
142 
143  if ( 0 == strncmp( pszSymbolName, "__NULL_IMPORT_DESCRIPTOR", 24 ) ) return FALSE;
144 
145  if ( strstr( pszSymbolName, "_NULL_THUNK_DATA" ) ) return FALSE;
146 
147  return TRUE;
148 }

Member Data Documentation

◆ m_strErrorMsg

std::string CLibSymbolInfo::m_strErrorMsg
protected

Definition at line 34 of file LibSymbolInfo.h.

◆ m_strResultsString

std::string CLibSymbolInfo::m_strResultsString
protected

Definition at line 33 of file LibSymbolInfo.h.


The documentation for this class was generated from the following files:
std::strlen
T strlen(T... args)
CLibSymbolInfo::IsFiltedSymbol
BOOL IsFiltedSymbol(std::string &pszSymbolName)
Definition: LibSymbolInfo.cpp:152
MEMORY_MAPPED_FILE
Definition: LibSymbolInfo.h:44
std::ostream::bad
T bad(T... args)
CLibSymbolInfo::IsRegularLibSymbol
BOOL IsRegularLibSymbol(PSTR pszSymbolName)
Definition: LibSymbolInfo.cpp:140
CLibSymbolInfo::ConvertBigEndian
DWORD ConvertBigEndian(DWORD bigEndian)
Definition: LibSymbolInfo.cpp:168
std::ostream::good
T good(T... args)
std::strstr
T strstr(T... args)
std::strncmp
T strncmp(T... args)
std::endl
T endl(T... args)
CLibSymbolInfo::m_strErrorMsg
std::string m_strErrorMsg
Definition: LibSymbolInfo.h:34
std::string::assign
T assign(T... args)
CLibSymbolInfo::Dump
BOOL Dump(LPTSTR lpszLibPathName, std::ostream &pFile)
Definition: LibSymbolInfo.cpp:70
MakePtr
#define MakePtr(cast, ptr, addValue)
Definition: LibSymbolInfo.cpp:26
GaudiKernel.Constants.TRUE
TRUE
Definition: Constants.py:37
GaudiKernel.Constants.FALSE
FALSE
Definition: Constants.py:38