30 #pragma warning ( disable : 4273 ) 32 #define pclose _pclose 33 #define fileno _fileno 44 #if !defined(AFX_LIBSYMBOLINFO_H__1A7003B4_BA53_11D1_AE46_1CFB51000000__INCLUDED_) 45 #define AFX_LIBSYMBOLINFO_H__1A7003B4_BA53_11D1_AE46_1CFB51000000__INCLUDED_ 49 #endif // _MSC_VER >= 1000 70 BOOL Dump(LPTSTR lpszLibPathName, std::ostream& pFile);
85 PVOID
GetBase(
void ){
return m_pMemoryMappedFileBase; }
101 #endif // !defined(AFX_LIBSYMBOLINFO_H__1A7003B4_BA53_11D1_AE46_1CFB51000000__INCLUDED_) 105 #define MakePtr( cast, ptr, addValue ) (cast)( (DWORD_PTR)(ptr) + (DWORD_PTR)(addValue)) 132 if(lpszLibPathName == NULL || pFile.bad() ) {
133 assert(lpszLibPathName != NULL);
134 assert(pFile.good());
135 m_strErrorMsg.assign(
"NULL <lpszLibPathName> or Invalid file handle.");
139 if(!
Dump(lpszLibPathName, pFile))
return FALSE;
160 if( FALSE == libFile.
IsValid() ) {
168 PSTR pArchiveStartString = (PSTR)libFile.
GetBase();
170 if ( 0 != strncmp( pArchiveStartString, IMAGE_ARCHIVE_START,
171 IMAGE_ARCHIVE_START_SIZE ) ) {
178 PIMAGE_ARCHIVE_MEMBER_HEADER pMbrHdr;
179 pMbrHdr =
MakePtr( PIMAGE_ARCHIVE_MEMBER_HEADER, pArchiveStartString,
180 IMAGE_ARCHIVE_START_SIZE );
183 PDWORD pcbSymbols = (PDWORD)(pMbrHdr + 1);
191 PDWORD pMemberOffsets = pcbSymbols + 1;
195 PSTR pszSymbolName =
MakePtr( PSTR, pMemberOffsets, 4 * cSymbols );
200 for (
unsigned i = 0; i < cSymbols; i++ )
212 string symbol(pszSymbolName);
214 pFile << symbol << endl;
221 pszSymbolName += strlen(pszSymbolName) + 1;
232 if ( 0 == strncmp( pszSymbolName,
"__IMPORT_DESCRIPTOR_", 20 ) )
235 if ( 0 == strncmp( pszSymbolName,
"__NULL_IMPORT_DESCRIPTOR", 24 ) )
238 if ( strstr( pszSymbolName,
"_NULL_THUNK_DATA" ) )
249 if ( symbolName.substr(0,3) ==
"_CT" )
return FALSE;
250 if ( symbolName.substr(0,3) ==
"_TI" )
return FALSE;
252 if ( symbolName.substr(0,2) ==
"__" )
254 if ( symbolName.substr(0,3) ==
"??_" && symbolName[3] !=
'0')
256 if( symbolName[0] ==
'_') {
257 symbolName.erase(0, 1);
260 if (symbolName.find (
"detail@boost") != string::npos )
262 if (symbolName.find (
"details@boost") != string::npos )
274 temp |= bigEndian >> 24;
275 temp |= ((bigEndian & 0x00FF0000) >> 8);
276 temp |= ((bigEndian & 0x0000FF00) << 8);
277 temp |= ((bigEndian & 0x000000FF) << 24);
294 m_hFile = INVALID_HANDLE_VALUE;
296 m_pMemoryMappedFileBase = 0;
300 m_hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
301 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)0);
303 if ( m_hFile == INVALID_HANDLE_VALUE )
308 m_cbFile = ::GetFileSize( m_hFile, 0 );
310 m_hFileMapping = CreateFileMapping(m_hFile,NULL, PAGE_READONLY, 0, 0,NULL);
311 if ( m_hFileMapping == 0 )
314 CloseHandle(m_hFile);
315 m_hFile = INVALID_HANDLE_VALUE;
319 m_pMemoryMappedFileBase = (PCHAR)MapViewOfFile( m_hFileMapping,
320 FILE_MAP_READ, 0, 0, 0);
321 if ( m_pMemoryMappedFileBase == 0 )
324 CloseHandle(m_hFileMapping);
326 CloseHandle(m_hFile);
327 m_hFile = INVALID_HANDLE_VALUE;
337 if ( m_pMemoryMappedFileBase )
338 UnmapViewOfFile( m_pMemoryMappedFileBase );
340 if ( m_hFileMapping )
341 CloseHandle( m_hFileMapping );
343 if ( m_hFile != INVALID_HANDLE_VALUE )
344 CloseHandle( m_hFile );
351 cerr <<
"Usage: genwindef [-l <dllname>] [-o <output-file> | exports.def] <obj or lib filenames>" << endl;
358 int main (
int argc,
char** argv )
361 string outfile(
"exports.def");
362 string library(
"UnknownLib");
369 while (argv[arg][0] ==
'-') {
370 if (strcmp(argv[arg],
"--") == 0) {
373 else if (strcmp(argv[arg],
"-l") == 0) {
378 else if (strcmp(argv[arg],
"-o") == 0) {
386 for (arg; arg < argc; arg++) {
387 objfiles += argv[arg];
388 if( arg+1 < argc) objfiles +=
" ";
392 ofstream out(outfile.c_str());
394 cerr <<
"windef: Error opening file " << outfile << endl;
397 out <<
"LIBRARY " << library << endl;
398 out <<
"EXPORTS" << endl;
400 libsymbols.
DumpSymbols(const_cast<char*>(objfiles.c_str()), out);
std::string GetLastError() const
BOOL IsFiltedSymbol(std::string &pszSymbolName)
std::string m_strResultsString
BOOL DumpSymbols(LPTSTR lpszLibPathName, std::ostream &pFile)
DWORD ConvertBigEndian(DWORD bigEndian)
#define MakePtr(cast, ptr, addValue)
PVOID m_pMemoryMappedFileBase
int main(int argc, char **argv)
BOOL IsRegularLibSymbol(PSTR pszSymbolName)
MEMORY_MAPPED_FILE * PMEMORY_MAPPED_FILE
MEMORY_MAPPED_FILE(PSTR pszFileName)
~MEMORY_MAPPED_FILE(void)
BOOL Dump(LPTSTR lpszLibPathName, std::ostream &pFile)
std::string m_strErrorMsg
virtual ~CLibSymbolInfo()