Geant4-11
Public Member Functions | Protected Member Functions | Protected Attributes
CLibSymbolInfo Class Reference

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

std::string m_strErrorMsg
 
std::string m_strResultsString
 

Detailed Description

Definition at line 58 of file genwindef.cc.

Constructor & Destructor Documentation

◆ CLibSymbolInfo()

CLibSymbolInfo::CLibSymbolInfo ( )

Definition at line 110 of file genwindef.cc.

111{
112}

◆ ~CLibSymbolInfo()

CLibSymbolInfo::~CLibSymbolInfo ( )
virtual

Definition at line 114 of file genwindef.cc.

115{
116}

Member Function Documentation

◆ ConvertBigEndian()

DWORD CLibSymbolInfo::ConvertBigEndian ( DWORD  bigEndian)
protected

Definition at line 270 of file genwindef.cc.

271{
272 DWORD temp = 0;
273
274 temp |= bigEndian >> 24;
275 temp |= ((bigEndian & 0x00FF0000) >> 8);
276 temp |= ((bigEndian & 0x0000FF00) << 8);
277 temp |= ((bigEndian & 0x000000FF) << 24);
278
279 return temp;
280}

Referenced by Dump().

◆ Dump()

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

Definition at line 154 of file genwindef.cc.

155{
156 string sBuff;
157 MEMORY_MAPPED_FILE libFile(lpszLibPathName);
158
159 // Ensure that the file mapping worked
160 if( FALSE == libFile.IsValid() ) {
161 m_strErrorMsg = "Unable to access file ";
162 m_strErrorMsg+= lpszLibPathName;
163 return FALSE;
164 }
165 // All COFF libraries start with the string "!<arch>\n". Verify that this
166 // string is at the beginning of the mapped file
167
168 PSTR pArchiveStartString = (PSTR)libFile.GetBase();
169
170 if ( 0 != strncmp( pArchiveStartString, IMAGE_ARCHIVE_START,
171 IMAGE_ARCHIVE_START_SIZE ) ) {
172 m_strErrorMsg.assign("Not a valid COFF LIB file.");
173 return FALSE;
174 }
175
176 // Point to the first archive member. This entry contains the LIB symbols,
177 // and immediately follows the archive start string ("!<arch>\n")
178 PIMAGE_ARCHIVE_MEMBER_HEADER pMbrHdr;
179 pMbrHdr = MakePtr( PIMAGE_ARCHIVE_MEMBER_HEADER, pArchiveStartString,
180 IMAGE_ARCHIVE_START_SIZE );
181
182 // First DWORD after this member header is a symbol count
183 PDWORD pcbSymbols = (PDWORD)(pMbrHdr + 1); // Pointer math!
184
185 // The symbol count is stored in big endian format, so adjust as
186 // appropriate for the target architecture
187 DWORD cSymbols = ConvertBigEndian( *pcbSymbols );
188
189 // Following the symbol count is an array of offsets to archive members
190 // (essentially, embedded .OBJ files)
191 PDWORD pMemberOffsets = pcbSymbols + 1; // Pointer math!
192
193 // Following the array of member offsets is an array of offsets to symbol
194 // names.
195 PSTR pszSymbolName = MakePtr( PSTR, pMemberOffsets, 4 * cSymbols );
196
197 //
198 // Loop through every symbol in the first archive member
199 //
200 for ( unsigned i = 0; i < cSymbols; i++ )
201 {
202 DWORD offset;
203
204 // The offsets to the archive member that contains the symbol is stored
205 // in big endian format, so convert it appropriately.
206 offset = ConvertBigEndian( *pMemberOffsets );
207
208 // Call DisplayLibInfoForSymbol, which figures out what kind of symbol
209 // it is. The "IsRegularLibSymbol" filters out symbols that are
210 // internal to the linking process
211 if ( IsRegularLibSymbol( pszSymbolName ) ) {
212 string symbol(pszSymbolName);
213 if (IsFiltedSymbol(symbol) ) {
214 pFile << symbol << endl;
215 }
216 }
217 // Advanced to the next symbol offset and name. The MemberOffsets
218 // array has fixed length entries, while the symbol names are
219 // sequential null-terminated strings
220 pMemberOffsets++;
221 pszSymbolName += strlen(pszSymbolName) + 1;
222 }
223 return TRUE;
224}
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23
std::string m_strErrorMsg
Definition: genwindef.cc:68
BOOL IsRegularLibSymbol(PSTR pszSymbolName)
Definition: genwindef.cc:230
BOOL IsFiltedSymbol(std::string &pszSymbolName)
Definition: genwindef.cc:246
DWORD ConvertBigEndian(DWORD bigEndian)
Definition: genwindef.cc:270
#define MakePtr(cast, ptr, addValue)
Definition: genwindef.cc:105

