Elf Symbol enumeration WIP.
Jeandet Alexis -
r41:da052a0662f0 default
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
@@ -61,6 +61,7 bool ElfFile::openFile(const QString &Fi
61 elf_getshdrstrndx (this->e, &this->shstrndx);
61 elf_getshdrstrndx (this->e, &this->shstrndx);
62 this->updateSegments();
62 this->updateSegments();
63 this->updateSections();
63 this->updateSections();
64 this->updateSymbols();
64 this->opened = true;
65 this->opened = true;
65 return 1;
66 return 1;
66 }
67 }
@@ -751,13 +752,35 void ElfFile::updateSegments()
751
752
752 void ElfFile::updateSymbols()
753 void ElfFile::updateSymbols()
753 {
754 {
755 for(int i=0;i<symbols.count();i++)
756 {
757 delete this->symbols.at(i);
758 }
759 this->symbols.clear();
760 updateSections(); //Useless in most case but safer to do it
761 for(int i=0;i<SectionCount;i++)
762 {
763 //First find Symbol table
764 if(this->getSectionName(i)==".symtab")
765 {
766 Elf_Section* sec = sections.at(i);
767 this->SymbolCount = sec->section_header->sh_size / sec->section_header->sh_entsize;
768 //Then list all symbols
769 for(int j=0;j<this->SymbolCount;j++)
770 {
771 GElf_Sym* esym = (GElf_Sym*)malloc(sizeof(GElf_Sym));
772 gelf_getsym(sec->data, j, esym);
773 QString name = elf_strptr(this->e,sec->section_header->sh_link,esym->st_name);
774 Elf_Symbol* sym = new Elf_Symbol(name,esym);
775 symbols.append(sym);
776 }
777 }
778 }
754
779
755 }
780 }
756
781
757
782
758
783
759
760
761 QString ElfFile::getSectionType(int index)
784 QString ElfFile::getSectionType(int index)
762 {
785 {
763 QString type("");
786 QString type("");
@@ -40,10 +40,24 public:
40 this->data = data;
40 this->data = data;
41 this->section_header = section_header;
41 this->section_header = section_header;
42 }
42 }
43 ~Elf_Section()
44 {
45 free(section_header);
46 }
43 Elf_Data* data;
47 Elf_Data* data;
44 GElf_Shdr* section_header;
48 GElf_Shdr* section_header;
45 };
49 };
46
50
51 class Elf_Symbol
52 {
53 public:
54 Elf_Symbol(){}
55 Elf_Symbol(const QString& name,GElf_Sym* sym):name(name),sym(sym){}
56 ~Elf_Symbol(){free(sym);}
57 QString name;
58 GElf_Sym* sym;
59 };
60
47 class ElfFile : public abstractExecFile
61 class ElfFile : public abstractExecFile
48 {
62 {
49 Q_OBJECT
63 Q_OBJECT
@@ -98,6 +112,7 private:
98 size_t SymbolCount,SectionCount,SegmentCount, shstrndx;
112 size_t SymbolCount,SectionCount,SegmentCount, shstrndx;
99 QList<GElf_Phdr*> Segments;
113 QList<GElf_Phdr*> Segments;
100 QList<Elf_Section*> sections;
114 QList<Elf_Section*> sections;
115 QList<Elf_Symbol*> symbols;
101
116
102 };
117 };
103
118
@@ -26,7 +26,7 void elfFileWidget::updateElfFile(ElfFil
26 this->ui->entryPointLabel->setText(QString("0x%1").arg((uint)p_elf->getEntryPointAddress(),8,16));
26 this->ui->entryPointLabel->setText(QString("0x%1").arg((uint)p_elf->getEntryPointAddress(),8,16));
27 this->ui->typeLabel->setText(p_elf->getType());
27 this->ui->typeLabel->setText(p_elf->getType());
28 this->ui->sectionCountLabel->setText(QString::number(p_elf->getSectionCount()));
28 this->ui->sectionCountLabel->setText(QString::number(p_elf->getSectionCount()));
29 // this->ui->symbolCountLabel->setText(p_elf->get);
29 this->ui->symbolCountLabel->setText(QString::number(p_elf->getSymbolCount()));
30 }
30 }
31 }
31 }
32
32
Comments 0
You need to be logged in to leave comments. Login now