aclements / libelfin

C++11 ELF/DWARF parser
MIT License
314 stars 99 forks source link

Sorting sections? #43

Open dnezamaev opened 4 years ago

dnezamaev commented 4 years ago

Hi. Thank you for library, it is really easy to use it. However i dont understand one thing. How to sort sections vector returned by elf::sections() method? Getting error, when i using std::sort() like this:

bool compare_sections_name(const elf::section & section1, const elf::section & section2)
{
  return section1.get_name() < section2.get_name();
}

// later in main
elf::elf f(elf::create_mmap_loader(fd));
auto sorted = f.sections();
std::sort(sorted.begin(), sorted.end(), compare_sections_by_name);

AFAIK it happens because elf::section class must implement assignment operator and it does not. So i suggest to add line to class declaration (and probably do same for segment class): section & operator = (section const &) = default;

The only my idea how to do sorting now is to get vector of pointers sections and sort pointers, but i dont like such workaround.