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 @@ -708,8 +708,12 @@ QString ElfFile::getSegmentFlags(int ind QString ElfFile::getSectionName(int index) { - char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name); - return QString(nameChr); + if((index=0)) + { + char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name); + return QString(nameChr); + } + return ""; } @@ -824,6 +828,162 @@ QString ElfFile::getSectionType(int inde return type; } +QString ElfFile::getSymbolName(int index) +{ + if(this->e!=NULL) + { + if(index < this->symbols.count()) + { + return symbols.at(index)->name; + } + } + return ""; +} + +QString ElfFile::getSymbolType(int index) +{ + if(this->e!=NULL) + { + if(index < this->symbols.count()) + { + int type = GELF_ST_TYPE(symbols.at(index)->sym->st_info); + switch(type) + { + case STT_NOTYPE: + return "No Type"; + break; + case STT_OBJECT: + return "Object"; + break; + case STT_FUNC: + return "Function"; + break; + case STT_SECTION: + return "Section"; + break; + case STT_FILE: + return "File"; + break; + case STT_COMMON: + return "Common data object"; + break; + case STT_TLS: + return "Thread-local data object"; + break; + case STT_NUM: + return "Number of defined types"; + break; + case STT_LOOS: + return "Start of OS-specific"; + break; + case STT_HIOS: + return "End of OS-specific"; + break; + case STT_LOPROC: + return "Start of processor-specific"; + break; + case STT_HIPROC: + return "End of processor-specific"; + break; + default: + return "none"; + break; + } + } + } + return "none"; +} + +quint64 ElfFile::getSymbolSize(int index) +{ + if(this->e!=NULL) + { + if((index < this->symbols.count()) && (index>=0)) + { + return symbols.at(index)->sym->st_size; + } + } + return 0; +} + +QString ElfFile::getSymbolSectionName(int index) +{ + if(this->e!=NULL) + { + if((index < this->symbols.count()) && (index>=0)) + { + return getSectionName(symbols.at(index)->sym->st_shndx-1); + } + } + return "none"; +} + +int ElfFile::getSymbolSectionIndex(int index) +{ + if(this->e!=NULL) + { + if((index < this->symbols.count()) && (index>=0)) + { + return symbols.at(index)->sym->st_shndx; + } + } + return 0; +} + +quint64 ElfFile::getSymbolAddress(int index) +{ + if(this->e!=NULL) + { + if((index < this->symbols.count()) && (index>=0)) + { + return symbols.at(index)->sym->st_value; + } + } + return 0; +} + +QString ElfFile::getSymbolLinkType(int index) +{ + if(this->e!=NULL) + { + if(index < this->symbols.count()) + { + int btype = GELF_ST_BIND(symbols.at(index)->sym->st_info); + switch(btype) + { + case STB_LOCAL: + return "Local"; + break; + case STB_GLOBAL: + return "Global"; + break; + case STB_WEAK: + return "Weak"; + break; + case STB_NUM: + return "Number of defined types"; + break; + case STB_LOOS: + return "Start of OS-specific"; + break; + case STB_HIOS: + return "End of OS-specific"; + break; + case STB_LOPROC: + return "Start of processor-specific"; + break; + case STB_HIPROC: + return "End of processor-specific"; + break; + default: + return "none"; + break; + } + } + } + return "none"; +} + bool ElfFile::isElf(const QString &File) { int file =0; 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 @@ -77,22 +77,33 @@ public: QString getABI(); qint64 getVersion(); qint64 getEntryPointAddress(); + int getSectionCount(); int getSymbolCount(); int getSegmentCount(); + QString getSegmentType(int index); qint64 getSegmentOffset(int index); qint64 getSegmentVaddr(int index); qint64 getSegmentPaddr(int index); - qint64 getSectionPaddr(int index); qint64 getSegmentFilesz(int index); qint64 getSectionDatasz(int index); + qint64 getSegmentMemsz(int index); + QString getSegmentFlags(int index); + bool getSectionData(int index, char **buffer); - qint64 getSegmentMemsz(int index); + qint64 getSectionPaddr(int index); qint64 getSectionMemsz(int index); - QString getSegmentFlags(int index); QString getSectionName(int index); QString getSectionType(int index); + + QString getSymbolName(int index); + QString getSymbolType(int index); + quint64 getSymbolSize(int index); + QString getSymbolSectionName(int index); + int getSymbolSectionIndex(int index); + quint64 getSymbolAddress(int index); + QString getSymbolLinkType(int index); bool iself(); static bool isElf(const QString& File); 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 @@ -1,5 +1,6 @@ #include "elffilewidget.h" #include "ui_elffilewidget.h" +#include elfFileWidget::elfFileWidget(QWidget *parent) : QWidget(parent), @@ -28,6 +29,41 @@ void elfFileWidget::updateElfFile(ElfFil this->ui->sectionCountLabel->setText(QString::number(p_elf->getSectionCount())); this->ui->symbolCountLabel->setText(QString::number(p_elf->getSymbolCount())); } + updateSymbols(); +} + +void elfFileWidget::updateSymbols() +{ + this->ui->symbolsList->clear(); + this->ui->symbolsList->setRowCount(p_elf->getSymbolCount()); + this->ui->symbolsList->setHorizontalHeaderLabels(QStringList()<<"Value"<<"Size"<<"Type"<<"Link"<<"Section"<<"Name"); + for(int i=0;igetSymbolCount();i++) + { + QTableWidgetItem *newItem = new QTableWidgetItem(QString("0x%1").arg(p_elf->getSymbolAddress(i),8,16)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 0, newItem); + + newItem = new QTableWidgetItem(QString("0x%1").arg(p_elf->getSymbolSize(i),8,16)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 1, newItem); + + newItem = new QTableWidgetItem(p_elf->getSymbolType(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 2, newItem); + + newItem = new QTableWidgetItem(p_elf->getSymbolLinkType(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 3, newItem); + + newItem = new QTableWidgetItem(p_elf->getSymbolSectionName(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 4, newItem); + + newItem = new QTableWidgetItem(p_elf->getSymbolName(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 5, newItem); + } + this->ui->symbolsList->resizeColumnsToContents(); } @@ -43,4 +79,3 @@ void elfFileWidget::updateElfFile(ElfFil - diff --git a/src/common/elf/elffilewidget.h b/src/common/elf/elffilewidget.h --- a/src/common/elf/elffilewidget.h +++ b/src/common/elf/elffilewidget.h @@ -18,6 +18,7 @@ public: public slots: void updateElfFile(ElfFile* file); + void updateSymbols(); private: Ui::elfFileWidget *ui; diff --git a/src/common/elf/elffilewidget.ui b/src/common/elf/elffilewidget.ui --- a/src/common/elf/elffilewidget.ui +++ b/src/common/elf/elffilewidget.ui @@ -6,8 +6,8 @@ 0 0 - 622 - 398 + 786 + 387 @@ -26,7 +26,7 @@ - 0 + 1 @@ -185,7 +185,41 @@ - + + + true + + + + Value + + + + + Size + + + + + Type + + + + + Link + + + + + Section + + + + + Name + + +