Description
elfconv needs to parse the ELF binary and uses two libraries, libbfd and libelf. However, libelf is enough to parse ELF binary and it is specific to ELF format, so we should fix not to use libbfd.
For example, elfconv uses libbfd to get every section data as follows, but maybe libelf can do the same functions.
|
void ELFObject::LoadSectionsBFD() { |
|
|
|
asection *bfd_sec; |
|
|
|
for (bfd_sec = bfd_h->sections; bfd_sec; bfd_sec = bfd_sec->next) { |
|
|
|
ELFSection::SectionType sec_type; |
|
flagword bfd_flags; |
|
bfd_vma vma; |
|
bfd_size_type size; |
|
std::string sec_name; |
|
uint8_t *sec_bytes; |
|
|
|
// get bfd flags |
|
bfd_flags = bfd_section_flags(bfd_sec); |
|
if (bfd_flags & SEC_CODE) { |
|
sec_type = ELFSection::SEC_TYPE_CODE; |
|
} else if (bfd_flags & (SEC_DATA | SEC_ALLOC)) { |
|
sec_type = ELFSection::SEC_TYPE_DATA; |
|
} else if (bfd_flags & SEC_READONLY) { |
|
sec_type = ELFSection::SEC_TYPE_READONLY; |
|
} else { |
|
sec_type = ELFSection::SEC_TYPE_UNKNOWN; |
|
} |
|
// get vma, section size, section name, section contents |
|
vma = bfd_section_vma(bfd_sec); |
|
size = bfd_section_size(bfd_sec); |
|
sec_name = std::string(bfd_section_name(bfd_sec)); |
|
if (sec_name.empty()) { |
|
sec_name = std::string("<unnamed>"); |
|
} |
|
sec_bytes = reinterpret_cast<uint8_t *>(malloc(size)); |
|
if (!sec_bytes) { |
|
elfconv_runtime_error("failed to allocate section bytes.\n"); |
|
} |
|
if (!bfd_get_section_contents(bfd_h, bfd_sec, sec_bytes, 0, size)) { |
|
elfconv_runtime_error("failed to read and copy section bytes.\n"); |
|
} |
|
|
|
sections.emplace_back(this, sec_type, sec_name, vma, size, sec_bytes); |
|
} |
|
} |
Description
elfconv needs to parse the ELF binary and uses two libraries,
libbfdandlibelf. However,libelfis enough to parse ELF binary and it is specific to ELF format, so we should fix not to uselibbfd.For example, elfconv uses
libbfdto get every section data as follows, but maybelibelfcan do the same functions.elfconv/lifter/Binary/Loader.cpp
Lines 261 to 302 in 2853198