18 #define MakePtr( cast, ptr, addValue ) (cast)( (DWORD_PTR)(ptr) + (DWORD_PTR)(addValue)) 45 if(lpszLibPathName == NULL || pFile.bad() ) {
46 assert(lpszLibPathName != NULL);
48 m_strErrorMsg.assign(
"NULL <lpszLibPathName> or Invalid file handle.");
52 if(!Dump(lpszLibPathName, pFile))
return FALSE;
73 if( FALSE == libFile.
IsValid() ) {
74 m_strErrorMsg =
"Unable to access file ";
75 m_strErrorMsg+= lpszLibPathName;
81 PSTR pArchiveStartString = (PSTR)libFile.
GetBase();
83 if ( 0 != strncmp( pArchiveStartString, IMAGE_ARCHIVE_START,
84 IMAGE_ARCHIVE_START_SIZE ) ) {
85 m_strErrorMsg.assign(
"Not a valid COFF LIB file.");
91 PIMAGE_ARCHIVE_MEMBER_HEADER pMbrHdr;
92 pMbrHdr =
MakePtr( PIMAGE_ARCHIVE_MEMBER_HEADER, pArchiveStartString,
93 IMAGE_ARCHIVE_START_SIZE );
96 PDWORD pcbSymbols = (PDWORD)(pMbrHdr + 1);
100 DWORD cSymbols = ConvertBigEndian( *pcbSymbols );
104 PDWORD pMemberOffsets = pcbSymbols + 1;
108 PSTR pszSymbolName =
MakePtr( PSTR, pMemberOffsets, 4 * cSymbols );
113 for (
unsigned i = 0; i < cSymbols; i++ )
119 offset = ConvertBigEndian( *pMemberOffsets );
124 if ( IsRegularLibSymbol( pszSymbolName ) ) {
125 string symbol(pszSymbolName);
126 if (IsFiltedSymbol(symbol) ) {
127 pFile << symbol << endl;
134 pszSymbolName += strlen(pszSymbolName) + 1;
145 if ( 0 == strncmp( pszSymbolName,
"__IMPORT_DESCRIPTOR_", 20 ) )
148 if ( 0 == strncmp( pszSymbolName,
"__NULL_IMPORT_DESCRIPTOR", 24 ) )
151 if ( strstr( pszSymbolName,
"_NULL_THUNK_DATA" ) )
162 if ( symbolName.substr(0,3) ==
"_CT" )
return FALSE;
163 if ( symbolName.substr(0,3) ==
"_TI" )
return FALSE;
165 if ( symbolName.substr(0,2) ==
"__" )
167 if ( symbolName.substr(0,3) ==
"??_" && symbolName[3] !=
'0')
169 if( symbolName[0] ==
'_') {
170 symbolName.erase(0, 1);
173 if (symbolName.find (
"detail@boost") != string::npos )
175 if (symbolName.find (
"details@boost") != string::npos )
187 temp |= bigEndian >> 24;
188 temp |= ((bigEndian & 0x00FF0000) >> 8);
189 temp |= ((bigEndian & 0x0000FF00) << 8);
190 temp |= ((bigEndian & 0x000000FF) << 24);
197 return m_strErrorMsg;
207 m_hFile = INVALID_HANDLE_VALUE;
209 m_pMemoryMappedFileBase = 0;
213 m_hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
214 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)0);
216 if ( m_hFile == INVALID_HANDLE_VALUE )
221 m_cbFile = ::GetFileSize( m_hFile, 0 );
223 m_hFileMapping = CreateFileMapping(m_hFile,NULL, PAGE_READONLY, 0, 0,NULL);
224 if ( m_hFileMapping == 0 )
227 CloseHandle(m_hFile);
228 m_hFile = INVALID_HANDLE_VALUE;
232 m_pMemoryMappedFileBase = (PCHAR)MapViewOfFile( m_hFileMapping,
233 FILE_MAP_READ, 0, 0, 0);
234 if ( m_pMemoryMappedFileBase == 0 )
237 CloseHandle(m_hFileMapping);
239 CloseHandle(m_hFile);
240 m_hFile = INVALID_HANDLE_VALUE;
250 if ( m_pMemoryMappedFileBase )
251 UnmapViewOfFile( m_pMemoryMappedFileBase );
253 if ( m_hFileMapping )
254 CloseHandle( m_hFileMapping );
256 if ( m_hFile != INVALID_HANDLE_VALUE )
257 CloseHandle( m_hFile );
std::string GetLastError() const
BOOL IsFiltedSymbol(std::string &pszSymbolName)
BOOL DumpSymbols(LPTSTR lpszLibPathName, std::ostream &pFile)
DWORD ConvertBigEndian(DWORD bigEndian)
#define MakePtr(cast, ptr, addValue)
BOOL IsRegularLibSymbol(PSTR pszSymbolName)
MEMORY_MAPPED_FILE(PSTR pszFileName)
~MEMORY_MAPPED_FILE(void)
BOOL Dump(LPTSTR lpszLibPathName, std::ostream &pFile)
virtual ~CLibSymbolInfo()