16 #define MakePtr( cast, ptr, addValue ) ( cast )( ( DWORD )( ptr ) + ( DWORD )( addValue ) ) 38 if ( lpszLibPathName == NULL || pFile.
bad() ) {
39 assert( lpszLibPathName != NULL );
40 assert( pFile.
good() );
41 m_strErrorMsg.assign(
"NULL <lpszLibPathName> or Invalid file handle." );
45 if ( !Dump( lpszLibPathName, pFile ) )
return FALSE;
66 m_strErrorMsg =
"Unable to access file ";
67 m_strErrorMsg += lpszLibPathName;
73 PSTR pArchiveStartString = (PSTR)libFile.
GetBase();
75 if ( 0 !=
strncmp( pArchiveStartString, IMAGE_ARCHIVE_START, IMAGE_ARCHIVE_START_SIZE ) ) {
76 m_strErrorMsg.assign(
"Not a valid COFF LIB file." );
82 PIMAGE_ARCHIVE_MEMBER_HEADER pMbrHdr;
83 pMbrHdr =
MakePtr( PIMAGE_ARCHIVE_MEMBER_HEADER, pArchiveStartString, IMAGE_ARCHIVE_START_SIZE );
86 PDWORD pcbSymbols = ( PDWORD )( pMbrHdr + 1 );
90 DWORD cSymbols = ConvertBigEndian( *pcbSymbols );
94 PDWORD pMemberOffsets = pcbSymbols + 1;
98 PSTR pszSymbolName =
MakePtr( PSTR, pMemberOffsets, 4 * cSymbols );
103 for (
unsigned i = 0; i < cSymbols; i++ ) {
108 offset = ConvertBigEndian( *pMemberOffsets );
113 if ( IsRegularLibSymbol( pszSymbolName ) ) {
114 string symbol( pszSymbolName );
115 if ( IsFiltedSymbol( symbol ) ) { pFile << symbol <<
endl; }
121 pszSymbolName +=
strlen( pszSymbolName ) + 1;
131 if ( 0 ==
strncmp( pszSymbolName,
"__IMPORT_DESCRIPTOR_", 20 ) )
return FALSE;
133 if ( 0 ==
strncmp( pszSymbolName,
"__NULL_IMPORT_DESCRIPTOR", 24 ) )
return FALSE;
135 if (
strstr( pszSymbolName,
"_NULL_THUNK_DATA" ) )
return FALSE;
143 if ( symbolName.
compare( 0, 2,
"__" ) == 0 )
return FALSE;
144 if ( symbolName.
compare( 0, 3,
"??_" ) == 0 && symbolName[3] !=
'0' )
146 if ( symbolName[0] ==
'_' ) {
147 symbolName.
erase( 0, 1 );
150 if ( symbolName.
find(
"detail@boost" ) != string::npos )
return FALSE;
151 if ( symbolName.
find(
"details@boost" ) != string::npos )
return FALSE;
161 temp |= bigEndian >> 24;
162 temp |= ( ( bigEndian & 0x00FF0000 ) >> 8 );
163 temp |= ( ( bigEndian & 0x0000FF00 ) << 8 );
164 temp |= ( ( bigEndian & 0x000000FF ) << 24 );
177 m_hFile = INVALID_HANDLE_VALUE;
179 m_pMemoryMappedFileBase = 0;
184 CreateFile( pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)0 );
186 if ( m_hFile == INVALID_HANDLE_VALUE ) {
190 m_cbFile = ::GetFileSize( m_hFile, 0 );
192 m_hFileMapping = CreateFileMapping( m_hFile, NULL, PAGE_READONLY, 0, 0, NULL );
193 if ( m_hFileMapping == 0 ) {
195 CloseHandle( m_hFile );
196 m_hFile = INVALID_HANDLE_VALUE;
200 m_pMemoryMappedFileBase = (PCHAR)MapViewOfFile( m_hFileMapping, FILE_MAP_READ, 0, 0, 0 );
201 if ( m_pMemoryMappedFileBase == 0 ) {
203 CloseHandle( m_hFileMapping );
205 CloseHandle( m_hFile );
206 m_hFile = INVALID_HANDLE_VALUE;
215 if ( m_pMemoryMappedFileBase ) UnmapViewOfFile( m_pMemoryMappedFileBase );
217 if ( m_hFileMapping ) CloseHandle( m_hFileMapping );
219 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)