diff --git a/elf/elffile.cpp b/elf/elffile.cpp --- a/elf/elffile.cpp +++ b/elf/elffile.cpp @@ -776,18 +776,21 @@ void ElfFile::updateSections() void ElfFile::updateSegments() { - elf_getphdrnum (this->e , &this->SegmentCount); for(int i=0;iSegments.count();i++) { free(this->Segments.at(i)); } this->Segments.clear(); - for(int i=0;i<(int)this->SegmentCount;i++) + this->SegmentCount = 0; + GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); + while ( header == gelf_getphdr(this->e ,this->SegmentCount, header )) { - GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); - gelf_getphdr (this->e , i , header ); this->Segments.append(header); + this->SegmentCount++; + header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); } + this->SegmentCount = this->Segments.count(); + free(header); } void ElfFile::updateSymbols() diff --git a/elf/elfparser.cpp b/elf/elfparser.cpp --- a/elf/elfparser.cpp +++ b/elf/elfparser.cpp @@ -433,18 +433,21 @@ void elfparser::updateSections() void elfparser::updateSegments() { - elf_getphdrnum (this->e , &this->SegmentCount); for(int i=0;iSegments.count();i++) { free(this->Segments.at(i)); } this->Segments.clear(); - for(int i=0;i<(int)this->SegmentCount;i++) + this->SegmentCount = 0; + GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); + while ( header == gelf_getphdr(this->e ,this->SegmentCount, header )) { - GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); - gelf_getphdr (this->e , i , header ); this->Segments.append(header); + this->SegmentCount++; + header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr)); } + this->SegmentCount = this->Segments.count(); + free(header); }