##// END OF EJS Templates
Elf viewer almost completed.
Jeandet Alexis -
r43:10bc9884d696 default
parent child
Show More
@@ -0,0 +1,51
1 #include "qtablewidgetintitem.h"
2
3 QTableWidgetIntItem::QTableWidgetIntItem(const QString &text,int Type)
4 :QTableWidgetItem(text,Type)
5 {
6 }
7
8 bool QTableWidgetIntItem::operator <(const QTableWidgetItem& other) const
9 {
10 return toInt() < toInt(other);
11 }
12
13 bool QTableWidgetIntItem::operator >(const QTableWidgetItem &other) const
14 {
15 return toInt() > toInt(other);
16 }
17
18 bool QTableWidgetIntItem::operator ==(const QTableWidgetItem &other) const
19 {
20 return toInt() == toInt(other);
21 }
22
23 int QTableWidgetIntItem::toInt() const
24 {
25 bool ok=true;
26 if(type()==DecimalItem)
27 {
28 return text().toInt();
29 }
30 else if(type()==HexaDecimalItem)
31 {
32 return text().replace("0x","").toInt(&ok,16);
33 }
34 return 0;
35 }
36
37 int QTableWidgetIntItem::toInt(const QTableWidgetItem &item) const
38 {
39 bool ok=true;
40 if(item.type()==DecimalItem)
41 {
42 return item.text().toInt();
43 }
44 else if(item.type()==HexaDecimalItem)
45 {
46 return item.text().replace("0x","").toInt(&ok,16);
47 }
48 return 0;
49 }
50
51
@@ -0,0 +1,22
1 #ifndef QTABLEWIDGETINTITEM_H
2 #define QTABLEWIDGETINTITEM_H
3
4 #include <QTableWidgetItem>
5
6 #define DecimalItem 0
7 #define HexaDecimalItem 1
8
9 class QTableWidgetIntItem : public QTableWidgetItem
10 {
11
12 public:
13 explicit QTableWidgetIntItem(const QString& text, int Type);
14 bool operator <(const QTableWidgetItem &other)const;
15 bool operator >(const QTableWidgetItem &other)const;
16 bool operator ==(const QTableWidgetItem &other)const;
17 int toInt() const;
18 int toInt(const QTableWidgetItem &item) const;
19
20 };
21
22 #endif // QTABLEWIDGETINTITEM_H
@@ -40,7 +40,8 header.files = \
40 40 elf/elffile.h \
41 41 elf/elffilewidget.h \
42 42 qipdialogbox.h \
43 lppserial/src/RS232.h
43 lppserial/src/RS232.h \
44 qtablewidgetintitem.h
44 45
45 46 win32{
46 47 elfheader.path = $$[QT_INSTALL_HEADERS]/SocExplorer/common/libelf
@@ -85,7 +86,8 HEADERS += \
85 86 qipdialogbox.h \
86 87 PySocExplorer.h \
87 88 SocExplorerPlot.h \
88 elf/elffilewidget.h
89 elf/elffilewidget.h \
90 qtablewidgetintitem.h
89 91
90 92
91 93 SOURCES += \
@@ -104,7 +106,8 SOURCES += \
104 106 elf/elffile.cpp \
105 107 qipdialogbox.cpp \
106 108 SocExplorerPlot.cpp \
107 elf/elffilewidget.cpp
109 elf/elffilewidget.cpp \
110 qtablewidgetintitem.cpp
108 111
109 112 FORMS += \
110 113 elf/elffilewidget.ui
@@ -43,6 +43,28 ElfFile::ElfFile(const QString &File)
43 43 openFile(File);
44 44 }
45 45
46 ElfFile::~ElfFile()
47 {
48 closeFile();
49 if(scn)free(scn);
50 if(data)free(data);
51 for(int i=0;i<this->sections.count();i++)
52 {
53 delete this->sections.at(i);
54 }
55 this->sections.clear();
56 for(int i=0;i<this->Segments.count();i++)
57 {
58 free(this->Segments.at(i));
59 }
60 this->Segments.clear();
61 for(int i=0;i<symbols.count();i++)
62 {
63 delete this->symbols.at(i);
64 }
65 this->symbols.clear();
66 }
67
46 68 bool ElfFile::openFile(const QString &File)
47 69 {
48 70 this->p_fileName = File;
@@ -828,6 +850,19 QString ElfFile::getSectionType(int inde
828 850 return type;
829 851 }
830 852
853 int ElfFile::getSectionIndex(QString name)
854 {
855 if(this->e!=NULL)
856 {
857 for(int i=0;i<sections.count();i++)
858 {
859 if(getSectionName(i)==name)
860 return i;
861 }
862 }
863 return -1;
864 }
865
831 866 QString ElfFile::getSymbolName(int index)
832 867 {
833 868 if(this->e!=NULL)
@@ -64,6 +64,7 class ElfFile : public abstractExecFile
64 64 public:
65 65 ElfFile();
66 66 ElfFile(const QString& File);
67 ~ElfFile();
67 68 bool openFile(const QString& File);
68 69 bool isopened();
69 70 int closeFile();
@@ -96,6 +97,7 public:
96 97 qint64 getSectionMemsz(int index);
97 98 QString getSectionName(int index);
98 99 QString getSectionType(int index);
100 int getSectionIndex(QString name);
99 101
100 102 QString getSymbolName(int index);
101 103 QString getSymbolType(int index);
@@ -1,19 +1,26
1 1 #include "elffilewidget.h"
2 2 #include "ui_elffilewidget.h"
3 3 #include <QtWidgets/QTableWidgetItem>
4 #include "qhexedit.h"
5 #include "qtablewidgetintitem.h"
4 6
5 7 elfFileWidget::elfFileWidget(QWidget *parent) :
6 8 QWidget(parent),
7 9 ui(new Ui::elfFileWidget)
8 10 {
9 11 ui->setupUi(this);
12 connect(this->ui->sectionsList,SIGNAL(cellActivated(int,int)),this,SLOT(sectionCellActivated(int,int)));
10 13 }
11 14
15
16
12 17 elfFileWidget::~elfFileWidget()
13 18 {
14 19 delete ui;
15 20 }
16 21
22
23
17 24 void elfFileWidget::updateElfFile(ElfFile *file)
18 25 {
19 26 this->p_elf = file;
@@ -30,44 +37,91 void elfFileWidget::updateElfFile(ElfFil
30 37 this->ui->symbolCountLabel->setText(QString::number(p_elf->getSymbolCount()));
31 38 }
32 39 updateSymbols();
40 updateSections();
33 41 }
34 42
43
44
35 45 void elfFileWidget::updateSymbols()
36 46 {
37 47 this->ui->symbolsList->clear();
38 48 this->ui->symbolsList->setRowCount(p_elf->getSymbolCount());
39 this->ui->symbolsList->setHorizontalHeaderLabels(QStringList()<<"Value"<<"Size"<<"Type"<<"Link"<<"Section"<<"Name");
49 this->ui->symbolsList->setHorizontalHeaderLabels(QStringList()<<"Index"<<"Value"<<"Size"<<"Type"<<"Link"<<"Section"<<"Name");
40 50 for(int i=0;i<p_elf->getSymbolCount();i++)
41 51 {
42 QTableWidgetItem *newItem = new QTableWidgetItem(QString("0x%1").arg(p_elf->getSymbolAddress(i),8,16));
52 QTableWidgetItem *newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(i),DecimalItem);
43 53 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
44 54 this->ui->symbolsList->setItem(i, 0, newItem);
45 55
46 newItem = new QTableWidgetItem(QString("0x%1").arg(p_elf->getSymbolSize(i),8,16));
56 newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("0x%1").arg(p_elf->getSymbolAddress(i),8,16).replace(" ","0"),HexaDecimalItem);
47 57 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
48 58 this->ui->symbolsList->setItem(i, 1, newItem);
49 59
60 newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(p_elf->getSymbolSize(i)),DecimalItem);
61 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
62 this->ui->symbolsList->setItem(i, 2, newItem);
63
50 64 newItem = new QTableWidgetItem(p_elf->getSymbolType(i));
51 65 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
52 this->ui->symbolsList->setItem(i, 2, newItem);
66 this->ui->symbolsList->setItem(i, 3, newItem);
53 67
54 68 newItem = new QTableWidgetItem(p_elf->getSymbolLinkType(i));
55 69 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
56 this->ui->symbolsList->setItem(i, 3, newItem);
70 this->ui->symbolsList->setItem(i, 4, newItem);
57 71
58 72 newItem = new QTableWidgetItem(p_elf->getSymbolSectionName(i));
59 73 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
60 this->ui->symbolsList->setItem(i, 4, newItem);
74 this->ui->symbolsList->setItem(i, 5, newItem);
61 75
62 76 newItem = new QTableWidgetItem(p_elf->getSymbolName(i));
63 77 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
64 this->ui->symbolsList->setItem(i, 5, newItem);
78 this->ui->symbolsList->setItem(i, 6, newItem);
65 79 }
66 80 this->ui->symbolsList->resizeColumnsToContents();
67 81 }
68 82
69 83
70 84
85 void elfFileWidget::updateSections()
86 {
87 this->ui->sectionsList->clear();
88 this->ui->sectionsList->setRowCount(p_elf->getSectionCount());
89 this->ui->sectionsList->setHorizontalHeaderLabels(QStringList()<<"Index"<<"Name"<<"Address"<<"Size");
90 for(int i=0;i<p_elf->getSectionCount();i++)
91 {
92 QTableWidgetItem *newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("%1").arg(i),DecimalItem);
93 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
94 this->ui->sectionsList->setItem(i,0, newItem);
95
96 newItem = new QTableWidgetItem(p_elf->getSectionName(i));
97 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
98 this->ui->sectionsList->setItem(i, 1, newItem);
99
100 newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("0x%1").arg(p_elf->getSectionPaddr(i),8,16).replace(" ","0"),HexaDecimalItem);
101 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
102 this->ui->sectionsList->setItem(i, 2, newItem);
103
104 newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("%1").arg(p_elf->getSectionDatasz(i)),DecimalItem);
105 newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
106 this->ui->sectionsList->setItem(i, 3, newItem);
107 }
108 this->ui->sectionsList->resizeColumnsToContents();
109 }
110
111 void elfFileWidget::sectionCellActivated(int row, int column)
112 {
113 Q_UNUSED(column)
114 char* buff=NULL;
115 int sectionIndex = p_elf->getSectionIndex(this->ui->sectionsList->item(row,1)->text());
116 if(sectionIndex!=-1)
117 {
118 this->p_elf->getSectionData(sectionIndex,&buff);
119 this->ui->sectionsHexView->setData(QByteArray(buff,this->p_elf->getSectionDatasz(sectionIndex)));
120 }
121 }
122
123
124
71 125
72 126
73 127
@@ -19,6 +19,10 public:
19 19 public slots:
20 20 void updateElfFile(ElfFile* file);
21 21 void updateSymbols();
22 void updateSections();
23
24 private slots:
25 void sectionCellActivated(int row, int column);
22 26
23 27 private:
24 28 Ui::elfFileWidget *ui;
@@ -26,7 +26,7
26 26 <item row="0" column="0">
27 27 <widget class="QTabWidget" name="tabWidget">
28 28 <property name="currentIndex">
29 <number>1</number>
29 <number>2</number>
30 30 </property>
31 31 <widget class="QWidget" name="generalInfoTab">
32 32 <attribute name="title">
@@ -189,6 +189,17
189 189 <property name="sortingEnabled">
190 190 <bool>true</bool>
191 191 </property>
192 <attribute name="verticalHeaderVisible">
193 <bool>false</bool>
194 </attribute>
195 <attribute name="verticalHeaderShowSortIndicator" stdset="0">
196 <bool>false</bool>
197 </attribute>
198 <column>
199 <property name="text">
200 <string>Index</string>
201 </property>
202 </column>
192 203 <column>
193 204 <property name="text">
194 205 <string>Value</string>
@@ -239,7 +250,37
239 250 </widget>
240 251 </item>
241 252 <item row="0" column="1">
242 <widget class="QTableWidget" name="sectionsList"/>
253 <widget class="QTableWidget" name="sectionsList">
254 <property name="sortingEnabled">
255 <bool>true</bool>
256 </property>
257 <attribute name="verticalHeaderVisible">
258 <bool>false</bool>
259 </attribute>
260 <attribute name="verticalHeaderShowSortIndicator" stdset="0">
261 <bool>false</bool>
262 </attribute>
263 <column>
264 <property name="text">
265 <string>Index</string>
266 </property>
267 </column>
268 <column>
269 <property name="text">
270 <string>Name</string>
271 </property>
272 </column>
273 <column>
274 <property name="text">
275 <string>Address</string>
276 </property>
277 </column>
278 <column>
279 <property name="text">
280 <string>Size</string>
281 </property>
282 </column>
283 </widget>
243 284 </item>
244 285 </layout>
245 286 </widget>
@@ -210,6 +210,11 QList<codeFragment* > PythonQtWrapper_E
210 210 return ( theWrappedObject->getFragments(fragmentList));
211 211 }
212 212
213 int PythonQtWrapper_ElfFile::getSectionCount(ElfFile* theWrappedObject)
214 {
215 return ( theWrappedObject->getSectionCount());
216 }
217
213 218 bool PythonQtWrapper_ElfFile::getSectionData(ElfFile* theWrappedObject, int index, char** buffer)
214 219 {
215 220 return ( theWrappedObject->getSectionData(index, buffer));
@@ -220,6 +225,11 qint64 PythonQtWrapper_ElfFile::getSect
220 225 return ( theWrappedObject->getSectionDatasz(index));
221 226 }
222 227
228 int PythonQtWrapper_ElfFile::getSectionIndex(ElfFile* theWrappedObject, QString name)
229 {
230 return ( theWrappedObject->getSectionIndex(name));
231 }
232
223 233 qint64 PythonQtWrapper_ElfFile::getSectionMemsz(ElfFile* theWrappedObject, int index)
224 234 {
225 235 return ( theWrappedObject->getSectionMemsz(index));
@@ -240,9 +250,9 QString PythonQtWrapper_ElfFile::getSec
240 250 return ( theWrappedObject->getSectionType(index));
241 251 }
242 252
243 int PythonQtWrapper_ElfFile::getSectioncount(ElfFile* theWrappedObject)
244 {
245 return ( theWrappedObject->getSectionCount());
253 int PythonQtWrapper_ElfFile::getSegmentCount(ElfFile* theWrappedObject)
254 {
255 return ( theWrappedObject->getSegmentCount());
246 256 }
247 257
248 258 qint64 PythonQtWrapper_ElfFile::getSegmentFilesz(ElfFile* theWrappedObject, int index)
@@ -280,9 +290,44 qint64 PythonQtWrapper_ElfFile::getSegm
280 290 return ( theWrappedObject->getSegmentVaddr(index));
281 291 }
282 292
283 int PythonQtWrapper_ElfFile::getSegmentcount(ElfFile* theWrappedObject)
284 {
285 return ( theWrappedObject->getSegmentCount());
293 quint64 PythonQtWrapper_ElfFile::getSymbolAddress(ElfFile* theWrappedObject, int index)
294 {
295 return ( theWrappedObject->getSymbolAddress(index));
296 }
297
298 int PythonQtWrapper_ElfFile::getSymbolCount(ElfFile* theWrappedObject)
299 {
300 return ( theWrappedObject->getSymbolCount());
301 }
302
303 QString PythonQtWrapper_ElfFile::getSymbolLinkType(ElfFile* theWrappedObject, int index)
304 {
305 return ( theWrappedObject->getSymbolLinkType(index));
306 }
307
308 QString PythonQtWrapper_ElfFile::getSymbolName(ElfFile* theWrappedObject, int index)
309 {
310 return ( theWrappedObject->getSymbolName(index));
311 }
312
313 int PythonQtWrapper_ElfFile::getSymbolSectionIndex(ElfFile* theWrappedObject, int index)
314 {
315 return ( theWrappedObject->getSymbolSectionIndex(index));
316 }
317
318 QString PythonQtWrapper_ElfFile::getSymbolSectionName(ElfFile* theWrappedObject, int index)
319 {
320 return ( theWrappedObject->getSymbolSectionName(index));
321 }
322
323 quint64 PythonQtWrapper_ElfFile::getSymbolSize(ElfFile* theWrappedObject, int index)
324 {
325 return ( theWrappedObject->getSymbolSize(index));
326 }
327
328 QString PythonQtWrapper_ElfFile::getSymbolType(ElfFile* theWrappedObject, int index)
329 {
330 return ( theWrappedObject->getSymbolType(index));
286 331 }
287 332
288 333 QString PythonQtWrapper_ElfFile::getType(ElfFile* theWrappedObject)
@@ -92,13 +92,15 void delete_ElfFile(ElfFile* obj) { dele
92 92 qint64 getEntryPointAddress(ElfFile* theWrappedObject);
93 93 QList<codeFragment* > getFragments(ElfFile* theWrappedObject);
94 94 QList<codeFragment* > getFragments(ElfFile* theWrappedObject, QStringList fragmentList);
95 int getSectionCount(ElfFile* theWrappedObject);
95 96 bool getSectionData(ElfFile* theWrappedObject, int index, char** buffer);
96 97 qint64 getSectionDatasz(ElfFile* theWrappedObject, int index);
98 int getSectionIndex(ElfFile* theWrappedObject, QString name);
97 99 qint64 getSectionMemsz(ElfFile* theWrappedObject, int index);
98 100 QString getSectionName(ElfFile* theWrappedObject, int index);
99 101 qint64 getSectionPaddr(ElfFile* theWrappedObject, int index);
100 102 QString getSectionType(ElfFile* theWrappedObject, int index);
101 int getSectioncount(ElfFile* theWrappedObject);
103 int getSegmentCount(ElfFile* theWrappedObject);
102 104 qint64 getSegmentFilesz(ElfFile* theWrappedObject, int index);
103 105 QString getSegmentFlags(ElfFile* theWrappedObject, int index);
104 106 qint64 getSegmentMemsz(ElfFile* theWrappedObject, int index);
@@ -106,7 +108,14 void delete_ElfFile(ElfFile* obj) { dele
106 108 qint64 getSegmentPaddr(ElfFile* theWrappedObject, int index);
107 109 QString getSegmentType(ElfFile* theWrappedObject, int index);
108 110 qint64 getSegmentVaddr(ElfFile* theWrappedObject, int index);
109 int getSegmentcount(ElfFile* theWrappedObject);
111 quint64 getSymbolAddress(ElfFile* theWrappedObject, int index);
112 int getSymbolCount(ElfFile* theWrappedObject);
113 QString getSymbolLinkType(ElfFile* theWrappedObject, int index);
114 QString getSymbolName(ElfFile* theWrappedObject, int index);
115 int getSymbolSectionIndex(ElfFile* theWrappedObject, int index);
116 QString getSymbolSectionName(ElfFile* theWrappedObject, int index);
117 quint64 getSymbolSize(ElfFile* theWrappedObject, int index);
118 QString getSymbolType(ElfFile* theWrappedObject, int index);
110 119 QString getType(ElfFile* theWrappedObject);
111 120 qint64 getVersion(ElfFile* theWrappedObject);
112 121 bool static_ElfFile_isElf(const QString& File);
@@ -589,12 +598,12 public slots:
589 598 codeFragment* new_codeFragment();
590 599 codeFragment* new_codeFragment(char* data, unsigned int size, unsigned int address);
591 600 void delete_codeFragment(codeFragment* obj) { delete obj; }
601 void py_set_address(codeFragment* theWrappedObject, unsigned int address){ theWrappedObject->address = address; }
602 unsigned int py_get_address(codeFragment* theWrappedObject){ return theWrappedObject->address; }
603 void py_set_data(codeFragment* theWrappedObject, char* data){ theWrappedObject->data = data; }
604 char* py_get_data(codeFragment* theWrappedObject){ return theWrappedObject->data; }
592 605 void py_set_size(codeFragment* theWrappedObject, unsigned int size){ theWrappedObject->size = size; }
593 606 unsigned int py_get_size(codeFragment* theWrappedObject){ return theWrappedObject->size; }
594 void py_set_data(codeFragment* theWrappedObject, char* data){ theWrappedObject->data = data; }
595 char* py_get_data(codeFragment* theWrappedObject){ return theWrappedObject->data; }
596 void py_set_address(codeFragment* theWrappedObject, unsigned int address){ theWrappedObject->address = address; }
597 unsigned int py_get_address(codeFragment* theWrappedObject){ return theWrappedObject->address; }
598 607 };
599 608
600 609
General Comments 0
You need to be logged in to leave comments. Login now