I was skipping over symbols/relocs that I needed to handle

2.0
_xeroxz 4 years ago
parent 0c421e5050
commit 0c915c05d3

@ -171,10 +171,12 @@ namespace lnk
continue;
// skip both the .pdata and the .xdata sections... these are used for exceptions...
if (!strncmp((char*)section_headers[idx].Name, ".pdata", strlen(".pdata") - 1))
if (!strncmp(reinterpret_cast<const char*>(
section_headers[idx].Name), ".pdata", strlen(".pdata") - 1))
continue;
if (!strncmp((char*)section_headers[idx].Name, ".xdata", strlen(".xdata") - 1))
if (!strncmp(reinterpret_cast<const char*>(
section_headers[idx].Name), ".xdata", strlen(".xdata") - 1))
continue;
const auto reloc_dir =
@ -198,6 +200,10 @@ namespace lnk
string_table + symbol_table[reloc_dir[
reloc_idx].SymbolTableIndex].N.Name.Long);
if (entry.resolve_symbol_name.empty() ||
entry.resolve_symbol_name.c_str()[0] == '.')
continue;
entry.type = reloc_dir[reloc_idx].Type;
result.push_back(entry);
}
@ -227,17 +233,6 @@ namespace lnk
std::vector<symbol_t> result;
for (auto idx = 0u; idx < coff_header->NumberOfSymbols; ++idx)
{
// skip section symbols... we only want
// .data, .rdata, and executable (function) symbols...
if (symbol_table[idx].StorageClass != IMAGE_SYM_CLASS_EXTERNAL
|| !symbol_table[idx].SectionNumber)
{
if (symbol_table[idx].NumberOfAuxSymbols)
idx += symbol_table[idx].NumberOfAuxSymbols;
continue;
}
symbol_t symbol;
if (symbol_table[idx].N.Name.Short)
symbol.symbol_name =
@ -247,8 +242,20 @@ namespace lnk
std::string(string_table +
symbol_table[idx].N.Name.Long);
symbol.file_offset = section_headers[symbol_table[
idx].SectionNumber - 1].PointerToRawData + symbol_table[idx].Value;
// skip section symbols... we only want
// .data, .rdata, and executable (function) symbols...
if (symbol.symbol_name.empty() ||
symbol.symbol_name.c_str()[0] == '.' ||
symbol_table[idx].SectionNumber < 1)
{
if (symbol_table[idx].NumberOfAuxSymbols)
idx += symbol_table[idx].NumberOfAuxSymbols;
continue;
}
symbol.file_offset = section_headers[symbol_table[idx]
.SectionNumber - 1].PointerToRawData + symbol_table[idx].Value;
symbol.section_number = symbol_table[idx].SectionNumber;
symbol.section_offset = symbol_table[idx].Value;

@ -96,9 +96,10 @@ namespace theo
{
if (reloc.type != IMAGE_REL_AMD64_ADDR64)
{
std::printf("[!] error... unsupported relocation at file offset = 0x%x\n\t> symbol = %s\n",
reloc.file_offset, reloc.resolve_symbol_name.c_str());
std::printf("[!] error... unsupported relocation at file offset = 0x%x\n", reloc.file_offset);
std::printf("\t> symbol = %s\n", reloc.resolve_symbol_name.c_str());
std::printf("\t> reloc type = 0x%x\n", reloc.type);
std::printf("\t> object size = 0x%x\n", obj.size());
return false;
}
@ -109,9 +110,9 @@ namespace theo
// check obj symbol table for this relocation...
if (mapped_symbols[reloc.resolve_symbol_name])
{
std::printf(" > resolving internal symbol...\n");
std::printf(" > address = 0x%p\n", mapped_symbols[reloc.resolve_symbol_name]);
std::printf(" > symbol = %s\n", reloc.resolve_symbol_name.c_str());
std::printf("\t> resolving internal symbol...\n");
std::printf("\t\t> address = 0x%p\n", mapped_symbols[reloc.resolve_symbol_name]);
std::printf("\t\t> symbol = %s\n", reloc.resolve_symbol_name.c_str());
*reloc_addr = mapped_symbols[reloc.resolve_symbol_name];
}
else // else check external symbol table...
@ -130,9 +131,9 @@ namespace theo
*reloc_addr = extern_symbol;
}
std::printf(" > resolving external symbol...\n");
std::printf(" > address = 0x%p\n", *reloc_addr);
std::printf(" > symbol = %s\n", reloc.resolve_symbol_name.c_str());
std::printf("\t> resolving external symbol...\n");
std::printf("\t\t> address = 0x%p\n", *reloc_addr);
std::printf("\t\t> symbol = %s\n", reloc.resolve_symbol_name.c_str());
}
}
return true;

Loading…
Cancel
Save