6   #pragma warning ( disable : 4273 ) 
   20 #if !defined(AFX_LIBSYMBOLINFO_H__1A7003B4_BA53_11D1_AE46_1CFB51000000__INCLUDED_) 
   21 #define AFX_LIBSYMBOLINFO_H__1A7003B4_BA53_11D1_AE46_1CFB51000000__INCLUDED_ 
   25 #endif // _MSC_VER >= 1000 
   39   BOOL 
DumpSymbols(LPTSTR lpszLibPathName, std::ostream& pFile);
 
   46   BOOL 
Dump(LPTSTR lpszLibPathName, std::ostream& pFile); 
 
   77 #endif // !defined(AFX_LIBSYMBOLINFO_H__1A7003B4_BA53_11D1_AE46_1CFB51000000__INCLUDED_) 
   81 #define MakePtr( cast, ptr, addValue ) (cast)( (DWORD)(ptr) + (DWORD)(addValue)) 
  108   if(lpszLibPathName == NULL || pFile.bad() ) {
 
  109     assert(lpszLibPathName != NULL);
 
  111     m_strErrorMsg.assign(
"NULL <lpszLibPathName> or Invalid file handle.");
 
  115   if(!Dump(lpszLibPathName, pFile))  
return FALSE;
 
  137         m_strErrorMsg = 
"Unable to access file ";
 
  138     m_strErrorMsg+= lpszLibPathName;
 
  144   PSTR pArchiveStartString = (PSTR)libFile.
GetBase();
 
  146   if ( 0 != strncmp( pArchiveStartString, IMAGE_ARCHIVE_START,
 
  147                        IMAGE_ARCHIVE_START_SIZE )  )  {
 
  148       m_strErrorMsg.assign(
"Not a valid COFF LIB file.");
 
  154   PIMAGE_ARCHIVE_MEMBER_HEADER pMbrHdr;
 
  155   pMbrHdr = 
MakePtr( PIMAGE_ARCHIVE_MEMBER_HEADER, pArchiveStartString,
 
  156                      IMAGE_ARCHIVE_START_SIZE );
 
  159   PDWORD pcbSymbols = (PDWORD)(pMbrHdr + 1);  
 
  163   DWORD cSymbols = ConvertBigEndian( *pcbSymbols );
 
  167   PDWORD pMemberOffsets = pcbSymbols + 1;     
 
  171   PSTR pszSymbolName = 
MakePtr( PSTR, pMemberOffsets, 4 * cSymbols );
 
  176   for ( 
unsigned i = 0; i < cSymbols; i++ )
 
  182     offset = ConvertBigEndian( *pMemberOffsets );
 
  187     if ( IsRegularLibSymbol( pszSymbolName ) ) {
 
  188       string symbol(pszSymbolName);
 
  189       if (IsFiltedSymbol(symbol) ) {
 
  190         pFile << symbol << endl;
 
  197     pszSymbolName += strlen(pszSymbolName) + 1;
 
  208   if ( 0 == strncmp( pszSymbolName, 
"__IMPORT_DESCRIPTOR_", 20 ) )
 
  211   if ( 0 == strncmp( pszSymbolName, 
"__NULL_IMPORT_DESCRIPTOR", 24 ) )
 
  214   if ( strstr( pszSymbolName, 
"_NULL_THUNK_DATA" ) )
 
  225   if ( symbolName.substr(0,3) == 
"_CT" ) 
return FALSE;
 
  226   if ( symbolName.substr(0,3) == 
"_TI" ) 
return FALSE;
 
  228   if ( symbolName.substr(0,2) == 
"__" ) 
 
  230   if ( symbolName.substr(0,3) == 
"??_" && symbolName[3] != 
'0') 
 
  232   if( symbolName[0] == 
'_') {
 
  233     symbolName.erase(0, 1);  
 
  236   if (symbolName.find (
"detail@boost") != string::npos )
 
  238   if (symbolName.find (
"details@boost") != string::npos ) 
 
  250   temp |= bigEndian >> 24;
 
  251   temp |= ((bigEndian & 0x00FF0000) >> 8);
 
  252   temp |= ((bigEndian & 0x0000FF00) << 8);
 
  253   temp |= ((bigEndian & 0x000000FF) << 24);
 
  260   return m_strErrorMsg;
 
  270    m_hFile = INVALID_HANDLE_VALUE;
 
  272    m_pMemoryMappedFileBase = 0;
 
  276    m_hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
 
  277                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)0);
 
  279    if ( m_hFile == INVALID_HANDLE_VALUE )
 
  284     m_cbFile = ::GetFileSize( m_hFile, 0 );
 
  286    m_hFileMapping = CreateFileMapping(m_hFile,NULL, PAGE_READONLY, 0, 0,NULL);
 
  287    if ( m_hFileMapping == 0 )
 
  290        CloseHandle(m_hFile);
 
  291        m_hFile = INVALID_HANDLE_VALUE;
 
  295     m_pMemoryMappedFileBase = (PCHAR)MapViewOfFile( m_hFileMapping,
 
  296                                                    FILE_MAP_READ, 0, 0, 0);
 
  297     if ( m_pMemoryMappedFileBase == 0 )
 
  300        CloseHandle(m_hFileMapping);
 
  302        CloseHandle(m_hFile);
 
  303        m_hFile = INVALID_HANDLE_VALUE;
 
  313     if ( m_pMemoryMappedFileBase )
 
  314         UnmapViewOfFile( m_pMemoryMappedFileBase );
 
  316     if ( m_hFileMapping )
 
  317         CloseHandle( m_hFileMapping );
 
  319     if ( m_hFile != INVALID_HANDLE_VALUE )
 
  320         CloseHandle( m_hFile ); 
 
  327     cerr << 
"Usage: genwindef [-l <dllname>] [-o <output-file> | exports.def]  <obj or lib filenames>" << endl;
 
  334 int main ( 
int argc, 
char** argv )
 
  337   string outfile(
"exports.def");
 
  338   string library(
"UnknownLib");
 
  345   while (argv[arg][0] == 
'-') {
 
  346     if (strcmp(argv[arg], 
"--") == 0) {
 
  349     else if (strcmp(argv[arg], 
"-l") == 0) {
 
  354     else if (strcmp(argv[arg], 
"-o") == 0) {
 
  362   for (arg; arg < argc; arg++) {
 
  363      objfiles += argv[arg];
 
  364      if( arg+1 < argc) objfiles += 
" ";
 
  368   ofstream out(outfile.c_str());
 
  370     cerr << 
"windef: Error opening file " << outfile << endl;
 
  373   out << 
"LIBRARY " << library << endl;
 
  374   out << 
"EXPORTS" << endl;
 
  376   libsymbols.
DumpSymbols(const_cast<char*>(objfiles.c_str()), out);
 
std::string GetLastError() const 
 
std::string m_strResultsString
 
~MEMORY_MAPPED_FILE(void)
 
#define MakePtr(cast, ptr, addValue)
 
BOOL Dump(LPTSTR lpszLibPathName, std::ostream &pFile)
 
int main(int argc, char **argv)
 
std::string m_strErrorMsg
 
BOOL IsFiltedSymbol(std::string &pszSymbolName)
 
PVOID m_pMemoryMappedFileBase
 
MEMORY_MAPPED_FILE * PMEMORY_MAPPED_FILE
 
DWORD ConvertBigEndian(DWORD bigEndian)
 
MEMORY_MAPPED_FILE(PSTR pszFileName)
 
BOOL DumpSymbols(LPTSTR lpszLibPathName, std::ostream &pFile)
 
virtual ~CLibSymbolInfo()
 
BOOL IsRegularLibSymbol(PSTR pszSymbolName)