Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
 
 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)
 
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 44 of file LibSymbolInfo.h.

Constructor & Destructor Documentation

CLibSymbolInfo::CLibSymbolInfo ( )

Definition at line 23 of file LibSymbolInfo.cpp.

24 {
25 }
CLibSymbolInfo::~CLibSymbolInfo ( )
virtual

Definition at line 27 of file LibSymbolInfo.cpp.

28 {
29 }
CLibSymbolInfo::CLibSymbolInfo ( )
virtual CLibSymbolInfo::~CLibSymbolInfo ( )
virtual

Member Function Documentation

DWORD CLibSymbolInfo::ConvertBigEndian ( DWORD  bigEndian)
protected

Definition at line 183 of file LibSymbolInfo.cpp.

184 {
185  DWORD temp = 0;
186 
187  temp |= bigEndian >> 24;
188  temp |= ((bigEndian & 0x00FF0000) >> 8);
189  temp |= ((bigEndian & 0x0000FF00) << 8);
190  temp |= ((bigEndian & 0x000000FF) << 24);
191 
192  return temp;
193 }
DWORD CLibSymbolInfo::ConvertBigEndian ( DWORD  bigEndian)
protected
BOOL CLibSymbolInfo::Dump ( LPTSTR  lpszLibPathName,
std::ostream &  pFile 
)
protected

Definition at line 67 of file LibSymbolInfo.cpp.

68 {
69  string sBuff;
70  MEMORY_MAPPED_FILE libFile(lpszLibPathName);
71 
72  // Ensure that the file mapping worked
73  if( FALSE == libFile.IsValid() ) {
74  m_strErrorMsg = "Unable to access file ";
75  m_strErrorMsg+= lpszLibPathName;
76  return FALSE;
77  }
78  // All COFF libraries start with the string "!<arch>\n". Verify that this
79  // string is at the beginning of the mapped file
80 
81  PSTR pArchiveStartString = (PSTR)libFile.GetBase();
82 
83  if ( 0 != strncmp( pArchiveStartString, IMAGE_ARCHIVE_START,
84  IMAGE_ARCHIVE_START_SIZE ) ) {
85  m_strErrorMsg.assign("Not a valid COFF LIB file.");
86  return FALSE;
87  }
88 
89  // Point to the first archive member. This entry contains the LIB symbols,
90  // and immediately follows the archive start string ("!<arch>\n")
91  PIMAGE_ARCHIVE_MEMBER_HEADER pMbrHdr;
92  pMbrHdr = MakePtr( PIMAGE_ARCHIVE_MEMBER_HEADER, pArchiveStartString,
93  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  {
115  DWORD offset;
116 
117  // The offsets to the archive member that contains the symbol is stored
118  // in big endian format, so convert it appropriately.
119  offset = ConvertBigEndian( *pMemberOffsets );
120 
121  // Call DisplayLibInfoForSymbol, which figures out what kind of symbol
122  // it is. The "IsRegularLibSymbol" filters out symbols that are
123  // internal to the linking process
124  if ( IsRegularLibSymbol( pszSymbolName ) ) {
125  string symbol(pszSymbolName);
126  if (IsFiltedSymbol(symbol) ) {
127  pFile << symbol << endl;
128  }
129  }
130  // Advanced to the next symbol offset and name. The MemberOffsets
131  // array has fixed length entries, while the symbol names are
132  // sequential null-terminated strings
133  pMemberOffsets++;
134  pszSymbolName += strlen(pszSymbolName) + 1;
135  }
136  return TRUE;
137 }
#define MakePtr(cast, ptr, addValue)
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55
std::string m_strErrorMsg
Definition: LibSymbolInfo.h:54
BOOL IsFiltedSymbol(std::string &pszSymbolName)
DWORD ConvertBigEndian(DWORD bigEndian)
BOOL IsRegularLibSymbol(PSTR pszSymbolName)

Here is the call graph for this function:

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

Definition at line 43 of file LibSymbolInfo.cpp.

44 {
45  if(lpszLibPathName == NULL || pFile.bad() ) {
46  assert(lpszLibPathName != NULL);
47  assert(pFile.good());
48  m_strErrorMsg.assign("NULL <lpszLibPathName> or Invalid file handle.");
49  return FALSE;
50  }
51 
52  if(!Dump(lpszLibPathName, pFile)) return FALSE;
53  return TRUE;
54 }
#define FALSE
Definition: globals.hh:52
BOOL Dump(LPTSTR lpszLibPathName, std::ostream &pFile)
#define TRUE
Definition: globals.hh:55
std::string m_strErrorMsg
Definition: LibSymbolInfo.h:54

Here is the caller graph for this function:

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

Definition at line 195 of file LibSymbolInfo.cpp.

196 {
197  return m_strErrorMsg;
198 }
std::string m_strErrorMsg
Definition: LibSymbolInfo.h:54
std::string CLibSymbolInfo::GetLastError ( ) const
BOOL CLibSymbolInfo::IsFiltedSymbol ( std::string &  pszSymbolName)
protected

Definition at line 159 of file LibSymbolInfo.cpp.

160 {
161  // Filter problematic symbols for Win64
162  if ( symbolName.substr(0,3) == "_CT" ) return FALSE;
163  if ( symbolName.substr(0,3) == "_TI" ) return FALSE;
164  // Filter other symbols
165  if ( symbolName.substr(0,2) == "__" )
166  return FALSE;
167  if ( symbolName.substr(0,3) == "??_" && symbolName[3] != '0') // Keep 'operator/=' [??_0]
168  return FALSE;
169  if( symbolName[0] == '_') {
170  symbolName.erase(0, 1); // C functions ...
171  }
172  // Filter the internal Boost symbols
173  if (symbolName.find ("detail@boost") != string::npos )
174  return FALSE;
175  if (symbolName.find ("details@boost") != string::npos )
176  return FALSE;
177  return TRUE;
178 }
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55
BOOL CLibSymbolInfo::IsFiltedSymbol ( std::string &  pszSymbolName)
protected
BOOL CLibSymbolInfo::IsRegularLibSymbol ( PSTR  pszSymbolName)
protected

Definition at line 143 of file LibSymbolInfo.cpp.

144 {
145  if ( 0 == strncmp( pszSymbolName, "__IMPORT_DESCRIPTOR_", 20 ) )
146  return FALSE;
147 
148  if ( 0 == strncmp( pszSymbolName, "__NULL_IMPORT_DESCRIPTOR", 24 ) )
149  return FALSE;
150 
151  if ( strstr( pszSymbolName, "_NULL_THUNK_DATA" ) )
152  return FALSE;
153 
154  return TRUE;
155 }
#define FALSE
Definition: globals.hh:52
#define TRUE
Definition: globals.hh:55
BOOL CLibSymbolInfo::IsRegularLibSymbol ( PSTR  pszSymbolName)
protected

Member Data Documentation

std::string CLibSymbolInfo::m_strErrorMsg
protected

Definition at line 54 of file LibSymbolInfo.h.

std::string CLibSymbolInfo::m_strResultsString
protected

Definition at line 53 of file LibSymbolInfo.h.


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