|
|
| static int ConvertCoffs |
( |
ULONG * |
SymbolsCount, |
|
|
PROSSYM_ENTRY * |
SymbolsBase, |
|
|
ULONG * |
StringsLength, |
|
|
void * |
StringsBase, |
|
|
ULONG |
CoffSymbolsLength, |
|
|
void * |
CoffSymbolsBase, |
|
|
ULONG |
CoffStringsLength, |
|
|
void * |
CoffStringsBase, |
|
|
ULONG_PTR |
ImageBase, |
|
|
PIMAGE_FILE_HEADER |
PEFileHeader, |
|
|
PIMAGE_SECTION_HEADER |
PESectionHeaders |
|
) |
| [static] |
Definition at line 267 of file rsym.c.
Referenced by main().
{
ULONG Count, i;
PCOFF_SYMENT CoffEntry;
char FuncName[256];
char *p;
PROSSYM_ENTRY Current;
CoffEntry = (PCOFF_SYMENT) CoffSymbolsBase;
Count = CoffSymbolsLength / sizeof(COFF_SYMENT);
*SymbolsBase = malloc(Count * sizeof(ROSSYM_ENTRY));
if (NULL == *SymbolsBase)
{
fprintf(stderr, "Unable to allocate memory for converted COFF symbols\n");
return 1;
}
*SymbolsCount = 0;
Current = *SymbolsBase;
for (i = 0; i < Count; i++)
{
if (ISFCN(CoffEntry[i].e_type) || C_EXT == CoffEntry[i].e_sclass)
{
Current->Address = CoffEntry[i].e_value;
if (0 < CoffEntry[i].e_scnum)
{
if (PEFileHeader->NumberOfSections < CoffEntry[i].e_scnum)
{
free(*SymbolsBase);
fprintf(stderr, "Invalid section number %d in COFF symbols (only %d sections present)\n",
CoffEntry[i].e_scnum, PEFileHeader->NumberOfSections);
return 1;
}
Current->Address += PESectionHeaders[CoffEntry[i].e_scnum - 1].VirtualAddress;
}
Current->FileOffset = 0;
if (0 == CoffEntry[i].e.e.e_zeroes)
{
if (sizeof(FuncName) <= strlen((char *) CoffStringsBase + CoffEntry[i].e.e.e_offset))
{
free(*SymbolsBase);
fprintf(stderr, "Function name too long\n");
return 1;
}
strcpy(FuncName, (char *) CoffStringsBase + CoffEntry[i].e.e.e_offset);
}
else
{
memcpy(FuncName, CoffEntry[i].e.e_name, E_SYMNMLEN);
FuncName[E_SYMNMLEN] = '\0';
}
p = strrchr(FuncName, '@');
if (NULL != p)
{
*p = '\0';
}
p = ('_' == FuncName[0] || '@' == FuncName[0] ? FuncName + 1 : FuncName);
Current->FunctionOffset = FindOrAddString(p,
StringsLength,
StringsBase);
Current->SourceLine = 0;
memset ( ++Current, 0, sizeof(*Current) );
}
i += CoffEntry[i].e_numaux;
}
*SymbolsCount = (Current - *SymbolsBase + 1);
qsort(*SymbolsBase, *SymbolsCount, sizeof(ROSSYM_ENTRY), (int (*)(const void *, const void *)) CompareSymEntry);
return 0;
}
|