Simplify import watching

This commit is contained in:
momo5502
2025-09-08 19:04:12 +02:00
parent a671deb383
commit e55e078e92
4 changed files with 25 additions and 104 deletions

View File

@@ -12,11 +12,12 @@ struct exported_symbol
struct imported_symbol
{
std::string name{};
uint64_t address{};
size_t module_index{};
};
using exported_symbols = std::vector<exported_symbol>;
using imported_symbols = std::map<std::string, std::vector<imported_symbol>>;
using imported_symbols = std::unordered_map<uint64_t, imported_symbol>;
using imported_module_list = std::vector<std::string>;
using address_name_mapping = std::map<uint64_t, std::string>;
struct mapped_section
@@ -36,6 +37,7 @@ struct mapped_module
exported_symbols exports{};
imported_symbols imports{};
imported_module_list imported_modules{};
address_name_mapping address_names{};
std::vector<mapped_section> sections{};

View File

@@ -48,8 +48,8 @@ namespace
break;
}
const auto module_name = buffer.as_string(descriptor.Name);
auto& imports = binary.imports[module_name];
const auto module_index = binary.imported_modules.size();
binary.imported_modules.push_back(buffer.as_string(descriptor.Name));
auto original_thunk_data = buffer.as<IMAGE_THUNK_DATA64>(descriptor.FirstThunk);
if (descriptor.OriginalFirstThunk)
@@ -65,11 +65,12 @@ namespace
break;
}
imported_symbol sym{};
static_assert(sizeof(IMAGE_THUNK_DATA64) == sizeof(uint64_t));
const auto thunk_rva = descriptor.FirstThunk + sizeof(IMAGE_THUNK_DATA64) * j;
sym.address = thunk_rva + binary.image_base;
const auto thunk_address = thunk_rva + binary.image_base;
auto& sym = binary.imports[thunk_address];
sym.module_index = module_index;
if (IMAGE_SNAP_BY_ORDINAL64(original_thunk.u1.Ordinal))
{
@@ -80,8 +81,6 @@ namespace
sym.name =
buffer.as_string(static_cast<size_t>(original_thunk.u1.AddressOfData + offsetof(IMAGE_IMPORT_BY_NAME, Name)));
}
imports.push_back(std::move(sym));
}
}
}