31 #pragma warning ( disable : 4273 )
33 #define pclose _pclose
34 #define fileno _fileno
45 #if !defined(AFX_LIBSYMBOLINFO_H__1A7003B4_BA53_11D1_AE46_1CFB51000000__INCLUDED_)
46 #define AFX_LIBSYMBOLINFO_H__1A7003B4_BA53_11D1_AE46_1CFB51000000__INCLUDED_
50 #endif // _MSC_VER >= 1000
64 BOOL
DumpSymbols(LPTSTR lpszLibPathName, std::ostream& pFile);
71 BOOL
Dump(LPTSTR lpszLibPathName, std::ostream& pFile);
86 PVOID
GetBase(
void ){
return m_pMemoryMappedFileBase; }
94 HANDLE m_hFileMapping;
95 PVOID m_pMemoryMappedFileBase;
102 #endif // !defined(AFX_LIBSYMBOLINFO_H__1A7003B4_BA53_11D1_AE46_1CFB51000000__INCLUDED_)
106 #define MakePtr( cast, ptr, addValue ) (cast)( (DWORD)(ptr) + (DWORD)(addValue))
133 if(lpszLibPathName == NULL || pFile.bad() ) {
134 assert(lpszLibPathName != NULL);
135 assert(pFile.good());
136 m_strErrorMsg.assign(
"NULL <lpszLibPathName> or Invalid file handle.");
140 if(!Dump(lpszLibPathName, pFile))
return FALSE;
161 if(
FALSE == libFile.IsValid() ) {
162 m_strErrorMsg =
"Unable to access file ";
163 m_strErrorMsg+= lpszLibPathName;
169 PSTR pArchiveStartString = (PSTR)libFile.GetBase();
171 if ( 0 != strncmp( pArchiveStartString, IMAGE_ARCHIVE_START,
172 IMAGE_ARCHIVE_START_SIZE ) ) {
173 m_strErrorMsg.assign(
"Not a valid COFF LIB file.");
179 PIMAGE_ARCHIVE_MEMBER_HEADER pMbrHdr;
180 pMbrHdr =
MakePtr( PIMAGE_ARCHIVE_MEMBER_HEADER, pArchiveStartString,
181 IMAGE_ARCHIVE_START_SIZE );
184 PDWORD pcbSymbols = (PDWORD)(pMbrHdr + 1);
188 DWORD cSymbols = ConvertBigEndian( *pcbSymbols );
192 PDWORD pMemberOffsets = pcbSymbols + 1;
196 PSTR pszSymbolName =
MakePtr( PSTR, pMemberOffsets, 4 * cSymbols );
201 for (
unsigned i = 0; i < cSymbols; i++ )
207 offset = ConvertBigEndian( *pMemberOffsets );
212 if ( IsRegularLibSymbol( pszSymbolName ) ) {
213 string symbol(pszSymbolName);
214 if (IsFiltedSymbol(symbol) ) {
215 pFile << symbol << endl;
222 pszSymbolName += strlen(pszSymbolName) + 1;
233 if ( 0 == strncmp( pszSymbolName,
"__IMPORT_DESCRIPTOR_", 20 ) )
236 if ( 0 == strncmp( pszSymbolName,
"__NULL_IMPORT_DESCRIPTOR", 24 ) )
239 if ( strstr( pszSymbolName,
"_NULL_THUNK_DATA" ) )
250 if ( symbolName.substr(0,3) ==
"_CT" )
return FALSE;
251 if ( symbolName.substr(0,3) ==
"_TI" )
return FALSE;
253 if ( symbolName.substr(0,2) ==
"__" )
255 if ( symbolName.substr(0,3) ==
"??_" && symbolName[3] !=
'0')
257 if( symbolName[0] ==
'_') {
258 symbolName.erase(0, 1);
261 if (symbolName.find (
"detail@boost") != string::npos )
263 if (symbolName.find (
"details@boost") != string::npos )
275 temp |= bigEndian >> 24;
276 temp |= ((bigEndian & 0x00FF0000) >> 8);
277 temp |= ((bigEndian & 0x0000FF00) << 8);
278 temp |= ((bigEndian & 0x000000FF) << 24);
285 return m_strErrorMsg;
295 m_hFile = INVALID_HANDLE_VALUE;
297 m_pMemoryMappedFileBase = 0;
301 m_hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
302 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE)0);
304 if ( m_hFile == INVALID_HANDLE_VALUE )
309 m_cbFile = ::GetFileSize( m_hFile, 0 );
311 m_hFileMapping = CreateFileMapping(m_hFile,NULL, PAGE_READONLY, 0, 0,NULL);
312 if ( m_hFileMapping == 0 )
315 CloseHandle(m_hFile);
316 m_hFile = INVALID_HANDLE_VALUE;
320 m_pMemoryMappedFileBase = (PCHAR)MapViewOfFile( m_hFileMapping,
321 FILE_MAP_READ, 0, 0, 0);
322 if ( m_pMemoryMappedFileBase == 0 )
325 CloseHandle(m_hFileMapping);
327 CloseHandle(m_hFile);
328 m_hFile = INVALID_HANDLE_VALUE;
338 if ( m_pMemoryMappedFileBase )
339 UnmapViewOfFile( m_pMemoryMappedFileBase );
341 if ( m_hFileMapping )
342 CloseHandle( m_hFileMapping );
344 if ( m_hFile != INVALID_HANDLE_VALUE )
345 CloseHandle( m_hFile );
352 cerr <<
"Usage: genwindef [-l <dllname>] [-o <output-file> | exports.def] <obj or lib filenames>" << endl;
359 int main (
int argc,
char** argv )
362 string outfile(
"exports.def");
363 string library(
"UnknownLib");
370 while (argv[arg][0] ==
'-') {
371 if (strcmp(argv[arg],
"--") == 0) {
374 else if (strcmp(argv[arg],
"-l") == 0) {
379 else if (strcmp(argv[arg],
"-o") == 0) {
387 for (arg; arg < argc; arg++) {
388 objfiles += argv[arg];
389 if( arg+1 < argc) objfiles +=
" ";
393 ofstream out(outfile.c_str());
395 cerr <<
"windef: Error opening file " << outfile << endl;
398 out <<
"LIBRARY " << library << endl;
399 out <<
"EXPORTS" << endl;
401 libsymbols.
DumpSymbols(const_cast<char*>(objfiles.c_str()), out);
std::string GetLastError() const
std::string m_strResultsString
int main(int argc, char **argv)
MEMORY_MAPPED_FILE * PMEMORY_MAPPED_FILE
~MEMORY_MAPPED_FILE(void)
#define MakePtr(cast, ptr, addValue)
BOOL Dump(LPTSTR lpszLibPathName, std::ostream &pFile)
std::string m_strErrorMsg
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)