Gaudi Framework, version v23r3

Home   Generated: Thu Jun 28 2012
Public Member Functions | Protected Member Functions | Protected Attributes

CLibSymbolInfo Class Reference

#include <LibSymbolInfo.h>

Collaboration diagram for CLibSymbolInfo:
Collaboration graph
[legend]

List of all members.

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 19 of file LibSymbolInfo.h.


Constructor & Destructor Documentation

CLibSymbolInfo::CLibSymbolInfo (  )

Definition at line 23 of file LibSymbolInfo.cpp.

{
}
CLibSymbolInfo::~CLibSymbolInfo (  ) [virtual]

Definition at line 27 of file LibSymbolInfo.cpp.

{
}

Member Function Documentation

DWORD CLibSymbolInfo::ConvertBigEndian ( DWORD  bigEndian ) [protected]

Definition at line 179 of file LibSymbolInfo.cpp.

{
  DWORD temp = 0;

  temp |= bigEndian >> 24;
  temp |= ((bigEndian & 0x00FF0000) >> 8);
  temp |= ((bigEndian & 0x0000FF00) << 8);
  temp |= ((bigEndian & 0x000000FF) << 24);

  return temp;
}
BOOL CLibSymbolInfo::Dump ( LPTSTR  lpszLibPathName,
std::ostream pFile 
) [protected]

Definition at line 67 of file LibSymbolInfo.cpp.

{
  string sBuff;
  MEMORY_MAPPED_FILE libFile(lpszLibPathName);
        
  // Ensure that the file mapping worked
  if( FALSE == libFile.IsValid() ) {
        m_strErrorMsg = "Unable to access file ";
    m_strErrorMsg+= lpszLibPathName;
    return FALSE;
  }
  // All COFF libraries start with the string "!<arch>\n".  Verify that this
  // string is at the beginning of the mapped file

  PSTR pArchiveStartString = (PSTR)libFile.GetBase();

  if ( 0 != strncmp( pArchiveStartString, IMAGE_ARCHIVE_START,
                       IMAGE_ARCHIVE_START_SIZE )  )  {
      m_strErrorMsg.assign("Not a valid COFF LIB file.");
        return FALSE;
  }
    
  // Point to the first archive member.  This entry contains the LIB symbols,
  // and immediately follows the archive start string ("!<arch>\n")
  PIMAGE_ARCHIVE_MEMBER_HEADER pMbrHdr;
  pMbrHdr = MakePtr( PIMAGE_ARCHIVE_MEMBER_HEADER, pArchiveStartString,
                     IMAGE_ARCHIVE_START_SIZE );

  // First DWORD after this member header is a symbol count
  PDWORD pcbSymbols = (PDWORD)(pMbrHdr + 1);  // Pointer math!

  // The symbol count is stored in big endian format, so adjust as
  // appropriate for the target architecture
  DWORD cSymbols = ConvertBigEndian( *pcbSymbols );

  // Following the symbol count is an array of offsets to archive members
  // (essentially, embedded .OBJ files)
  PDWORD pMemberOffsets = pcbSymbols + 1;     // Pointer math!

  // Following the array of member offsets is an array of offsets to symbol
  // names.
  PSTR pszSymbolName = MakePtr( PSTR, pMemberOffsets, 4 * cSymbols );

  //
  // Loop through every symbol in the first archive member
  //      
  for ( unsigned i = 0; i < cSymbols; i++ )
  {
    DWORD offset;

    // The offsets to the archive member that contains the symbol is stored
    // in big endian format, so convert it appropriately.        
    offset = ConvertBigEndian( *pMemberOffsets );

    // Call DisplayLibInfoForSymbol, which figures out what kind of symbol
    // it is.  The "IsRegularLibSymbol" filters out symbols that are
    // internal to the linking process
    if ( IsRegularLibSymbol( pszSymbolName ) ) {
      string symbol(pszSymbolName);
      if (IsFiltedSymbol(symbol) ) {
        pFile << symbol << endl;
          }
    }            
    // Advanced to the next symbol offset and name.  The MemberOffsets
    // array has fixed length entries, while the symbol names are
    // sequential null-terminated strings
    pMemberOffsets++;
    pszSymbolName += strlen(pszSymbolName) + 1;
  }
  return TRUE;
}
BOOL CLibSymbolInfo::DumpSymbols ( LPTSTR  lpszLibPathName,
std::ostream pFile 
)

Definition at line 43 of file LibSymbolInfo.cpp.

{
  if(lpszLibPathName == NULL || pFile.bad() ) {
    assert(lpszLibPathName != NULL);
    assert(pFile.good());
    m_strErrorMsg.assign("NULL <lpszLibPathName> or Invalid file handle.");
    return FALSE;
  }

  if(!Dump(lpszLibPathName, pFile))  return FALSE;
  return TRUE;
}
string CLibSymbolInfo::GetLastError (  ) const

Definition at line 191 of file LibSymbolInfo.cpp.

{
  return m_strErrorMsg;
}
BOOL CLibSymbolInfo::IsFiltedSymbol ( std::string pszSymbolName ) [protected]

Definition at line 159 of file LibSymbolInfo.cpp.

{
  if ( symbolName.substr(0,2) == "__" ) 
    return FALSE;
  if ( symbolName.substr(0,3) == "??_" && symbolName[3] != '0') // Keep 'operator/='  [??_0]
    return FALSE;
  if( symbolName[0] == '_') {
    symbolName.erase(0, 1);  // C functions ...
  }
  // Filter the internal Boost symbols
  if (symbolName.find ("detail@boost") != string::npos )
        return FALSE;
  if (symbolName.find ("details@boost") != string::npos ) 
        return FALSE;
  return TRUE;
}
BOOL CLibSymbolInfo::IsRegularLibSymbol ( PSTR  pszSymbolName ) [protected]

Definition at line 143 of file LibSymbolInfo.cpp.

{
  if ( 0 == strncmp( pszSymbolName, "__IMPORT_DESCRIPTOR_", 20 ) )
      return FALSE;

  if ( 0 == strncmp( pszSymbolName, "__NULL_IMPORT_DESCRIPTOR", 24 ) )
      return FALSE;
      
  if ( strstr( pszSymbolName, "_NULL_THUNK_DATA" ) )
      return FALSE;
        
  return TRUE;
}

Member Data Documentation

Definition at line 29 of file LibSymbolInfo.h.

Definition at line 28 of file LibSymbolInfo.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 12:30:07 for Gaudi Framework, version v23r3 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004