The Gaudi Framework  v31r0 (aeb156f0)
CLibSymbolInfo Class Reference

#include <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 15 of file LibSymbolInfo.h.

Constructor & Destructor Documentation

CLibSymbolInfo::CLibSymbolInfo ( )

Definition at line 21 of file LibSymbolInfo.cpp.

21 {}
CLibSymbolInfo::~CLibSymbolInfo ( )
virtual

Definition at line 23 of file LibSymbolInfo.cpp.

23 {}

Member Function Documentation

DWORD CLibSymbolInfo::ConvertBigEndian ( DWORD  bigEndian)
protected

Definition at line 158 of file LibSymbolInfo.cpp.

158  {
159  DWORD temp = 0;
160 
161  temp |= bigEndian >> 24;
162  temp |= ( ( bigEndian & 0x00FF0000 ) >> 8 );
163  temp |= ( ( bigEndian & 0x0000FF00 ) << 8 );
164  temp |= ( ( bigEndian & 0x000000FF ) << 24 );
165 
166  return temp;
167 }
BOOL CLibSymbolInfo::Dump ( LPTSTR  lpszLibPathName,
std::ostream pFile 
)
protected

Definition at line 60 of file LibSymbolInfo.cpp.

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

Definition at line 37 of file LibSymbolInfo.cpp.

37  {
38  if ( lpszLibPathName == NULL || pFile.bad() ) {
39  assert( lpszLibPathName != NULL );
40  assert( pFile.good() );
41  m_strErrorMsg.assign( "NULL <lpszLibPathName> or Invalid file handle." );
42  return FALSE;
43  }
44 
45  if ( !Dump( lpszLibPathName, pFile ) ) return FALSE;
46  return TRUE;
47 }
T good(T...args)
BOOL Dump(LPTSTR lpszLibPathName, std::ostream &pFile)
std::string m_strErrorMsg
Definition: LibSymbolInfo.h:24
T assign(T...args)
T bad(T...args)
string CLibSymbolInfo::GetLastError ( ) const

Definition at line 169 of file LibSymbolInfo.cpp.

169 { return m_strErrorMsg; }
std::string m_strErrorMsg
Definition: LibSymbolInfo.h:24
BOOL CLibSymbolInfo::IsFiltedSymbol ( std::string pszSymbolName)
protected

Definition at line 142 of file LibSymbolInfo.cpp.

142  {
143  if ( symbolName.compare( 0, 2, "__" ) == 0 ) return FALSE;
144  if ( symbolName.compare( 0, 3, "??_" ) == 0 && symbolName[3] != '0' ) // Keep 'operator/=' [??_0]
145  return FALSE;
146  if ( symbolName[0] == '_' ) {
147  symbolName.erase( 0, 1 ); // C functions ...
148  }
149  // Filter the internal Boost symbols
150  if ( symbolName.find( "detail@boost" ) != string::npos ) return FALSE;
151  if ( symbolName.find( "details@boost" ) != string::npos ) return FALSE;
152  return TRUE;
153 }
BOOL CLibSymbolInfo::IsRegularLibSymbol ( PSTR  pszSymbolName)
protected

Definition at line 130 of file LibSymbolInfo.cpp.

130  {
131  if ( 0 == strncmp( pszSymbolName, "__IMPORT_DESCRIPTOR_", 20 ) ) return FALSE;
132 
133  if ( 0 == strncmp( pszSymbolName, "__NULL_IMPORT_DESCRIPTOR", 24 ) ) return FALSE;
134 
135  if ( strstr( pszSymbolName, "_NULL_THUNK_DATA" ) ) return FALSE;
136 
137  return TRUE;
138 }
T strncmp(T...args)
T strstr(T...args)

Member Data Documentation

std::string CLibSymbolInfo::m_strErrorMsg
protected

Definition at line 24 of file LibSymbolInfo.h.

std::string CLibSymbolInfo::m_strResultsString
protected

Definition at line 23 of file LibSymbolInfo.h.


The documentation for this class was generated from the following files: