Fix load_symbol ignoring source when a previous source has already been loaded

This commit is contained in:
Bigjango13 2024-01-30 19:44:07 -05:00
parent 5c5538df2f
commit a31641d106

View File

@ -13,10 +13,12 @@
// Load Symbol From ELF File
static void load_symbol(const char *source, const char *name, std::function<void(const unsigned char *, uint32_t)> callback) {
static std::unique_ptr<LIEF::ELF::Binary> binary = NULL;
if (binary == NULL) {
binary = LIEF::ELF::Parser::parse(source);
static std::unordered_map<std::string, std::unique_ptr<LIEF::ELF::Binary>> sources = {};
auto pos = sources.find(std::string(source));
if (pos == sources.end()) {
sources[std::string(source)] = LIEF::ELF::Parser::parse(source);
}
std::unique_ptr<LIEF::ELF::Binary> &binary = sources[std::string(source)];
const LIEF::ELF::Symbol *symbol = binary->get_dynamic_symbol(name);
if (symbol != NULL) {
LIEF::span<const uint8_t> data = binary->get_content_from_virtual_address(symbol->value(), symbol->size(), LIEF::Binary::VA_TYPES::VA);