References ConvertBigEndian(), FALSE, MEMORY_MAPPED_FILE::GetBase(), IsFiltedSymbol(), IsRegularLibSymbol(), MEMORY_MAPPED_FILE::IsValid(), m_strErrorMsg, MakePtr, and TRUE.

Referenced by DumpSymbols().

◆ DumpSymbols()

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

Definition at line 130 of file genwindef.cc.

131{
132 if(lpszLibPathName == NULL || pFile.bad() ) {
133 assert(lpszLibPathName != NULL);
134 assert(pFile.good());
135 m_strErrorMsg.assign("NULL <lpszLibPathName> or Invalid file handle.");
136 return FALSE;
137 }
138
139 if(!Dump(lpszLibPathName, pFile)) return FALSE;
140 return TRUE;
141}
BOOL Dump(LPTSTR lpszLibPathName, std::ostream &pFile)
Definition: genwindef.cc:154

References Dump(), FALSE, m_strErrorMsg, and TRUE.

Referenced by main().

◆ GetLastError()

string CLibSymbolInfo::GetLastError ( ) const

Definition at line 282 of file genwindef.cc.

283{
284 return m_strErrorMsg;
285}

References m_strErrorMsg.

◆ IsFiltedSymbol()

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

Definition at line 246 of file genwindef.cc.

247{
248 // Filter problematic symbols for Win64
249 if ( symbolName.substr(0,3) == "_CT" ) return FALSE;
250 if ( symbolName.substr(0,3) == "_TI" ) return FALSE;
251 // Filter other symbols
252 if ( symbolName.substr(0,2) == "__" )
253 return FALSE;
254 if ( symbolName.substr(0,3) == "??_" && symbolName[3] != '0') // Keep 'operator/=' [??_0]
255 return FALSE;
256 if( symbolName[0] == '_') {
257 symbolName.erase(0, 1); // C functions ...
258 }
259 // Filter the internal Boost symbols
260 if (symbolName.find ("detail@boost") != string::npos )
261 return FALSE;
262 if (symbolName.find ("details@boost") != string::npos )
263 return FALSE;
264 return TRUE;
265}

References FALSE, and TRUE.

Referenced by Dump().

◆ IsRegularLibSymbol()

BOOL CLibSymbolInfo::IsRegularLibSymbol ( PSTR  pszSymbolName)
protected

Definition at line 230 of file genwindef.cc.

231{
232 if ( 0 == strncmp( pszSymbolName, "__IMPORT_DESCRIPTOR_", 20 ) )
233 return FALSE;
234
235 if ( 0 == strncmp( pszSymbolName, "__NULL_IMPORT_DESCRIPTOR", 24 ) )
236 return FALSE;
237
238 if ( strstr( pszSymbolName, "_NULL_THUNK_DATA" ) )
239 return FALSE;
240
241 return TRUE;
242}

References FALSE, and TRUE.

Referenced by Dump().

Field Documentation

◆ m_strErrorMsg

std::string CLibSymbolInfo::m_strErrorMsg
protected

Definition at line 68 of file genwindef.cc.

Referenced by Dump(), DumpSymbols(), and GetLastError().

◆ m_strResultsString

std::string CLibSymbolInfo::m_strResultsString
protected

Definition at line 67 of file genwindef.cc.


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