Fix conflict when the builder tries to resolve the DT_XXX_ARRAY section

This commit is contained in:
Romain Thomas 2019-05-20 10:59:39 +02:00
parent 3730e447e1
commit 22344e764e
3 changed files with 20 additions and 1 deletions

View File

@ -121,6 +121,8 @@ class LIEF_API Builder {
bool should_swap(void) const;
Section& array_section(uint64_t addr);
mutable vector_iostream ios_;
Binary* binary_;

View File

@ -222,5 +222,22 @@ void Builder::build(NOTE_TYPES type) {
}
Section& Builder::array_section(uint64_t addr) {
static const std::set<ELF_SECTION_TYPES> ARRAY_TYPES = {
ELF_SECTION_TYPES::SHT_INIT_ARRAY,
ELF_SECTION_TYPES::SHT_FINI_ARRAY,
ELF_SECTION_TYPES::SHT_PREINIT_ARRAY,
};
for (Section* section : this->binary_->sections_) {
if (section->virtual_address() >= addr and
addr < (section->virtual_address() + section->size())
and ARRAY_TYPES.count(section->type()) > 0) {
return *section;
}
}
throw not_found("Can find the section associated with DT_ARRAY");
}
}
}

View File

@ -616,7 +616,7 @@ void Builder::build_dynamic_section(void) {
throw not_found(std::string("Unable to find the 'DT_ARRAYSZ' associated with ") + to_string(entry->tag()));
}
Section& array_section = this->binary_->section_from_virtual_address(address);
Section& array_section = this->array_section(address);
const std::vector<uint64_t>& array = entry->as<DynamicEntryArray>()->array();
const size_t array_size = array.size() * sizeof(Elf_Addr);