diff --git a/src/common/elf/elffile.cpp b/src/common/elf/elffile.cpp --- a/src/common/elf/elffile.cpp +++ b/src/common/elf/elffile.cpp @@ -61,6 +61,7 @@ bool ElfFile::openFile(const QString &Fi elf_getshdrstrndx (this->e, &this->shstrndx); this->updateSegments(); this->updateSections(); + this->updateSymbols(); this->opened = true; return 1; } @@ -751,13 +752,35 @@ void ElfFile::updateSegments() void ElfFile::updateSymbols() { + for(int i=0;isymbols.at(i); + } + this->symbols.clear(); + updateSections(); //Useless in most case but safer to do it + for(int i=0;igetSectionName(i)==".symtab") + { + Elf_Section* sec = sections.at(i); + this->SymbolCount = sec->section_header->sh_size / sec->section_header->sh_entsize; + //Then list all symbols + for(int j=0;jSymbolCount;j++) + { + GElf_Sym* esym = (GElf_Sym*)malloc(sizeof(GElf_Sym)); + gelf_getsym(sec->data, j, esym); + QString name = elf_strptr(this->e,sec->section_header->sh_link,esym->st_name); + Elf_Symbol* sym = new Elf_Symbol(name,esym); + symbols.append(sym); + } + } + } } - - QString ElfFile::getSectionType(int index) { QString type(""); diff --git a/src/common/elf/elffile.h b/src/common/elf/elffile.h --- a/src/common/elf/elffile.h +++ b/src/common/elf/elffile.h @@ -40,10 +40,24 @@ public: this->data = data; this->section_header = section_header; } + ~Elf_Section() + { + free(section_header); + } Elf_Data* data; GElf_Shdr* section_header; }; +class Elf_Symbol +{ +public: + Elf_Symbol(){} + Elf_Symbol(const QString& name,GElf_Sym* sym):name(name),sym(sym){} + ~Elf_Symbol(){free(sym);} + QString name; + GElf_Sym* sym; +}; + class ElfFile : public abstractExecFile { Q_OBJECT @@ -98,6 +112,7 @@ private: size_t SymbolCount,SectionCount,SegmentCount, shstrndx; QList Segments; QList sections; + QList symbols; }; diff --git a/src/common/elf/elffilewidget.cpp b/src/common/elf/elffilewidget.cpp --- a/src/common/elf/elffilewidget.cpp +++ b/src/common/elf/elffilewidget.cpp @@ -26,7 +26,7 @@ void elfFileWidget::updateElfFile(ElfFil this->ui->entryPointLabel->setText(QString("0x%1").arg((uint)p_elf->getEntryPointAddress(),8,16)); this->ui->typeLabel->setText(p_elf->getType()); this->ui->sectionCountLabel->setText(QString::number(p_elf->getSectionCount())); -// this->ui->symbolCountLabel->setText(p_elf->get); + this->ui->symbolCountLabel->setText(QString::number(p_elf->getSymbolCount())); } }