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

Merged
TheBrokenRail merged 2 commits from bigjango13/minecraft-pi-reborn:sounds into master 2024-02-07 02:16:35 +00:00
1 changed files with 5 additions and 3 deletions

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 = {};
std::string cpp_source = source;
if (sources.count(cpp_source) == 0) {
bigjango13 marked this conversation as resolved Outdated

Why not do?

static std::unordered_map<std::string, std::unique_ptr<LIEF::ELF::Binary>> sources = {};
std::string cpp_source = source;
if (sources.count(cpp_source) == 0) {
    sources[cpp_source] = LIEF::ELF::Parser::parse(source);
}
std::unique_ptr<LIEF::ELF::Binary> &binary = sources[cpp_source];
Why not do? ```c++ static std::unordered_map<std::string, std::unique_ptr<LIEF::ELF::Binary>> sources = {}; std::string cpp_source = source; if (sources.count(cpp_source) == 0) { sources[cpp_source] = LIEF::ELF::Parser::parse(source); } std::unique_ptr<LIEF::ELF::Binary> &binary = sources[cpp_source]; ```

I didn't know about .count until now. Should I change it to that?

I didn't know about `.count` until now. Should I change it to that?

Yeah, it's what the rest of Reborn uses.

Is it actually better? 🤷

But consistency is good.

Yeah, it's what the rest of Reborn uses. Is it actually better? 🤷 But consistency is good.

Done 👍

Done :+1:
sources[cpp_source] = LIEF::ELF::Parser::parse(source);
}
std::unique_ptr<LIEF::ELF::Binary> &binary = sources[cpp_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);