mirror of
https://github.com/momo5502/emulator.git
synced 2026-02-01 00:41:02 +00:00
Simplify import watching
This commit is contained in:
@@ -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{};
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user