diff --git a/src/common/common.pro b/src/common/common.pro --- a/src/common/common.pro +++ b/src/common/common.pro @@ -40,7 +40,8 @@ header.files = \ elf/elffile.h \ elf/elffilewidget.h \ qipdialogbox.h \ - lppserial/src/RS232.h + lppserial/src/RS232.h \ + qtablewidgetintitem.h win32{ elfheader.path = $$[QT_INSTALL_HEADERS]/SocExplorer/common/libelf @@ -85,7 +86,8 @@ HEADERS += \ qipdialogbox.h \ PySocExplorer.h \ SocExplorerPlot.h \ - elf/elffilewidget.h + elf/elffilewidget.h \ + qtablewidgetintitem.h SOURCES += \ @@ -104,7 +106,8 @@ SOURCES += \ elf/elffile.cpp \ qipdialogbox.cpp \ SocExplorerPlot.cpp \ - elf/elffilewidget.cpp + elf/elffilewidget.cpp \ + qtablewidgetintitem.cpp FORMS += \ elf/elffilewidget.ui 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 @@ -43,6 +43,28 @@ ElfFile::ElfFile(const QString &File) openFile(File); } +ElfFile::~ElfFile() +{ + closeFile(); + if(scn)free(scn); + if(data)free(data); + for(int i=0;isections.count();i++) + { + delete this->sections.at(i); + } + this->sections.clear(); + for(int i=0;iSegments.count();i++) + { + free(this->Segments.at(i)); + } + this->Segments.clear(); + for(int i=0;isymbols.at(i); + } + this->symbols.clear(); +} + bool ElfFile::openFile(const QString &File) { this->p_fileName = File; @@ -828,6 +850,19 @@ QString ElfFile::getSectionType(int inde return type; } +int ElfFile::getSectionIndex(QString name) +{ + if(this->e!=NULL) + { + for(int i=0;ie!=NULL) 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 @@ -64,6 +64,7 @@ class ElfFile : public abstractExecFile public: ElfFile(); ElfFile(const QString& File); + ~ElfFile(); bool openFile(const QString& File); bool isopened(); int closeFile(); @@ -96,6 +97,7 @@ public: qint64 getSectionMemsz(int index); QString getSectionName(int index); QString getSectionType(int index); + int getSectionIndex(QString name); QString getSymbolName(int index); QString getSymbolType(int index); 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,19 +1,26 @@ #include "elffilewidget.h" #include "ui_elffilewidget.h" #include +#include "qhexedit.h" +#include "qtablewidgetintitem.h" elfFileWidget::elfFileWidget(QWidget *parent) : QWidget(parent), ui(new Ui::elfFileWidget) { ui->setupUi(this); + connect(this->ui->sectionsList,SIGNAL(cellActivated(int,int)),this,SLOT(sectionCellActivated(int,int))); } + + elfFileWidget::~elfFileWidget() { delete ui; } + + void elfFileWidget::updateElfFile(ElfFile *file) { this->p_elf = file; @@ -30,44 +37,91 @@ void elfFileWidget::updateElfFile(ElfFil this->ui->symbolCountLabel->setText(QString::number(p_elf->getSymbolCount())); } updateSymbols(); + updateSections(); } + + 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"); + this->ui->symbolsList->setHorizontalHeaderLabels(QStringList()<<"Index"<<"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)); + QTableWidgetItem *newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(i),DecimalItem); 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 = (QTableWidgetItem*)new QTableWidgetIntItem(QString("0x%1").arg(p_elf->getSymbolAddress(i),8,16).replace(" ","0"),HexaDecimalItem); newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); this->ui->symbolsList->setItem(i, 1, newItem); + newItem = (QTableWidgetItem*)new QTableWidgetIntItem(QString("%1").arg(p_elf->getSymbolSize(i)),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->symbolsList->setItem(i, 2, newItem); + newItem = new QTableWidgetItem(p_elf->getSymbolType(i)); newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); - this->ui->symbolsList->setItem(i, 2, newItem); + this->ui->symbolsList->setItem(i, 3, newItem); newItem = new QTableWidgetItem(p_elf->getSymbolLinkType(i)); newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); - this->ui->symbolsList->setItem(i, 3, newItem); + this->ui->symbolsList->setItem(i, 4, newItem); newItem = new QTableWidgetItem(p_elf->getSymbolSectionName(i)); newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); - this->ui->symbolsList->setItem(i, 4, newItem); + this->ui->symbolsList->setItem(i, 5, newItem); newItem = new QTableWidgetItem(p_elf->getSymbolName(i)); newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); - this->ui->symbolsList->setItem(i, 5, newItem); + this->ui->symbolsList->setItem(i, 6, newItem); } this->ui->symbolsList->resizeColumnsToContents(); } +void elfFileWidget::updateSections() +{ + this->ui->sectionsList->clear(); + this->ui->sectionsList->setRowCount(p_elf->getSectionCount()); + this->ui->sectionsList->setHorizontalHeaderLabels(QStringList()<<"Index"<<"Name"<<"Address"<<"Size"); + for(int i=0;igetSectionCount();i++) + { + QTableWidgetItem *newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("%1").arg(i),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->sectionsList->setItem(i,0, newItem); + + newItem = new QTableWidgetItem(p_elf->getSectionName(i)); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->sectionsList->setItem(i, 1, newItem); + + newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("0x%1").arg(p_elf->getSectionPaddr(i),8,16).replace(" ","0"),HexaDecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->sectionsList->setItem(i, 2, newItem); + + newItem = (QTableWidgetItem*) new QTableWidgetIntItem(QString("%1").arg(p_elf->getSectionDatasz(i)),DecimalItem); + newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable); + this->ui->sectionsList->setItem(i, 3, newItem); + } + this->ui->sectionsList->resizeColumnsToContents(); +} + +void elfFileWidget::sectionCellActivated(int row, int column) +{ + Q_UNUSED(column) + char* buff=NULL; + int sectionIndex = p_elf->getSectionIndex(this->ui->sectionsList->item(row,1)->text()); + if(sectionIndex!=-1) + { + this->p_elf->getSectionData(sectionIndex,&buff); + this->ui->sectionsHexView->setData(QByteArray(buff,this->p_elf->getSectionDatasz(sectionIndex))); + } +} + + + 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 @@ -19,6 +19,10 @@ public: public slots: void updateElfFile(ElfFile* file); void updateSymbols(); + void updateSections(); + +private slots: + void sectionCellActivated(int row, int column); 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 @@ -26,7 +26,7 @@ - 1 + 2 @@ -189,6 +189,17 @@ true + + false + + + false + + + + Index + + Value @@ -239,7 +250,37 @@ - + + + true + + + false + + + false + + + + Index + + + + + Name + + + + + Address + + + + + Size + + + diff --git a/src/common/pythonQtOut/generated_cpp/PySocExplorer/PySocExplorer0.cpp b/src/common/pythonQtOut/generated_cpp/PySocExplorer/PySocExplorer0.cpp --- a/src/common/pythonQtOut/generated_cpp/PySocExplorer/PySocExplorer0.cpp +++ b/src/common/pythonQtOut/generated_cpp/PySocExplorer/PySocExplorer0.cpp @@ -210,6 +210,11 @@ QList PythonQtWrapper_E return ( theWrappedObject->getFragments(fragmentList)); } +int PythonQtWrapper_ElfFile::getSectionCount(ElfFile* theWrappedObject) +{ + return ( theWrappedObject->getSectionCount()); +} + bool PythonQtWrapper_ElfFile::getSectionData(ElfFile* theWrappedObject, int index, char** buffer) { return ( theWrappedObject->getSectionData(index, buffer)); @@ -220,6 +225,11 @@ qint64 PythonQtWrapper_ElfFile::getSect return ( theWrappedObject->getSectionDatasz(index)); } +int PythonQtWrapper_ElfFile::getSectionIndex(ElfFile* theWrappedObject, QString name) +{ + return ( theWrappedObject->getSectionIndex(name)); +} + qint64 PythonQtWrapper_ElfFile::getSectionMemsz(ElfFile* theWrappedObject, int index) { return ( theWrappedObject->getSectionMemsz(index)); @@ -240,9 +250,9 @@ QString PythonQtWrapper_ElfFile::getSec return ( theWrappedObject->getSectionType(index)); } -int PythonQtWrapper_ElfFile::getSectioncount(ElfFile* theWrappedObject) -{ - return ( theWrappedObject->getSectionCount()); +int PythonQtWrapper_ElfFile::getSegmentCount(ElfFile* theWrappedObject) +{ + return ( theWrappedObject->getSegmentCount()); } qint64 PythonQtWrapper_ElfFile::getSegmentFilesz(ElfFile* theWrappedObject, int index) @@ -280,9 +290,44 @@ qint64 PythonQtWrapper_ElfFile::getSegm return ( theWrappedObject->getSegmentVaddr(index)); } -int PythonQtWrapper_ElfFile::getSegmentcount(ElfFile* theWrappedObject) -{ - return ( theWrappedObject->getSegmentCount()); +quint64 PythonQtWrapper_ElfFile::getSymbolAddress(ElfFile* theWrappedObject, int index) +{ + return ( theWrappedObject->getSymbolAddress(index)); +} + +int PythonQtWrapper_ElfFile::getSymbolCount(ElfFile* theWrappedObject) +{ + return ( theWrappedObject->getSymbolCount()); +} + +QString PythonQtWrapper_ElfFile::getSymbolLinkType(ElfFile* theWrappedObject, int index) +{ + return ( theWrappedObject->getSymbolLinkType(index)); +} + +QString PythonQtWrapper_ElfFile::getSymbolName(ElfFile* theWrappedObject, int index) +{ + return ( theWrappedObject->getSymbolName(index)); +} + +int PythonQtWrapper_ElfFile::getSymbolSectionIndex(ElfFile* theWrappedObject, int index) +{ + return ( theWrappedObject->getSymbolSectionIndex(index)); +} + +QString PythonQtWrapper_ElfFile::getSymbolSectionName(ElfFile* theWrappedObject, int index) +{ + return ( theWrappedObject->getSymbolSectionName(index)); +} + +quint64 PythonQtWrapper_ElfFile::getSymbolSize(ElfFile* theWrappedObject, int index) +{ + return ( theWrappedObject->getSymbolSize(index)); +} + +QString PythonQtWrapper_ElfFile::getSymbolType(ElfFile* theWrappedObject, int index) +{ + return ( theWrappedObject->getSymbolType(index)); } QString PythonQtWrapper_ElfFile::getType(ElfFile* theWrappedObject) diff --git a/src/common/pythonQtOut/generated_cpp/PySocExplorer/PySocExplorer0.h b/src/common/pythonQtOut/generated_cpp/PySocExplorer/PySocExplorer0.h --- a/src/common/pythonQtOut/generated_cpp/PySocExplorer/PySocExplorer0.h +++ b/src/common/pythonQtOut/generated_cpp/PySocExplorer/PySocExplorer0.h @@ -92,13 +92,15 @@ void delete_ElfFile(ElfFile* obj) { dele qint64 getEntryPointAddress(ElfFile* theWrappedObject); QList getFragments(ElfFile* theWrappedObject); QList getFragments(ElfFile* theWrappedObject, QStringList fragmentList); + int getSectionCount(ElfFile* theWrappedObject); bool getSectionData(ElfFile* theWrappedObject, int index, char** buffer); qint64 getSectionDatasz(ElfFile* theWrappedObject, int index); + int getSectionIndex(ElfFile* theWrappedObject, QString name); qint64 getSectionMemsz(ElfFile* theWrappedObject, int index); QString getSectionName(ElfFile* theWrappedObject, int index); qint64 getSectionPaddr(ElfFile* theWrappedObject, int index); QString getSectionType(ElfFile* theWrappedObject, int index); - int getSectioncount(ElfFile* theWrappedObject); + int getSegmentCount(ElfFile* theWrappedObject); qint64 getSegmentFilesz(ElfFile* theWrappedObject, int index); QString getSegmentFlags(ElfFile* theWrappedObject, int index); qint64 getSegmentMemsz(ElfFile* theWrappedObject, int index); @@ -106,7 +108,14 @@ void delete_ElfFile(ElfFile* obj) { dele qint64 getSegmentPaddr(ElfFile* theWrappedObject, int index); QString getSegmentType(ElfFile* theWrappedObject, int index); qint64 getSegmentVaddr(ElfFile* theWrappedObject, int index); - int getSegmentcount(ElfFile* theWrappedObject); + quint64 getSymbolAddress(ElfFile* theWrappedObject, int index); + int getSymbolCount(ElfFile* theWrappedObject); + QString getSymbolLinkType(ElfFile* theWrappedObject, int index); + QString getSymbolName(ElfFile* theWrappedObject, int index); + int getSymbolSectionIndex(ElfFile* theWrappedObject, int index); + QString getSymbolSectionName(ElfFile* theWrappedObject, int index); + quint64 getSymbolSize(ElfFile* theWrappedObject, int index); + QString getSymbolType(ElfFile* theWrappedObject, int index); QString getType(ElfFile* theWrappedObject); qint64 getVersion(ElfFile* theWrappedObject); bool static_ElfFile_isElf(const QString& File); @@ -589,12 +598,12 @@ public slots: codeFragment* new_codeFragment(); codeFragment* new_codeFragment(char* data, unsigned int size, unsigned int address); void delete_codeFragment(codeFragment* obj) { delete obj; } +void py_set_address(codeFragment* theWrappedObject, unsigned int address){ theWrappedObject->address = address; } +unsigned int py_get_address(codeFragment* theWrappedObject){ return theWrappedObject->address; } +void py_set_data(codeFragment* theWrappedObject, char* data){ theWrappedObject->data = data; } +char* py_get_data(codeFragment* theWrappedObject){ return theWrappedObject->data; } void py_set_size(codeFragment* theWrappedObject, unsigned int size){ theWrappedObject->size = size; } unsigned int py_get_size(codeFragment* theWrappedObject){ return theWrappedObject->size; } -void py_set_data(codeFragment* theWrappedObject, char* data){ theWrappedObject->data = data; } -char* py_get_data(codeFragment* theWrappedObject){ return theWrappedObject->data; } -void py_set_address(codeFragment* theWrappedObject, unsigned int address){ theWrappedObject->address = address; } -unsigned int py_get_address(codeFragment* theWrappedObject){ return theWrappedObject->address; } }; diff --git a/src/common/qtablewidgetintitem.cpp b/src/common/qtablewidgetintitem.cpp new file mode 100644 --- /dev/null +++ b/src/common/qtablewidgetintitem.cpp @@ -0,0 +1,51 @@ +#include "qtablewidgetintitem.h" + +QTableWidgetIntItem::QTableWidgetIntItem(const QString &text,int Type) + :QTableWidgetItem(text,Type) +{ +} + +bool QTableWidgetIntItem::operator <(const QTableWidgetItem& other) const +{ + return toInt() < toInt(other); +} + +bool QTableWidgetIntItem::operator >(const QTableWidgetItem &other) const +{ + return toInt() > toInt(other); +} + +bool QTableWidgetIntItem::operator ==(const QTableWidgetItem &other) const +{ + return toInt() == toInt(other); +} + +int QTableWidgetIntItem::toInt() const +{ + bool ok=true; + if(type()==DecimalItem) + { + return text().toInt(); + } + else if(type()==HexaDecimalItem) + { + return text().replace("0x","").toInt(&ok,16); + } + return 0; +} + +int QTableWidgetIntItem::toInt(const QTableWidgetItem &item) const +{ + bool ok=true; + if(item.type()==DecimalItem) + { + return item.text().toInt(); + } + else if(item.type()==HexaDecimalItem) + { + return item.text().replace("0x","").toInt(&ok,16); + } + return 0; +} + + diff --git a/src/common/qtablewidgetintitem.h b/src/common/qtablewidgetintitem.h new file mode 100644 --- /dev/null +++ b/src/common/qtablewidgetintitem.h @@ -0,0 +1,22 @@ +#ifndef QTABLEWIDGETINTITEM_H +#define QTABLEWIDGETINTITEM_H + +#include + +#define DecimalItem 0 +#define HexaDecimalItem 1 + +class QTableWidgetIntItem : public QTableWidgetItem +{ + +public: + explicit QTableWidgetIntItem(const QString& text, int Type); + bool operator <(const QTableWidgetItem &other)const; + bool operator >(const QTableWidgetItem &other)const; + bool operator ==(const QTableWidgetItem &other)const; + int toInt() const; + int toInt(const QTableWidgetItem &item) const; + +}; + +#endif // QTABLEWIDGETINTITEM_H