|
|
|
@ -151,7 +151,7 @@ namespace lnk
|
|
|
|
|
const auto string_table =
|
|
|
|
|
reinterpret_cast<const char*>(
|
|
|
|
|
reinterpret_cast<std::uintptr_t>(symbol_table) +
|
|
|
|
|
(coff_header->NumberOfSymbols * sizeof IMAGE_SYMBOL));
|
|
|
|
|
(coff_header->NumberOfSymbols * sizeof IMAGE_SYMBOL));
|
|
|
|
|
|
|
|
|
|
std::vector<image_reloc_t> result;
|
|
|
|
|
for (auto idx = 0u; idx < coff_header->NumberOfSections; ++idx)
|
|
|
|
@ -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 =
|
|
|
|
@ -187,7 +189,7 @@ namespace lnk
|
|
|
|
|
image_reloc_t entry;
|
|
|
|
|
entry.file_offset =
|
|
|
|
|
reloc_dir[reloc_idx].VirtualAddress +
|
|
|
|
|
section_headers[idx].PointerToRawData;
|
|
|
|
|
section_headers[idx].PointerToRawData;
|
|
|
|
|
|
|
|
|
|
if (symbol_table[reloc_dir[reloc_idx].SymbolTableIndex].N.Name.Short)
|
|
|
|
|
entry.resolve_symbol_name =
|
|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
@ -222,15 +228,25 @@ namespace lnk
|
|
|
|
|
const auto string_table =
|
|
|
|
|
reinterpret_cast<const char*>(
|
|
|
|
|
reinterpret_cast<std::uintptr_t>(symbol_table) +
|
|
|
|
|
(coff_header->NumberOfSymbols * sizeof IMAGE_SYMBOL));
|
|
|
|
|
(coff_header->NumberOfSymbols * sizeof IMAGE_SYMBOL));
|
|
|
|
|
|
|
|
|
|
std::vector<symbol_t> result;
|
|
|
|
|
for (auto idx = 0u; idx < coff_header->NumberOfSymbols; ++idx)
|
|
|
|
|
{
|
|
|
|
|
symbol_t symbol;
|
|
|
|
|
if (symbol_table[idx].N.Name.Short)
|
|
|
|
|
symbol.symbol_name =
|
|
|
|
|
std::string((char*)symbol_table[idx].N.ShortName);
|
|
|
|
|
else
|
|
|
|
|
symbol.symbol_name =
|
|
|
|
|
std::string(string_table +
|
|
|
|
|
symbol_table[idx].N.Name.Long);
|
|
|
|
|
|
|
|
|
|
// 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.symbol_name.empty() ||
|
|
|
|
|
symbol.symbol_name.c_str()[0] == '.' ||
|
|
|
|
|
symbol_table[idx].SectionNumber < 1)
|
|
|
|
|
{
|
|
|
|
|
if (symbol_table[idx].NumberOfAuxSymbols)
|
|
|
|
|
idx += symbol_table[idx].NumberOfAuxSymbols;
|
|
|
|
@ -238,17 +254,8 @@ namespace lnk
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
symbol_t symbol;
|
|
|
|
|
if (symbol_table[idx].N.Name.Short)
|
|
|
|
|
symbol.symbol_name =
|
|
|
|
|
std::string((char*)symbol_table[idx].N.ShortName);
|
|
|
|
|
else
|
|
|
|
|
symbol.symbol_name =
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|