@@ -29,61 +29,58 ElfFile::ElfFile(QObject *parent) : | |||
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | ElfFile::ElfFile(const QString &File, QObject *parent) |
|
32 | :abstractExecFile(parent) | |
|
32 | :abstractExecFile(parent),elfparser() | |
|
33 | 33 | { |
|
34 | 34 | this->p_fileName = File; |
|
35 |
|
|
|
35 | setFilename(File); | |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | bool ElfFile::openFile(const QString &File) |
|
39 | 39 | { |
|
40 | 40 | this->p_fileName = File; |
|
41 |
|
|
|
41 | return setFilename(File); | |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | bool ElfFile::isopened() |
|
45 | 45 | { |
|
46 |
return parser |
|
|
46 | return elfparser::isopened(); | |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | int ElfFile::closeFile() |
|
50 | 50 | { |
|
51 |
return parser |
|
|
51 | return elfparser::closeFile(); | |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | QList<codeFragment> ElfFile::getFragments() | |
|
55 | { | |
|
56 | QList<codeFragment> fragments; | |
|
57 | if (parser.isopened()) | |
|
58 | { | |
|
59 | fragments.append(getFragment(".text")); | |
|
60 | fragments.append(getFragment(".data")); | |
|
61 | } | |
|
62 | } | |
|
63 | 54 | |
|
64 | 55 | QList<codeFragment> ElfFile::getFragments(QStringList fragmentList) |
|
65 | 56 | { |
|
66 | 57 | QList<codeFragment> fragments; |
|
67 |
if ( |
|
|
58 | if (isopened()) | |
|
68 | 59 | { |
|
69 | 60 | for(int i =0;i<fragmentList.count();i++) |
|
70 | 61 | { |
|
71 | 62 | fragments.append(getFragment(fragmentList.at(i))); |
|
72 | 63 | } |
|
73 | 64 | } |
|
65 | return fragments; | |
|
66 | } | |
|
67 | ||
|
68 | QList<codeFragment> ElfFile::getFragments() | |
|
69 | { | |
|
70 | return getFragments(QStringList()<<".data"<<".text"); | |
|
74 | 71 | } |
|
75 | 72 | |
|
76 | 73 | codeFragment ElfFile::getFragment(const QString &name) |
|
77 | 74 | { |
|
78 | 75 | codeFragment fragment; |
|
79 |
for(int i=0;i< |
|
|
76 | for(int i=0;i<getSectioncount();i++) | |
|
80 | 77 | { |
|
81 |
if( |
|
|
78 | if(getSectionName(i) == name) | |
|
82 | 79 | { |
|
83 | 80 | fragment.data =NULL; |
|
84 |
fragment.size = |
|
|
85 |
fragment.address = |
|
|
86 |
|
|
|
81 | fragment.size = getSectionDatasz(i); | |
|
82 | fragment.address = getSectionPaddr(i); | |
|
83 | getSectionData(i,&fragment.data); | |
|
87 | 84 | } |
|
88 | 85 | } |
|
89 | 86 |
@@ -27,7 +27,7 | |||
|
27 | 27 | #ifndef ELFFILE_H |
|
28 | 28 | #define ELFFILE_H |
|
29 | 29 | |
|
30 | class ElfFile : public abstractExecFile | |
|
30 | class ElfFile : public abstractExecFile, public elfparser | |
|
31 | 31 | { |
|
32 | 32 | Q_OBJECT |
|
33 | 33 | public: |
@@ -38,11 +38,12 public: | |||
|
38 | 38 | int closeFile(); |
|
39 | 39 | QList<codeFragment> getFragments(); |
|
40 | 40 | QList<codeFragment> getFragments(QStringList fragmentList); |
|
41 | // elfparser parser; | |
|
42 | ||
|
41 | 43 | signals: |
|
42 | 44 | |
|
43 | 45 | public slots: |
|
44 | 46 | private: |
|
45 | elfparser parser; | |
|
46 | 47 | codeFragment getFragment(const QString& name); |
|
47 | 48 | |
|
48 | 49 | }; |
@@ -12,3 +12,15 elfFileWidget::~elfFileWidget() | |||
|
12 | 12 | { |
|
13 | 13 | delete ui; |
|
14 | 14 | } |
|
15 | ||
|
16 | void elfFileWidget::updateElfFile(ElfFile *file) | |
|
17 | { | |
|
18 | this->p_elf = file; | |
|
19 | if(p_elf->isopened() && p_elf->iself()) | |
|
20 | { | |
|
21 | this->ui->classLabel->setText(p_elf->getClass()); | |
|
22 | this->ui->VersionLabel->setText(QString::number(p_elf->getVersion())); | |
|
23 | this->ui->machineLabel->setText(p_elf->getArchitecture()); | |
|
24 | this->ui->endiannesLabel->setText(p_elf->getEndianness()); | |
|
25 | } | |
|
26 | } |
@@ -2,6 +2,7 | |||
|
2 | 2 | #define ELFFILEWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include <QWidget> |
|
5 | #include "elffile.h" | |
|
5 | 6 | |
|
6 | 7 | namespace Ui { |
|
7 | 8 | class elfFileWidget; |
@@ -14,9 +15,12 class elfFileWidget : public QWidget | |||
|
14 | 15 | public: |
|
15 | 16 | explicit elfFileWidget(QWidget *parent = 0); |
|
16 | 17 | ~elfFileWidget(); |
|
18 | public slots: | |
|
19 | void updateElfFile(ElfFile* file); | |
|
17 | 20 | |
|
18 | 21 | private: |
|
19 | 22 | Ui::elfFileWidget *ui; |
|
23 | ElfFile* p_elf; | |
|
20 | 24 | }; |
|
21 | 25 | |
|
22 | 26 | #endif // ELFFILEWIDGET_H |
@@ -30,8 +30,154 | |||
|
30 | 30 | </property> |
|
31 | 31 | <widget class="QWidget" name="generalInfoTab"> |
|
32 | 32 | <attribute name="title"> |
|
33 |
<string> |
|
|
33 | <string>File Informations</string> | |
|
34 | 34 | </attribute> |
|
35 | <layout class="QGridLayout" name="gridLayout_4"> | |
|
36 | <item row="0" column="0"> | |
|
37 | <widget class="QGroupBox" name="groupBox"> | |
|
38 | <property name="title"> | |
|
39 | <string>Elf header</string> | |
|
40 | </property> | |
|
41 | <layout class="QFormLayout" name="formLayout"> | |
|
42 | <item row="0" column="0"> | |
|
43 | <widget class="QLabel" name="label"> | |
|
44 | <property name="text"> | |
|
45 | <string>Class:</string> | |
|
46 | </property> | |
|
47 | </widget> | |
|
48 | </item> | |
|
49 | <item row="0" column="1"> | |
|
50 | <widget class="QLabel" name="classLabel"> | |
|
51 | <property name="text"> | |
|
52 | <string>none</string> | |
|
53 | </property> | |
|
54 | </widget> | |
|
55 | </item> | |
|
56 | <item row="1" column="0"> | |
|
57 | <widget class="QLabel" name="label_3"> | |
|
58 | <property name="text"> | |
|
59 | <string>Endianness:</string> | |
|
60 | </property> | |
|
61 | </widget> | |
|
62 | </item> | |
|
63 | <item row="1" column="1"> | |
|
64 | <widget class="QLabel" name="endiannesLabel"> | |
|
65 | <property name="text"> | |
|
66 | <string>none</string> | |
|
67 | </property> | |
|
68 | </widget> | |
|
69 | </item> | |
|
70 | <item row="2" column="0"> | |
|
71 | <widget class="QLabel" name="label_5"> | |
|
72 | <property name="text"> | |
|
73 | <string>Version:</string> | |
|
74 | </property> | |
|
75 | </widget> | |
|
76 | </item> | |
|
77 | <item row="3" column="0"> | |
|
78 | <widget class="QLabel" name="label_6"> | |
|
79 | <property name="text"> | |
|
80 | <string>Type:</string> | |
|
81 | </property> | |
|
82 | </widget> | |
|
83 | </item> | |
|
84 | <item row="4" column="0"> | |
|
85 | <widget class="QLabel" name="label_7"> | |
|
86 | <property name="text"> | |
|
87 | <string>Machine:</string> | |
|
88 | </property> | |
|
89 | </widget> | |
|
90 | </item> | |
|
91 | <item row="6" column="0"> | |
|
92 | <widget class="QLabel" name="label_8"> | |
|
93 | <property name="text"> | |
|
94 | <string>Entry point address:</string> | |
|
95 | </property> | |
|
96 | </widget> | |
|
97 | </item> | |
|
98 | <item row="2" column="1"> | |
|
99 | <widget class="QLabel" name="VersionLabel"> | |
|
100 | <property name="text"> | |
|
101 | <string>none</string> | |
|
102 | </property> | |
|
103 | </widget> | |
|
104 | </item> | |
|
105 | <item row="3" column="1"> | |
|
106 | <widget class="QLabel" name="typeLabel"> | |
|
107 | <property name="text"> | |
|
108 | <string>none</string> | |
|
109 | </property> | |
|
110 | </widget> | |
|
111 | </item> | |
|
112 | <item row="4" column="1"> | |
|
113 | <widget class="QLabel" name="machineLabel"> | |
|
114 | <property name="text"> | |
|
115 | <string>none</string> | |
|
116 | </property> | |
|
117 | </widget> | |
|
118 | </item> | |
|
119 | <item row="6" column="1"> | |
|
120 | <widget class="QLabel" name="entryPointLabel"> | |
|
121 | <property name="text"> | |
|
122 | <string>none</string> | |
|
123 | </property> | |
|
124 | </widget> | |
|
125 | </item> | |
|
126 | <item row="5" column="0"> | |
|
127 | <widget class="QLabel" name="label_17"> | |
|
128 | <property name="text"> | |
|
129 | <string>OS/ABI:</string> | |
|
130 | </property> | |
|
131 | </widget> | |
|
132 | </item> | |
|
133 | <item row="5" column="1"> | |
|
134 | <widget class="QLabel" name="abiLabel"> | |
|
135 | <property name="text"> | |
|
136 | <string>none</string> | |
|
137 | </property> | |
|
138 | </widget> | |
|
139 | </item> | |
|
140 | </layout> | |
|
141 | </widget> | |
|
142 | </item> | |
|
143 | <item row="1" column="0"> | |
|
144 | <widget class="QGroupBox" name="groupBox_2"> | |
|
145 | <property name="title"> | |
|
146 | <string>Sections</string> | |
|
147 | </property> | |
|
148 | <layout class="QFormLayout" name="formLayout_2"> | |
|
149 | <item row="0" column="0"> | |
|
150 | <widget class="QLabel" name="label_9"> | |
|
151 | <property name="text"> | |
|
152 | <string>Section count:</string> | |
|
153 | </property> | |
|
154 | </widget> | |
|
155 | </item> | |
|
156 | <item row="1" column="0"> | |
|
157 | <widget class="QLabel" name="label_10"> | |
|
158 | <property name="text"> | |
|
159 | <string>Sections begin address:</string> | |
|
160 | </property> | |
|
161 | </widget> | |
|
162 | </item> | |
|
163 | <item row="0" column="1"> | |
|
164 | <widget class="QLabel" name="sectionCountLabel"> | |
|
165 | <property name="text"> | |
|
166 | <string>none</string> | |
|
167 | </property> | |
|
168 | </widget> | |
|
169 | </item> | |
|
170 | <item row="1" column="1"> | |
|
171 | <widget class="QLabel" name="sectionBeginLabel"> | |
|
172 | <property name="text"> | |
|
173 | <string>none</string> | |
|
174 | </property> | |
|
175 | </widget> | |
|
176 | </item> | |
|
177 | </layout> | |
|
178 | </widget> | |
|
179 | </item> | |
|
180 | </layout> | |
|
35 | 181 | </widget> |
|
36 | 182 | <widget class="QWidget" name="symbolsTab"> |
|
37 | 183 | <attribute name="title"> |
@@ -321,6 +321,17 int elfparser::closeFile() | |||
|
321 | 321 | return 0; |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | QString elfparser::getClass() | |
|
325 | { | |
|
326 | if(this->e!=NULL) | |
|
327 | { | |
|
328 | int eclass = gelf_getclass(this->e); | |
|
329 | if(eclass==ELFCLASS32)return "ELF32"; | |
|
330 | if(eclass==ELFCLASS64)return "ELF64"; | |
|
331 | } | |
|
332 | return "none"; | |
|
333 | } | |
|
334 | ||
|
324 | 335 | |
|
325 | 336 | bool elfparser::isopened() |
|
326 | 337 | { |
@@ -374,6 +385,16 QString elfparser::getType() | |||
|
374 | 385 | return kind; |
|
375 | 386 | } |
|
376 | 387 | |
|
388 | QString elfparser::getEndianness() | |
|
389 | { | |
|
390 | if(this->e!=NULL) | |
|
391 | { | |
|
392 | if(this->ehdr.e_ident[EI_DATA]==ELFDATA2LSB)return "2's complement, little endian"; | |
|
393 | if(this->ehdr.e_ident[EI_DATA]==ELFDATA2MSB)return "2's complement, big endian"; | |
|
394 | } | |
|
395 | return "none"; | |
|
396 | } | |
|
397 | ||
|
377 | 398 | |
|
378 | 399 | int32_t elfparser::getVersion() |
|
379 | 400 | { |
@@ -49,8 +49,10 public: | |||
|
49 | 49 | bool isopened(); |
|
50 | 50 | int setFilename(const QString& name); |
|
51 | 51 | int closeFile(); |
|
52 | QString getClass(); | |
|
52 | 53 | QString getArchitecture(); |
|
53 | 54 | QString getType(); |
|
55 | QString getEndianness(); | |
|
54 | 56 | int32_t getVersion(); |
|
55 | 57 | int getSectioncount(); |
|
56 | 58 | int getSegmentcount(); |
@@ -82,7 +84,6 private: | |||
|
82 | 84 | Elf_Data * data; |
|
83 | 85 | size_t SectionCount,SegmentCount, shstrndx; |
|
84 | 86 | QList<GElf_Phdr*> Segments; |
|
85 | //QList<GElf_Shdr*> Sections; | |
|
86 | 87 | QList<Elf_Section*> sections; |
|
87 | 88 | |
|
88 | 89 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now