Example #1
0
/*
 *  Dump an object file--either a full listing or just the exported symbols.
 */
void DumpObjFile(PIMAGE_FILE_HEADER pImageFileHeader, FILE *fout, int full)
{
    PIMAGE_SYMBOL PCOFFSymbolTable;
    DWORD COFFSymbolCount;

    PCOFFSymbolTable = (PIMAGE_SYMBOL)
        ((DWORD)pImageFileHeader + pImageFileHeader->PointerToSymbolTable);
    COFFSymbolCount = pImageFileHeader->NumberOfSymbols;

    if (full) {
        DumpSymbolTable(PCOFFSymbolTable, fout, COFFSymbolCount);
    } else {
        DumpExternals(PCOFFSymbolTable, fout, COFFSymbolCount);
    }
}
Example #2
0
/*----------------------------------------------------------------------
* DumpObjFile --
*
*	Dump an object file--either a full listing or just the exported
*	symbols.
*----------------------------------------------------------------------
*/
void DumpObjFile(PIMAGE_FILE_HEADER pImageFileHeader, FILE *fout, int full)
{
    PIMAGE_SYMBOL PCOFFSymbolTable;
    DWORD COFFSymbolCount;

    //PCOFFSymbolTable = (PIMAGE_SYMBOL)LongToPtr(
    //((DWORD)PtrToLong( pImageFileHeader ) + pImageFileHeader->PointerToSymbolTable) );
    PCOFFSymbolTable = MakePtr(PIMAGE_SYMBOL, pImageFileHeader,	pImageFileHeader->PointerToSymbolTable);
    COFFSymbolCount = pImageFileHeader->NumberOfSymbols;

    if (full)
    {
        DumpSymbolTable(PCOFFSymbolTable, fout, COFFSymbolCount);
    }
    else
    {
        DumpExternals(PCOFFSymbolTable, fout, COFFSymbolCount);
    }
}
Example #3
0
/*
 *----------------------------------------------------------------------
 * DumpExternals --
 *
 *	Dumps a COFF symbol table from an EXE or OBJ.  We only use
 *	it to dump tables from OBJs.
 *----------------------------------------------------------------------
 */
void
DumpExternals(PIMAGE_SYMBOL pSymbolTable, FILE *fout, unsigned cSymbols)
{
	unsigned i;
	PSTR stringTable;
	char *s;
#if MOB
	char *f;
#endif
	char symbol[1024];
	int	len;

	/*
	 * The string table apparently starts right after the symbol table
	 */
	stringTable = (PSTR)&pSymbolTable[cSymbols]; 

	for ( i=0; i < cSymbols; i++ ) {
		// fprintf(fout, "%04X ", i);
/*
 *	Require pSymbolTable->Type == 0x20 	for only functions
 */
#if MOB
		if ((pSymbolTable->SectionNumber > 0 && (
					pSymbolTable->Type == 0x0 || pSymbolTable->Type == 0x20) &&
				pSymbolTable->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) ||
				(pSymbolTable->SectionNumber == IMAGE_SYM_UNDEFINED &&
				pSymbolTable->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)) {
#else
		if ((pSymbolTable->SectionNumber > 0 && pSymbolTable->Type == 0x20) &&
				pSymbolTable->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) {
#endif

#if MOB || 1
			if ( pSymbolTable->N.Name.Short != 0 ) {
				strncpy(symbol, (char*) pSymbolTable->N.ShortName, 8);
				symbol[8] = 0;
			} else {
				strcpy(symbol, stringTable + pSymbolTable->N.Name.Long);
			}
			s = symbol;
			if (*s == '_') {
				s++;
			}
#if MOB || 1
			if (strncmp(s, "??_G", 4) == 0) {
				goto next;
			}
			if (strncmp(s, "??_E", 4) == 0) {
				goto next;
			}
#endif
			len = strlen(s);
			if (s[len - 1] == '2' && s[len - 2] == '1' && s[len - 3] == '@') {
				s[len - 3] = '\0';
			}
			fprintf(fout, "\t%s\n", s);
#else
			if (pSymbolTable->N.Name.Short != 0) {
				strncpy(symbol, (char*) pSymbolTable->N.ShortName, 8);
				symbol[8] = 0;
			} else {
				s = stringTable + pSymbolTable->N.Name.Long;
				strcpy(symbol, s);
			}
			s = symbol;
#if 0
			f = strchr(s, '@');
			if (f) {
				*f = 0;
			}
#endif

#if defined(_MSC_VER) && defined(_X86_)
			if (strncmp(&symbol[1], "_imp_", 5) != 0)
				fprintf(fout, "\t%s\n", &symbol[1]);
#else
			fprintf(fout, "\t%s\n", symbol);
#endif
#endif
#if OLD
		} else {
			char sectionName[10];
			if ( pSymbolTable->N.Name.Short != 0 ) {
				strncpy(symbol, (char*) pSymbolTable->N.ShortName, 8);
				symbol[8] = 0;
			} else {
				strcpy(symbol, stringTable + pSymbolTable->N.Name.Long);
			}
			s = symbol;
			GetSectionName(pSymbolTable->SectionNumber, sectionName,
						   sizeof(sectionName));
			fprintf(fout, "SKIP %s, sect %d:%s type 0x%x, sc %d:%s\n", s,
				pSymbolTable->SectionNumber, sectionName, pSymbolTable->Type,
				pSymbolTable->StorageClass,
			    GetSZStorageClass(pSymbolTable->StorageClass));
#endif
		}
next:

		/*
		 * Take into account any aux symbols
		 */
		i += pSymbolTable->NumberOfAuxSymbols;
		pSymbolTable += pSymbolTable->NumberOfAuxSymbols;
		pSymbolTable++;
	}
}

/*
 *----------------------------------------------------------------------
 * DumpObjFile --
 *
 *	Dump an object file--either a full listing or just the exported
 *	symbols.
 *----------------------------------------------------------------------
 */
void
DumpObjFile(PIMAGE_FILE_HEADER pImageFileHeader, FILE *fout, int full)
{
	PIMAGE_SYMBOL PCOFFSymbolTable;
	DWORD COFFSymbolCount;

	PCOFFSymbolTable = (PIMAGE_SYMBOL)
		((DWORD)pImageFileHeader + pImageFileHeader->PointerToSymbolTable);
	COFFSymbolCount = pImageFileHeader->NumberOfSymbols;

	if (full) {
		DumpSymbolTable(PCOFFSymbolTable, fout, COFFSymbolCount);
	} else {
		DumpExternals(PCOFFSymbolTable, fout, COFFSymbolCount);
	}
}