16 #define MakePtr( cast, ptr, addValue ) ( cast )( ( DWORD )( ptr ) + ( DWORD )( addValue ) ) 39 if ( lpszLibPathName == NULL || pFile.
bad() ) {
40 assert( lpszLibPathName != NULL );
41 assert( pFile.
good() );
42 m_strErrorMsg.assign(
"NULL <lpszLibPathName> or Invalid file handle." );
46 if ( !Dump( lpszLibPathName, pFile ) )
return FALSE;
68 m_strErrorMsg =
"Unable to access file ";
69 m_strErrorMsg += lpszLibPathName;
75 PSTR pArchiveStartString = (PSTR)libFile.
GetBase();
77 if ( 0 !=
strncmp( pArchiveStartString, IMAGE_ARCHIVE_START, IMAGE_ARCHIVE_START_SIZE ) ) {
78 m_strErrorMsg.assign(
"Not a valid COFF LIB file." );
84 PIMAGE_ARCHIVE_MEMBER_HEADER pMbrHdr;
85 pMbrHdr =
MakePtr( PIMAGE_ARCHIVE_MEMBER_HEADER, pArchiveStartString, IMAGE_ARCHIVE_START_SIZE );
88 PDWORD pcbSymbols = ( PDWORD )( pMbrHdr + 1 );
92 DWORD cSymbols = ConvertBigEndian( *pcbSymbols );
96 PDWORD pMemberOffsets = pcbSymbols + 1;
100 PSTR pszSymbolName =
MakePtr( PSTR, pMemberOffsets, 4 * cSymbols );
105 for (
unsigned i = 0; i < cSymbols; i++ ) {
110 offset = ConvertBigEndian( *pMemberOffsets );
115 if ( IsRegularLibSymbol( pszSymbolName ) ) {
116 string symbol( pszSymbolName );
117 if ( IsFiltedSymbol( symbol ) ) {
118 pFile << symbol <<
endl;
125 pszSymbolName +=
strlen( pszSymbolName ) + 1;
136 if ( 0 ==
strncmp( pszSymbolName,
"__IMPORT_DESCRIPTOR_", 20 ) )
return FALSE;
138 if ( 0 ==
strncmp( pszSymbolName,
"__NULL_IMPORT_DESCRIPTOR", 24 ) )
return FALSE;
140 if (
strstr( pszSymbolName,
"_NULL_THUNK_DATA" ) )
return FALSE;
149 if ( symbolName.
compare( 0, 2,
"__" ) == 0 )
return FALSE;
150 if ( symbolName.
compare( 0, 3,
"??_" ) == 0 && symbolName[3] !=
'0' )
152 if ( symbolName[0] ==
'_' ) {
153 symbolName.
erase( 0, 1 );
156 if ( symbolName.
find(
"detail@boost" ) != string::npos )
return FALSE;
157 if ( symbolName.
find(
"details@boost" ) != string::npos )
return FALSE;
168 temp |= bigEndian >> 24;
169 temp |= ( ( bigEndian & 0x00FF0000 ) >> 8 );
170 temp |= ( ( bigEndian & 0x0000FF00 ) << 8 );
171 temp |= ( ( bigEndian & 0x000000FF ) << 24 );
185 m_hFile = INVALID_HANDLE_VALUE;
187 m_pMemoryMappedFileBase = 0;
192 CreateFile( pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)0 );
194 if ( m_hFile == INVALID_HANDLE_VALUE ) {
198 m_cbFile = ::GetFileSize( m_hFile, 0 );
200 m_hFileMapping = CreateFileMapping( m_hFile, NULL, PAGE_READONLY, 0, 0, NULL );
201 if ( m_hFileMapping == 0 ) {
203 CloseHandle( m_hFile );
204 m_hFile = INVALID_HANDLE_VALUE;
208 m_pMemoryMappedFileBase = (PCHAR)MapViewOfFile( m_hFileMapping, FILE_MAP_READ, 0, 0, 0 );
209 if ( m_pMemoryMappedFileBase == 0 ) {
211 CloseHandle( m_hFileMapping );
213 CloseHandle( m_hFile );
214 m_hFile = INVALID_HANDLE_VALUE;
224 if ( m_pMemoryMappedFileBase ) UnmapViewOfFile( m_pMemoryMappedFileBase );
226 if ( m_hFileMapping ) CloseHandle( m_hFileMapping );
228 if ( m_hFile != INVALID_HANDLE_VALUE ) CloseHandle( m_hFile );
std::string GetLastError() const
~MEMORY_MAPPED_FILE(void)
#define MakePtr(cast, ptr, addValue)
BOOL Dump(LPTSTR lpszLibPathName, std::ostream &pFile)
BOOL IsFiltedSymbol(std::string &pszSymbolName)
DWORD ConvertBigEndian(DWORD bigEndian)
MEMORY_MAPPED_FILE(PSTR pszFileName)
BOOL DumpSymbols(LPTSTR lpszLibPathName, std::ostream &pFile)
virtual ~CLibSymbolInfo()
BOOL IsRegularLibSymbol(PSTR pszSymbolName)