##// END OF EJS Templates
ElfFile classes WIP.
jeandet -
r35:f6b4da9a999c default
parent child
Show More
@@ -0,0 +1,14
1 #include "elffilewidget.h"
2 #include "ui_elffilewidget.h"
3
4 elfFileWidget::elfFileWidget(QWidget *parent) :
5 QWidget(parent),
6 ui(new Ui::elfFileWidget)
7 {
8 ui->setupUi(this);
9 }
10
11 elfFileWidget::~elfFileWidget()
12 {
13 delete ui;
14 }
@@ -0,0 +1,22
1 #ifndef ELFFILEWIDGET_H
2 #define ELFFILEWIDGET_H
3
4 #include <QWidget>
5
6 namespace Ui {
7 class elfFileWidget;
8 }
9
10 class elfFileWidget : public QWidget
11 {
12 Q_OBJECT
13
14 public:
15 explicit elfFileWidget(QWidget *parent = 0);
16 ~elfFileWidget();
17
18 private:
19 Ui::elfFileWidget *ui;
20 };
21
22 #endif // ELFFILEWIDGET_H
@@ -0,0 +1,80
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>elfFileWidget</class>
4 <widget class="QWidget" name="elfFileWidget">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>622</width>
10 <height>398</height>
11 </rect>
12 </property>
13 <property name="minimumSize">
14 <size>
15 <width>0</width>
16 <height>0</height>
17 </size>
18 </property>
19 <property name="focusPolicy">
20 <enum>Qt::NoFocus</enum>
21 </property>
22 <property name="windowTitle">
23 <string>Form</string>
24 </property>
25 <layout class="QGridLayout" name="gridLayout">
26 <item row="0" column="0">
27 <widget class="QTabWidget" name="tabWidget">
28 <property name="currentIndex">
29 <number>0</number>
30 </property>
31 <widget class="QWidget" name="generalInfoTab">
32 <attribute name="title">
33 <string>General Informations</string>
34 </attribute>
35 </widget>
36 <widget class="QWidget" name="symbolsTab">
37 <attribute name="title">
38 <string>Symbols</string>
39 </attribute>
40 <layout class="QGridLayout" name="gridLayout_2">
41 <item row="0" column="0">
42 <widget class="QTableWidget" name="symbolsList"/>
43 </item>
44 </layout>
45 </widget>
46 <widget class="QWidget" name="sectionsTab">
47 <attribute name="title">
48 <string>Sections</string>
49 </attribute>
50 <layout class="QGridLayout" name="gridLayout_3">
51 <item row="0" column="0">
52 <widget class="QHexEdit" name="sectionsHexView" native="true">
53 <property name="minimumSize">
54 <size>
55 <width>100</width>
56 <height>0</height>
57 </size>
58 </property>
59 </widget>
60 </item>
61 <item row="0" column="1">
62 <widget class="QTableWidget" name="sectionsList"/>
63 </item>
64 </layout>
65 </widget>
66 </widget>
67 </item>
68 </layout>
69 </widget>
70 <customwidgets>
71 <customwidget>
72 <class>QHexEdit</class>
73 <extends>QWidget</extends>
74 <header location="global">qhexedit.h</header>
75 <container>1</container>
76 </customwidget>
77 </customwidgets>
78 <resources/>
79 <connections/>
80 </ui>
@@ -1,63 +1,38
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "abstractexecfile.h"
22 #include "abstractexecfile.h"
23
23
24 abstractExecFile::abstractExecFile(QObject *parent) :
24 abstractExecFile::abstractExecFile(QObject *parent) :
25 QObject(parent)
25 QObject(parent)
26 {
26 {
27 }
27 }
28
28
29 abstractExecFile::abstractExecFile(const QString &File, QObject *parent)
29 abstractExecFile::abstractExecFile(const QString &File, QObject *parent)
30 {
30 {
31
31
32 }
32 }
33
33
34 bool abstractExecFile::openFile(const QString &File)
35 {
36
37 }
38
39 bool abstractExecFile::isopened()
40 {
41
42 }
43
44 int abstractExecFile::setFilename(const QString &name)
45 {
46
47 }
48
49 int abstractExecFile::closeFile()
50 {
51
52 }
53
54 QList<codeFragment> abstractExecFile::getFragments()
55 {
56
57 }
58
59
34
60 codeFragment::codeFragment()
35 codeFragment::codeFragment()
61 {
36 {
62
37
63 }
38 }
@@ -1,53 +1,54
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef ABSTRACTEXECFILE_H
22 #ifndef ABSTRACTEXECFILE_H
23 #define ABSTRACTEXECFILE_H
23 #define ABSTRACTEXECFILE_H
24
24
25 #include <QObject>
25 #include <QObject>
26
26
27 class codeFragment
27 class codeFragment
28 {
28 {
29 public:
29 public:
30 codeFragment();
30 codeFragment();
31 char* data;
31 char* data;
32 quint32 size;
32 quint32 size;
33 quint32 address;
33 quint32 address;
34 };
34 };
35
35
36 class abstractExecFile : public QObject
36 class abstractExecFile : public QObject
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39 public:
39 public:
40 abstractExecFile(QObject *parent = 0);
40 abstractExecFile(QObject *parent = 0);
41 abstractExecFile(const QString& File,QObject *parent = 0);
41 abstractExecFile(const QString& File,QObject *parent = 0);
42 virtual bool openFile(const QString& File);
42 virtual bool openFile(const QString& File)=0;
43 virtual bool isopened();
43 virtual bool isopened()=0;
44 virtual int setFilename(const QString& name);
44 virtual int closeFile()=0;
45 virtual int closeFile();
45 virtual QList<codeFragment> getFragments()=0;
46 virtual QList<codeFragment> getFragments();
47 signals:
46 signals:
48
47
49 public slots:
48 public slots:
50
49
50 protected:
51 QString p_fileName;
51 };
52 };
52
53
53 #endif // ABSTRACTEXECFILE_H
54 #endif // ABSTRACTEXECFILE_H
@@ -1,108 +1,113
1 SOCEXPLORER_ROOT = \"$${PWD}/../..\"
1 SOCEXPLORER_ROOT = \"$${PWD}/../..\"
2 include($${PWD}/../../build_cfg/socexplorer.pri)
2 include($${PWD}/../../build_cfg/socexplorer.pri)
3 include($${PWD}/lppserial/lppserial.pri)
3 include($${PWD}/lppserial/lppserial.pri)
4
4
5 TEMPLATE = lib
5 TEMPLATE = lib
6 TARGET = socexplorercommon$${DEBUG_EXT}
6 TARGET = socexplorercommon$${DEBUG_EXT}
7
7
8 win32:CONFIG += dll
8 win32:CONFIG += dll
9 win32:CONFIG -= static
9 win32:CONFIG -= static
10
10
11 win32:INCLUDEPATH += $${PWD}/elf/libelfWin32/include
11 win32:INCLUDEPATH += $${PWD}/elf/libelfWin32/include
12 win32:INCLUDEPATH += $${PWD}/elf/libelfWin32/include/libelf
12 win32:INCLUDEPATH += $${PWD}/elf/libelfWin32/include/libelf
13 win32:DEFINES+=_ELF_WINDOWS_
13 win32:DEFINES+=_ELF_WINDOWS_
14 DEFINES+=RS232_debug
14 DEFINES+=RS232_debug
15
15
16 win32:LIBS += $${PWD}/elf/libelfWin32/bin/libelf.a
16 win32:LIBS += $${PWD}/elf/libelfWin32/bin/libelf.a
17 unix:LIBS += -lelf
17 unix:LIBS += -lelf
18
18
19 QMAKE_LFLAGS_RELEASE += --enable-auto-import
19 QMAKE_LFLAGS_RELEASE += --enable-auto-import
20 QMAKE_LFLAGS_DEBUG += --enable-auto-import
20 QMAKE_LFLAGS_DEBUG += --enable-auto-import
21
21
22 target.path = $$[QT_INSTALL_LIBS]
22 target.path = $$[QT_INSTALL_LIBS]
23 isEmpty(target.path) {
23 isEmpty(target.path) {
24 error(can\'t get QT_INSTALL_LIBS)
24 error(can\'t get QT_INSTALL_LIBS)
25 }
25 }
26
26
27 header.path = $$[QT_INSTALL_HEADERS]/SocExplorer/common
27 header.path = $$[QT_INSTALL_HEADERS]/SocExplorer/common
28 header.files = \
28 header.files = \
29 memsizewdgt.h \
29 memsizewdgt.h \
30 qhexspinbox.h \
30 qhexspinbox.h \
31 qsvgicon.h \
31 qsvgicon.h \
32 qhexedit/qhexedit_p.h \
32 qhexedit/qhexedit_p.h \
33 qhexedit/qhexedit.h \
33 qhexedit/qhexedit.h \
34 qhexedit/xbytearray.h \
34 qhexedit/xbytearray.h \
35 QCustomPlot/qcustomplot.h \
35 QCustomPlot/qcustomplot.h \
36 SocExplorerPlot.h \
36 SocExplorerPlot.h \
37 tcp_terminal_client.h \
37 tcp_terminal_client.h \
38 elf/elfinfowdgt.h \
38 elf/elfinfowdgt.h \
39 elf/elfparser.h \
39 elf/elfparser.h \
40 elf/elffile.h \
40 elf/elffile.h \
41 qipdialogbox.h \
41 qipdialogbox.h \
42 lppserial/src/RS232.h
42 lppserial/src/RS232.h
43
43
44 win32{
44 win32{
45 elfheader.path = $$[QT_INSTALL_HEADERS]/SocExplorer/common/libelf
45 elfheader.path = $$[QT_INSTALL_HEADERS]/SocExplorer/common/libelf
46 elfheader.files += \
46 elfheader.files += \
47 elf/libelfWin32/include/libelf/byteswap.h \
47 elf/libelfWin32/include/libelf/byteswap.h \
48 elf/libelfWin32/include/libelf/errors.h \
48 elf/libelfWin32/include/libelf/errors.h \
49 elf/libelfWin32/include/libelf/gelf.h \
49 elf/libelfWin32/include/libelf/gelf.h \
50 elf/libelfWin32/include/libelf/nlist.h \
50 elf/libelfWin32/include/libelf/nlist.h \
51 elf/libelfWin32/include/libelf/sys_elf.h \
51 elf/libelfWin32/include/libelf/sys_elf.h \
52 elf/libelfWin32/include/libelf/verneed.h \
52 elf/libelfWin32/include/libelf/verneed.h \
53 elf/libelfWin32/include/libelf/elf_repl.h \
53 elf/libelfWin32/include/libelf/elf_repl.h \
54 elf/libelfWin32/include/libelf/ext_types.h \
54 elf/libelfWin32/include/libelf/ext_types.h \
55 elf/libelfWin32/include/libelf/libelf.h \
55 elf/libelfWin32/include/libelf/libelf.h \
56 elf/libelfWin32/include/libelf/private.h \
56 elf/libelfWin32/include/libelf/private.h \
57 elf/libelfWin32/include/libelf/verdef.h
57 elf/libelfWin32/include/libelf/verdef.h
58 INSTALLS += elfheader
58 INSTALLS += elfheader
59 }
59 }
60
60
61
61
62 isEmpty(header.path) {
62 isEmpty(header.path) {
63 error(can\'t get QT_INSTALL_HEADERS)
63 error(can\'t get QT_INSTALL_HEADERS)
64 }
64 }
65
65
66 INSTALLS += target header
66 INSTALLS += target header
67
67
68 INCLUDEPATH += QCustomPlot qhexedit
68 INCLUDEPATH += QCustomPlot qhexedit
69
69
70 HEADERS += \
70 HEADERS += \
71 memsizewdgt.h \
71 memsizewdgt.h \
72 qhexspinbox.h \
72 qhexspinbox.h \
73 qsvgicon.h \
73 qsvgicon.h \
74 qhexedit/qhexedit_p.h \
74 qhexedit/qhexedit_p.h \
75 qhexedit/qhexedit.h \
75 qhexedit/qhexedit.h \
76 qhexedit/xbytearray.h \
76 qhexedit/xbytearray.h \
77 qhexedit/commands.h \
77 qhexedit/commands.h \
78 QCustomPlot/qcustomplot.h \
78 QCustomPlot/qcustomplot.h \
79 tcp_terminal_client.h \
79 tcp_terminal_client.h \
80 elf/elfinfowdgt.h \
80 elf/elfinfowdgt.h \
81 elf/elfparser.h \
81 elf/elfparser.h \
82 abstractexecfile.h \
82 abstractexecfile.h \
83 elf/elffile.h \
83 elf/elffile.h \
84 qipdialogbox.h \
84 qipdialogbox.h \
85 PySocExplorer.h \
85 PySocExplorer.h \
86 SocExplorerPlot.h
86 SocExplorerPlot.h \
87 elf/elffilewidget.h
87
88
88
89
89 SOURCES += \
90 SOURCES += \
90 memsizewdgt.cpp \
91 memsizewdgt.cpp \
91 qhexspinbox.cpp \
92 qhexspinbox.cpp \
92 qsvgicon.cpp \
93 qsvgicon.cpp \
93 qhexedit/qhexedit_p.cpp \
94 qhexedit/qhexedit_p.cpp \
94 qhexedit/qhexedit.cpp \
95 qhexedit/qhexedit.cpp \
95 qhexedit/xbytearray.cpp \
96 qhexedit/xbytearray.cpp \
96 qhexedit/commands.cpp \
97 qhexedit/commands.cpp \
97 QCustomPlot/qcustomplot.cpp \
98 QCustomPlot/qcustomplot.cpp \
98 tcp_terminal_client.cpp \
99 tcp_terminal_client.cpp \
99 elf/elfinfowdgt.cpp \
100 elf/elfinfowdgt.cpp \
100 elf/elfparser.cpp \
101 elf/elfparser.cpp \
101 abstractexecfile.cpp \
102 abstractexecfile.cpp \
102 elf/elffile.cpp \
103 elf/elffile.cpp \
103 qipdialogbox.cpp \
104 qipdialogbox.cpp \
104 SocExplorerPlot.cpp
105 SocExplorerPlot.cpp \
106 elf/elffilewidget.cpp
107
108 FORMS += \
109 elf/elffilewidget.ui
105
110
106
111
107
112
108
113
@@ -1,32 +1,104
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author :
20 -- Mail : alexis.jeandet@member.fsf.org
20 Alexis Jeandet
21 -- Mail :
22 alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
23 ----------------------------------------------------------------------------*/
22 #include "elffile.h"
24 #include "elffile.h"
23
25
24 ElfFile::ElfFile(QObject *parent) :
26 ElfFile::ElfFile(QObject *parent) :
25 abstractExecFile(parent)
27 abstractExecFile(parent)
26 {
28 {
27 }
29 }
28
30
29 ElfFile::ElfFile(const QString &File, QObject *parent)
31 ElfFile::ElfFile(const QString &File, QObject *parent)
32 :abstractExecFile(parent)
30 {
33 {
34 this->p_fileName = File;
35 parser.setFilename(File);
36 }
37
38 bool ElfFile::openFile(const QString &File)
39 {
40 this->p_fileName = File;
41 parser.setFilename(File);
42 }
43
44 bool ElfFile::isopened()
45 {
46 return parser.isopened();
47 }
48
49 int ElfFile::closeFile()
50 {
51 return parser.closeFile();
52 }
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
64 QList<codeFragment> ElfFile::getFragments(QStringList fragmentList)
65 {
66 QList<codeFragment> fragments;
67 if (parser.isopened())
68 {
69 for(int i =0;i<fragmentList.count();i++)
70 {
71 fragments.append(getFragment(fragmentList.at(i)));
72 }
73 }
74 }
75
76 codeFragment ElfFile::getFragment(const QString &name)
77 {
78 codeFragment fragment;
79 for(int i=0;i<parser.getSectioncount();i++)
80 {
81 if(parser.getSectionName(i) == name)
82 {
83 fragment.data =NULL;
84 fragment.size = parser.getSectionDatasz(i);
85 fragment.address = parser.getSectionPaddr(i);
86 parser.getSectionData(i,&fragment.data);
87 }
88 }
31
89
32 }
90 }
91
92
93
94
95
96
97
98
99
100
101
102
103
104
@@ -1,40 +1,50
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include <abstractexecfile.h>
22 #include <abstractexecfile.h>
23 #include <elf.h>
23 #include <elf.h>
24 #include "elfparser.h"
25 #include <QStringList>
26
24 #ifndef ELFFILE_H
27 #ifndef ELFFILE_H
25 #define ELFFILE_H
28 #define ELFFILE_H
26
29
27 class ElfFile : public abstractExecFile
30 class ElfFile : public abstractExecFile
28 {
31 {
29 Q_OBJECT
32 Q_OBJECT
30 public:
33 public:
31 ElfFile(QObject *parent = 0);
34 ElfFile(QObject *parent = 0);
32 ElfFile(const QString& File,QObject *parent = 0);
35 ElfFile(const QString& File,QObject *parent = 0);
33
36 bool openFile(const QString& File);
37 bool isopened();
38 int closeFile();
39 QList<codeFragment> getFragments();
40 QList<codeFragment> getFragments(QStringList fragmentList);
34 signals:
41 signals:
35
42
36 public slots:
43 public slots:
44 private:
45 elfparser parser;
46 codeFragment getFragment(const QString& name);
37
47
38 };
48 };
39
49
40 #endif // ELFFILE_H
50 #endif // ELFFILE_H
@@ -1,701 +1,716
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "elfparser.h"
22 #include "elfparser.h"
23 #include <sys/types.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
25 #include <fcntl.h>
26 #include <unistd.h>
26 #include <unistd.h>
27
27
28 void elfresolveMachine(Elf64_Half e_machine,char* MachineName)
28 QString elfresolveMachine(Elf64_Half e_machine)
29 {
29 {
30
30 QString machineName;
31 //Update from with bash script don't write it by yourself!
31 //Update from with bash script don't write it by yourself!
32 switch(e_machine)
32 switch(e_machine)
33 {
33 {
34 case EM_NONE :
34 case EM_NONE:
35 strcpy(MachineName,"No machine");
35 machineName = " No machine ";
36 break;
36 break;
37 case EM_M32 :
37 case EM_M32:
38 strcpy(MachineName,"AT&T WE 32100");
38 machineName = " AT&T WE 32100 ";
39 break;
39 break;
40 case EM_SPARC :
40 case EM_SPARC:
41 strcpy(MachineName,"SUN SPARC");
41 machineName = " SUN SPARC ";
42 break;
42 break;
43 case EM_386 :
43 case EM_386:
44 strcpy(MachineName,"Intel 80386");
44 machineName = " Intel 80386 ";
45 break;
45 break;
46 case EM_68K :
46 case EM_68K:
47 strcpy(MachineName,"Motorola m68k family");
47 machineName = " Motorola m68k family ";
48 break;
48 break;
49 case EM_88K :
49 case EM_88K:
50 strcpy(MachineName,"Motorola m88k family");
50 machineName = " Motorola m88k family ";
51 break;
51 break;
52 case EM_860 :
52 case EM_860:
53 strcpy(MachineName,"Intel 80860");
53 machineName = " Intel 80860 ";
54 break;
54 break;
55 case EM_MIPS :
55 case EM_MIPS:
56 strcpy(MachineName,"MIPS R3000 big-endian");
56 machineName = " MIPS R3000 big-endian ";
57 break;
57 break;
58 case EM_S370 :
58 case EM_S370:
59 strcpy(MachineName,"IBM System\/370");
59 machineName = " IBM System/370 ";
60 break;
60 break;
61 case EM_MIPS_RS3_LE :
61 case EM_MIPS_RS3_LE:
62 strcpy(MachineName,"MIPS R3000 little-endian");
62 machineName = " MIPS R3000 little-endian ";
63 break;
63 break;
64 case EM_PARISC :
64 case EM_PARISC:
65 strcpy(MachineName,"HPPA");
65 machineName = " HPPA ";
66 break;
66 break;
67 case EM_VPP500 :
67 case EM_VPP500:
68 strcpy(MachineName,"Fujitsu VPP500");
68 machineName = " Fujitsu VPP500 ";
69 break;
69 break;
70 case EM_SPARC32PLUS :
70 case EM_SPARC32PLUS:
71 strcpy(MachineName,"Sun's \"v8plus\"");
71 machineName = " Sun's \"v8plus\" ";
72 break;
73 case EM_960:
74 machineName = " Intel 80960 ";
72 break;
75 break;
73 case EM_960 :
76 case EM_PPC:
74 strcpy(MachineName,"Intel 80960");
77 machineName = " PowerPC ";
75 break;
78 break;
76 case EM_PPC :
79 case EM_PPC64:
77 strcpy(MachineName,"PowerPC");
80 machineName = " PowerPC 64-bit ";
78 break;
81 break;
79 case EM_PPC64 :
82 case EM_S390:
80 strcpy(MachineName,"PowerPC 64-bit");
83 machineName = " IBM S390 ";
81 break;
84 break;
82 case EM_S390 :
85 case EM_V800:
83 strcpy(MachineName,"IBM S390");
86 machineName = " NEC V800 series ";
84 break;
87 break;
85 case EM_V800 :
88 case EM_FR20:
86 strcpy(MachineName,"NEC V800 series");
89 machineName = " Fujitsu FR20 ";
87 break;
90 break;
88 case EM_FR20 :
91 case EM_RH32:
89 strcpy(MachineName,"Fujitsu FR20");
92 machineName = " TRW RH-32 ";
90 break;
93 break;
91 case EM_RH32 :
94 case EM_RCE:
92 strcpy(MachineName,"TRW RH-32");
95 machineName = " Motorola RCE ";
93 break;
96 break;
94 case EM_RCE :
97 case EM_ARM:
95 strcpy(MachineName,"Motorola RCE");
98 machineName = " ARM ";
96 break;
99 break;
97 case EM_ARM :
100 case EM_FAKE_ALPHA:
98 strcpy(MachineName,"ARM");
101 machineName = " Digital Alpha ";
102 break;
103 case EM_SH:
104 machineName = " Hitachi SH ";
99 break;
105 break;
100 case EM_SH :
106 case EM_SPARCV9:
101 strcpy(MachineName,"Hitachi SH");
107 machineName = " SPARC v9 64-bit ";
102 break;
108 break;
103 case EM_SPARCV9 :
109 case EM_TRICORE:
104 strcpy(MachineName,"SPARC v9 64-bit");
110 machineName = " Siemens Tricore ";
105 break;
111 break;
106 case EM_TRICORE :
112 case EM_ARC:
107 strcpy(MachineName,"Siemens Tricore");
113 machineName = " Argonaut RISC Core ";
108 break;
114 break;
109 case EM_ARC :
115 case EM_H8_300:
110 strcpy(MachineName,"Argonaut RISC Core");
116 machineName = " Hitachi H8/300 ";
111 break;
117 break;
112 case EM_H8_300 :
118 case EM_H8_300H:
113 strcpy(MachineName,"Hitachi H8\/300");
119 machineName = " Hitachi H8/300H ";
114 break;
120 break;
115 case EM_H8_300H :
121 case EM_H8S:
116 strcpy(MachineName,"Hitachi H8\/300H");
122 machineName = " Hitachi H8S ";
117 break;
123 break;
118 case EM_H8S :
124 case EM_H8_500:
119 strcpy(MachineName,"Hitachi H8S");
125 machineName = " Hitachi H8/500 ";
120 break;
126 break;
121 case EM_H8_500 :
127 case EM_IA_64:
122 strcpy(MachineName,"Hitachi H8\/500");
128 machineName = " Intel Merced ";
123 break;
129 break;
124 case EM_IA_64 :
130 case EM_MIPS_X:
125 strcpy(MachineName,"Intel Merced");
131 machineName = " Stanford MIPS-X ";
132 break;
133 case EM_COLDFIRE:
134 machineName = " Motorola Coldfire ";
126 break;
135 break;
127 case EM_MIPS_X :
136 case EM_68HC12:
128 strcpy(MachineName,"Stanford MIPS-X");
137 machineName = " Motorola M68HC12 ";
129 break;
138 break;
130 case EM_COLDFIRE :
139 case EM_MMA:
131 strcpy(MachineName,"Motorola Coldfire");
140 machineName = " Fujitsu MMA Multimedia Accelerator";
132 break;
141 break;
133 case EM_68HC12 :
142 case EM_PCP:
134 strcpy(MachineName,"Motorola M68HC12");
143 machineName = " Siemens PCP ";
135 break;
144 break;
136 case EM_MMA :
145 case EM_NCPU:
137 strcpy(MachineName,"Fujitsu MMA Multimedia Accelerator");
146 machineName = " Sony nCPU embeeded RISC ";
138 break;
147 break;
139 case EM_PCP :
148 case EM_NDR1:
140 strcpy(MachineName,"Siemens PCP");
149 machineName = " Denso NDR1 microprocessor ";
141 break;
150 break;
142 case EM_NCPU :
151 case EM_STARCORE:
143 strcpy(MachineName,"Sony nCPU embeeded RISC");
152 machineName = " Motorola Start*Core processor ";
144 break;
153 break;
145 case EM_NDR1 :
154 case EM_ME16:
146 strcpy(MachineName,"Denso NDR1 microprocessor");
155 machineName = " Toyota ME16 processor ";
147 break;
156 break;
148 case EM_STARCORE :
157 case EM_ST100:
149 strcpy(MachineName,"Motorola Start*Core processor");
158 machineName = " STMicroelectronic ST100 processor ";
150 break;
159 break;
151 case EM_ME16 :
160 case EM_TINYJ:
152 strcpy(MachineName,"Toyota ME16 processor");
161 machineName = " Advanced Logic Corp. Tinyj emb.fam";
162 break;
163 case EM_X86_64:
164 machineName = " AMD x86-64 architecture ";
153 break;
165 break;
154 case EM_ST100 :
166 case EM_PDSP:
155 strcpy(MachineName,"STMicroelectronic ST100 processor");
167 machineName = " Sony DSP Processor ";
156 break;
168 break;
157 case EM_TINYJ :
169 case EM_FX66:
158 strcpy(MachineName,"Advanced Logic Corp. Tinyj emb.fam");
170 machineName = " Siemens FX66 microcontroller ";
159 break;
171 break;
160 case EM_X86_64 :
172 case EM_ST9PLUS:
161 strcpy(MachineName,"AMD x86-64 architecture");
173 machineName = " STMicroelectronics ST9+ 8/16 mc ";
162 break;
174 break;
163 case EM_PDSP :
175 case EM_ST7:
164 strcpy(MachineName,"Sony DSP Processor");
176 machineName = " STmicroelectronics ST7 8 bit mc ";
165 break;
177 break;
166 case EM_FX66 :
178 case EM_68HC16:
167 strcpy(MachineName,"Siemens FX66 microcontroller");
179 machineName = " Motorola MC68HC16 microcontroller ";
168 break;
180 break;
169 case EM_ST9PLUS :
181 case EM_68HC11:
170 strcpy(MachineName,"STMicroelectronics ST9+ 8\/16 mc");
182 machineName = " Motorola MC68HC11 microcontroller ";
171 break;
183 break;
172 case EM_ST7 :
184 case EM_68HC08:
173 strcpy(MachineName,"STmicroelectronics ST7 8 bit mc");
185 machineName = " Motorola MC68HC08 microcontroller ";
174 break;
186 break;
175 case EM_68HC16 :
187 case EM_68HC05:
176 strcpy(MachineName,"Motorola MC68HC16 microcontroller");
188 machineName = " Motorola MC68HC05 microcontroller ";
177 break;
189 break;
178 case EM_68HC11 :
190 case EM_SVX:
179 strcpy(MachineName,"Motorola MC68HC11 microcontroller");
191 machineName = " Silicon Graphics SVx ";
192 break;
193 case EM_ST19:
194 machineName = " STMicroelectronics ST19 8 bit mc ";
180 break;
195 break;
181 case EM_68HC08 :
196 case EM_VAX:
182 strcpy(MachineName,"Motorola MC68HC08 microcontroller");
197 machineName = " Digital VAX ";
183 break;
198 break;
184 case EM_68HC05 :
199 case EM_CRIS:
185 strcpy(MachineName,"Motorola MC68HC05 microcontroller");
200 machineName = " Axis Communications 32-bit embedded processor ";
186 break;
201 break;
187 case EM_SVX :
202 case EM_JAVELIN:
188 strcpy(MachineName,"Silicon Graphics SVx");
203 machineName = " Infineon Technologies 32-bit embedded processor ";
189 break;
204 break;
190 case EM_ST19 :
205 case EM_FIREPATH:
191 strcpy(MachineName,"STMicroelectronics ST19 8 bit mc");
206 machineName = " Element 14 64-bit DSP Processor ";
192 break;
207 break;
193 case EM_VAX :
208 case EM_ZSP:
194 strcpy(MachineName,"Digital VAX");
209 machineName = " LSI Logic 16-bit DSP Processor ";
195 break;
210 break;
196 case EM_CRIS :
211 case EM_MMIX:
197 strcpy(MachineName,"Axis Communications 32-bit embedded processor");
212 machineName = " Donald Knuth's educational 64-bit processor ";
198 break;
213 break;
199 case EM_JAVELIN :
214 case EM_HUANY:
200 strcpy(MachineName,"Infineon Technologies 32-bit embedded processor");
215 machineName = " Harvard University machine-independent object files ";
201 break;
216 break;
202 case EM_FIREPATH :
217 case EM_PRISM:
203 strcpy(MachineName,"Element 14 64-bit DSP Processor");
218 machineName = " SiTera Prism ";
204 break;
219 break;
205 case EM_ZSP :
220 case EM_AVR:
206 strcpy(MachineName,"LSI Logic 16-bit DSP Processor");
221 machineName = " Atmel AVR 8-bit microcontroller ";
222 break;
223 case EM_FR30:
224 machineName = " Fujitsu FR30 ";
207 break;
225 break;
208 case EM_MMIX :
226 case EM_D10V:
209 strcpy(MachineName,"Donald Knuth's educational 64-bit processor");
227 machineName = " Mitsubishi D10V ";
210 break;
228 break;
211 case EM_HUANY :
229 case EM_D30V:
212 strcpy(MachineName,"Harvard University machine-independent object files");
230 machineName = " Mitsubishi D30V ";
213 break;
231 break;
214 case EM_PRISM :
232 case EM_V850:
215 strcpy(MachineName,"SiTera Prism");
233 machineName = " NEC v850 ";
216 break;
234 break;
217 case EM_AVR :
235 case EM_M32R:
218 strcpy(MachineName,"Atmel AVR 8-bit microcontroller");
236 machineName = " Mitsubishi M32R ";
219 break;
237 break;
220 case EM_FR30 :
238 case EM_MN10300:
221 strcpy(MachineName,"Fujitsu FR30");
239 machineName = " Matsushita MN10300 ";
222 break;
240 break;
223 case EM_D10V :
241 case EM_MN10200:
224 strcpy(MachineName,"Mitsubishi D10V");
242 machineName = " Matsushita MN10200 ";
225 break;
243 break;
226 case EM_D30V :
244 case EM_PJ:
227 strcpy(MachineName,"Mitsubishi D30V");
245 machineName = " picoJava ";
228 break;
246 break;
229 case EM_V850 :
247 case EM_OPENRISC:
230 strcpy(MachineName,"NEC v850");
248 machineName = " OpenRISC 32-bit embedded processor ";
231 break;
249 break;
232 case EM_M32R :
250 case EM_ARC_A5:
233 strcpy(MachineName,"Mitsubishi M32R");
251 machineName = " ARC Cores Tangent-A5 ";
234 break;
252 break;
235 case EM_MN10300 :
253 case EM_XTENSA:
236 strcpy(MachineName,"Matsushita MN10300");
254 machineName = " Tensilica Xtensa Architecture ";
237 break;
255 break;
238 case EM_MN10200 :
256 case EM_AARCH64:
239 strcpy(MachineName,"Matsushita MN10200");
257 machineName = " ARM AARCH64 ";
240 break;
258 break;
241 case EM_PJ :
259 case EM_TILEPRO:
242 strcpy(MachineName,"picoJava");
260 machineName = " Tilera TILEPro ";
243 break;
261 break;
244 case EM_OPENRISC :
262 case EM_MICROBLAZE:
245 strcpy(MachineName,"OpenRISC 32-bit embedded processor");
263 machineName = " Xilinx MicroBlaze ";
246 break;
264 break;
247 case EM_ARC_A5 :
265 case EM_TILEGX:
248 strcpy(MachineName,"ARC Cores Tangent-A5");
266 machineName = " Tilera TILE-Gx ";
249 break;
267 break;
250 case EM_XTENSA :
268 case EM_NUM:
251 strcpy(MachineName,"Tensilica Xtensa Architecture");
269 machineName = "";
252 break;
270 break;
253 default:
271 default:
254 strcpy(MachineName,"Unknow Machine");
272 machineName ="Unknow Machine";
255 break;
273 break;
256 }
274 }
257
275 return machineName;
258 }
276 }
259
277
260
278
261 elfparser::elfparser()
279 elfparser::elfparser()
262 {
280 {
263 this->opened = false;
281 this->opened = false;
264 this->type_elf = false;
282 this->type_elf = false;
265 this->elfFile = NULL;
283 this->elfFile = NULL;
266 this->e = NULL;
284 this->e = NULL;
267 }
285 }
268
286
269
287
270 int elfparser::setFilename(const QString &name)
288 int elfparser::setFilename(const QString &name)
271 {
289 {
272 this->closeFile();
290 this->closeFile();
273 if(elf_version(EV_CURRENT)==EV_NONE)return 0;
291 if(elf_version(EV_CURRENT)==EV_NONE)return 0;
274 #ifdef _ELF_WINDOWS_
292 #ifdef _ELF_WINDOWS_
275 this->elfFile = open(name.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
293 this->elfFile = open(name.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
276 #else
294 #else
277 this->elfFile = open(name.toStdString().c_str(),O_RDONLY ,0);
295 this->elfFile = open(name.toStdString().c_str(),O_RDONLY ,0);
278 #endif
296 #endif
279 if(this->elfFile==NULL)return 0;
297 if(this->elfFile==NULL)return 0;
280 this->e = elf_begin(this->elfFile,ELF_C_READ,NULL);
298 this->e = elf_begin(this->elfFile,ELF_C_READ,NULL);
281 if(this->e==NULL)return 0;
299 if(this->e==NULL)return 0;
282 this->ek = elf_kind(this->e);
300 this->ek = elf_kind(this->e);
283 gelf_getehdr (this->e, &this->ehdr );
301 gelf_getehdr (this->e, &this->ehdr );
284 elf_getshdrstrndx (this->e, &this->shstrndx);
302 elf_getshdrstrndx (this->e, &this->shstrndx);
285 this->updateSegments();
303 this->updateSegments();
286 this->updateSections();
304 this->updateSections();
287 return 1;
305 return 1;
288 }
306 }
289
307
290
308
291 int elfparser::closeFile()
309 int elfparser::closeFile()
292 {
310 {
293 if(this->elfFile!=NULL)
311 if(this->elfFile!=NULL)
294 {
312 {
295 if(this->e!=NULL)
313 if(this->e!=NULL)
296 {
314 {
297 elf_end(this->e);
315 elf_end(this->e);
298 this->e = NULL;
316 this->e = NULL;
299 }
317 }
300 close(this->elfFile);
318 close(this->elfFile);
301 this->elfFile = NULL;
319 this->elfFile = NULL;
302 }
320 }
303 return 0;
321 return 0;
304 }
322 }
305
323
306
324
307 bool elfparser::isopened()
325 bool elfparser::isopened()
308 {
326 {
309 return this->opened;
327 return this->opened;
310 }
328 }
311
329
312
330
313 bool elfparser::iself()
331 bool elfparser::iself()
314 {
332 {
315 return this->type_elf;
333 return this->type_elf;
316 }
334 }
317
335
318
336
319 QString elfparser::getArchitecture()
337 QString elfparser::getArchitecture()
320 {
338 {
321 QString arch("");
322 char archName[256]="";
323 if(this->e!=NULL)
339 if(this->e!=NULL)
324 {
340 {
325 elfresolveMachine(this->ehdr.e_machine,archName);
341 return elfresolveMachine(this->ehdr.e_machine);
326 arch = archName;
327 }
342 }
328 return arch;
343 return "";
329 }
344 }
330
345
331
346
332 QString elfparser::getType()
347 QString elfparser::getType()
333 {
348 {
334 QString kind("");
349 QString kind("");
335 if(this->e!=NULL)
350 if(this->e!=NULL)
336 {
351 {
337 switch(this->ek)
352 switch(this->ek)
338 {
353 {
339 case ELF_K_AR:
354 case ELF_K_AR:
340 kind = "Archive";
355 kind = "Archive";
341 break;
356 break;
342 case ELF_K_ELF:
357 case ELF_K_ELF:
343 kind = "Elf";
358 kind = "Elf";
344 break;
359 break;
345 case ELF_K_COFF:
360 case ELF_K_COFF:
346 kind = "COFF";
361 kind = "COFF";
347 break;
362 break;
348 case ELF_K_NUM:
363 case ELF_K_NUM:
349 kind = "NUM";
364 kind = "NUM";
350 break;
365 break;
351 case ELF_K_NONE:
366 case ELF_K_NONE:
352 kind = "Data";
367 kind = "Data";
353 break;
368 break;
354 default:
369 default:
355 kind = "Unknow";
370 kind = "Unknow";
356 break;
371 break;
357 }
372 }
358 }
373 }
359 return kind;
374 return kind;
360 }
375 }
361
376
362
377
363 int32_t elfparser::getVersion()
378 int32_t elfparser::getVersion()
364 {
379 {
365 if(this->e!=NULL)
380 if(this->e!=NULL)
366 {
381 {
367 return this->ehdr.e_version;
382 return this->ehdr.e_version;
368 }
383 }
369 }
384 }
370
385
371
386
372 int elfparser::getSectioncount()
387 int elfparser::getSectioncount()
373 {
388 {
374 return (int)this->SectionCount;
389 return (int)this->SectionCount;
375 }
390 }
376
391
377
392
378 int elfparser::getSegmentcount()
393 int elfparser::getSegmentcount()
379 {
394 {
380 return (int)this->SegmentCount;
395 return (int)this->SegmentCount;
381 }
396 }
382
397
383
398
384 QString elfparser::getSegmentType(int index)
399 QString elfparser::getSegmentType(int index)
385 {
400 {
386 QString type("");
401 QString type("");
387 if(this->e!=NULL)
402 if(this->e!=NULL)
388 {
403 {
389 if(index < this->Segments.count())
404 if(index < this->Segments.count())
390 {
405 {
391 switch(this->Segments.at(index)->p_type)
406 switch(this->Segments.at(index)->p_type)
392 {
407 {
393 case PT_NULL:
408 case PT_NULL:
394 type = "Program header table entry unused";
409 type = "Program header table entry unused";
395 break;
410 break;
396 case PT_LOAD:
411 case PT_LOAD:
397 type = "Loadable program segment";
412 type = "Loadable program segment";
398 break;
413 break;
399 case PT_DYNAMIC :
414 case PT_DYNAMIC :
400 type = "Dynamic linking information";
415 type = "Dynamic linking information";
401 break;
416 break;
402 case PT_INTERP:
417 case PT_INTERP:
403 type ="Program interpreter";
418 type ="Program interpreter";
404 break;
419 break;
405 case PT_NOTE:
420 case PT_NOTE:
406 type = "Auxiliary information";
421 type = "Auxiliary information";
407 break;
422 break;
408 case PT_SHLIB:
423 case PT_SHLIB:
409 type = "Reserved";
424 type = "Reserved";
410 break;
425 break;
411 case PT_PHDR:
426 case PT_PHDR:
412 type = "Entry for header table itself";
427 type = "Entry for header table itself";
413 break;
428 break;
414 case PT_TLS:
429 case PT_TLS:
415 type = "Thread-local storage segment";
430 type = "Thread-local storage segment";
416 break;
431 break;
417 case PT_NUM:
432 case PT_NUM:
418 type = "Number of defined types";
433 type = "Number of defined types";
419 break;
434 break;
420 case PT_LOOS:
435 case PT_LOOS:
421 type = "Start of OS-specific";
436 type = "Start of OS-specific";
422 break;
437 break;
423 case PT_SUNWSTACK:
438 case PT_SUNWSTACK:
424 type = "Stack segment";
439 type = "Stack segment";
425 break;
440 break;
426 case PT_LOPROC:
441 case PT_LOPROC:
427 type = "Start of processor-specific";
442 type = "Start of processor-specific";
428 break;
443 break;
429 case PT_HIPROC:
444 case PT_HIPROC:
430 type = "End of processor-specific";
445 type = "End of processor-specific";
431 break;
446 break;
432 default:
447 default:
433 type = "Unknow Section Type";
448 type = "Unknow Section Type";
434 break;
449 break;
435 }
450 }
436 }
451 }
437 }
452 }
438
453
439 return type;
454 return type;
440 }
455 }
441
456
442
457
443 int64_t elfparser::getSegmentOffset(int index)
458 int64_t elfparser::getSegmentOffset(int index)
444 {
459 {
445 int64_t Offset;
460 int64_t Offset;
446 if(this->e!=NULL)
461 if(this->e!=NULL)
447 {
462 {
448 if(index < this->Segments.count())
463 if(index < this->Segments.count())
449 {
464 {
450 Offset = (int64_t)this->Segments.at(index)->p_offset;
465 Offset = (int64_t)this->Segments.at(index)->p_offset;
451 }
466 }
452 }
467 }
453 return Offset;
468 return Offset;
454 }
469 }
455
470
456
471
457 int64_t elfparser::getSegmentVaddr(int index)
472 int64_t elfparser::getSegmentVaddr(int index)
458 {
473 {
459 int64_t Vaddr = 0;
474 int64_t Vaddr = 0;
460 if(this->e!=NULL)
475 if(this->e!=NULL)
461 {
476 {
462 if(index < this->Segments.count())
477 if(index < this->Segments.count())
463 {
478 {
464 Vaddr = (int64_t)this->Segments.at(index)->p_vaddr;
479 Vaddr = (int64_t)this->Segments.at(index)->p_vaddr;
465 }
480 }
466 }
481 }
467 return Vaddr;
482 return Vaddr;
468 }
483 }
469
484
470
485
471 int64_t elfparser::getSegmentPaddr(int index)
486 int64_t elfparser::getSegmentPaddr(int index)
472 {
487 {
473 int64_t Paddr=0;
488 int64_t Paddr=0;
474 if(this->e!=NULL)
489 if(this->e!=NULL)
475 {
490 {
476 if(index < this->Segments.count())
491 if(index < this->Segments.count())
477 {
492 {
478 Paddr = (int64_t)this->Segments.at(index)->p_paddr;
493 Paddr = (int64_t)this->Segments.at(index)->p_paddr;
479 }
494 }
480 }
495 }
481 return Paddr;
496 return Paddr;
482 }
497 }
483
498
484 int64_t elfparser::getSectionPaddr(int index)
499 int64_t elfparser::getSectionPaddr(int index)
485 {
500 {
486 int64_t Paddr=0;
501 int64_t Paddr=0;
487 if(this->e!=NULL)
502 if(this->e!=NULL)
488 {
503 {
489 if(index < this->sections.count())
504 if(index < this->sections.count())
490 {
505 {
491 Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr;
506 Paddr = (int64_t)this->sections.at(index)->section_header->sh_addr;
492 }
507 }
493 }
508 }
494 return Paddr;
509 return Paddr;
495 }
510 }
496
511
497
512
498 int64_t elfparser::getSegmentFilesz(int index)
513 int64_t elfparser::getSegmentFilesz(int index)
499 {
514 {
500 int64_t FileSz=0;
515 int64_t FileSz=0;
501 if(this->e!=NULL)
516 if(this->e!=NULL)
502 {
517 {
503 if(index < this->Segments.count())
518 if(index < this->Segments.count())
504 {
519 {
505 FileSz = (int64_t)this->Segments.at(index)->p_filesz;
520 FileSz = (int64_t)this->Segments.at(index)->p_filesz;
506 }
521 }
507 }
522 }
508 return FileSz;
523 return FileSz;
509 }
524 }
510
525
511 int64_t elfparser::getSectionDatasz(int index)
526 int64_t elfparser::getSectionDatasz(int index)
512 {
527 {
513 int64_t DataSz=0;
528 int64_t DataSz=0;
514 if(this->e!=NULL)
529 if(this->e!=NULL)
515 {
530 {
516 if(index < this->sections.count())
531 if(index < this->sections.count())
517 {
532 {
518 DataSz = (int64_t)this->sections.at(index)->data->d_size;
533 DataSz = (int64_t)this->sections.at(index)->data->d_size;
519 }
534 }
520 }
535 }
521 return DataSz;
536 return DataSz;
522 }
537 }
523
538
524 bool elfparser::getSectionData(int index, char **buffer)
539 bool elfparser::getSectionData(int index, char **buffer)
525 {
540 {
526 if(this->e!=NULL)
541 if(this->e!=NULL)
527 {
542 {
528 if(index < this->sections.count())
543 if(index < this->sections.count())
529 {
544 {
530 *buffer = (char *)this->sections.at(index)->data->d_buf;
545 *buffer = (char *)this->sections.at(index)->data->d_buf;
531 return true;
546 return true;
532 }
547 }
533 }
548 }
534 return false;
549 return false;
535 }
550 }
536
551
537
552
538 int64_t elfparser::getSegmentMemsz(int index)
553 int64_t elfparser::getSegmentMemsz(int index)
539 {
554 {
540 int64_t MemSz=0;
555 int64_t MemSz=0;
541 if(this->e!=NULL)
556 if(this->e!=NULL)
542 {
557 {
543 if(index < this->Segments.count())
558 if(index < this->Segments.count())
544 {
559 {
545 MemSz = (int64_t)this->Segments.at(index)->p_memsz;
560 MemSz = (int64_t)this->Segments.at(index)->p_memsz;
546 }
561 }
547 }
562 }
548 return MemSz;
563 return MemSz;
549 }
564 }
550
565
551 int64_t elfparser::getSectionMemsz(int index)
566 int64_t elfparser::getSectionMemsz(int index)
552 {
567 {
553 int64_t MemSz=0;
568 int64_t MemSz=0;
554 if(this->e!=NULL)
569 if(this->e!=NULL)
555 {
570 {
556 if(index < this->sections.count())
571 if(index < this->sections.count())
557 {
572 {
558 MemSz = (int64_t)this->sections.at(index)->section_header->sh_size;
573 MemSz = (int64_t)this->sections.at(index)->section_header->sh_size;
559 }
574 }
560 }
575 }
561 return MemSz;
576 return MemSz;
562 }
577 }
563
578
564
579
565 QString elfparser::getSegmentFlags(int index)
580 QString elfparser::getSegmentFlags(int index)
566 {
581 {
567 QString flags("");
582 QString flags("");
568 if(this->e!=NULL)
583 if(this->e!=NULL)
569 {
584 {
570 if(index < this->Segments.count())
585 if(index < this->Segments.count())
571 {
586 {
572 if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x";
587 if((this->Segments.at(index)->p_flags&PF_X) == PF_X)flags+="x";
573 if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w";
588 if((this->Segments.at(index)->p_flags&PF_W) == PF_W)flags+="w";
574 if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r";
589 if((this->Segments.at(index)->p_flags&PF_R) == PF_R)flags+="r";
575 if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific";
590 if((this->Segments.at(index)->p_flags&PF_MASKOS) == PF_MASKOS)flags+=" OS-specific";
576 if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific";
591 if((this->Segments.at(index)->p_flags&PF_MASKPROC) == PF_MASKPROC)flags+=" Processor-specific";
577 }
592 }
578 }
593 }
579 return flags;
594 return flags;
580 }
595 }
581
596
582
597
583 QString elfparser::getSectionName(int index)
598 QString elfparser::getSectionName(int index)
584 {
599 {
585 char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name);
600 char* nameChr = elf_strptr(this->e , this->shstrndx , this->sections.at(index)->section_header->sh_name);
586 return QString(nameChr);
601 return QString(nameChr);
587 }
602 }
588
603
589
604
590 void elfparser::updateSections()
605 void elfparser::updateSections()
591 {
606 {
592 for(int i=0;i<this->sections.count();i++)
607 for(int i=0;i<this->sections.count();i++)
593 {
608 {
594 delete this->sections.at(i);
609 delete this->sections.at(i);
595 }
610 }
596 this->sections.clear();
611 this->sections.clear();
597 this->scn = elf_nextscn (this->e , NULL );
612 this->scn = elf_nextscn (this->e , NULL );
598 this->SectionCount = 0;
613 this->SectionCount = 0;
599 while( this->scn != NULL )
614 while( this->scn != NULL )
600 {
615 {
601 GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr));
616 GElf_Shdr* shdr = (GElf_Shdr*)malloc(sizeof(GElf_Shdr));
602 gelf_getshdr ( this->scn , shdr );
617 gelf_getshdr ( this->scn , shdr );
603 Elf_Data* data = elf_getdata(this->scn, NULL);
618 Elf_Data* data = elf_getdata(this->scn, NULL);
604 this->sections.append(new Elf_Section(data,shdr));
619 this->sections.append(new Elf_Section(data,shdr));
605 this->SectionCount+=1;
620 this->SectionCount+=1;
606 this->scn = elf_nextscn(e , scn);
621 this->scn = elf_nextscn(e , scn);
607 }
622 }
608 }
623 }
609
624
610
625
611 void elfparser::updateSegments()
626 void elfparser::updateSegments()
612 {
627 {
613 elf_getphdrnum (this->e , &this->SegmentCount);
628 elf_getphdrnum (this->e , &this->SegmentCount);
614 for(int i=0;i<this->Segments.count();i++)
629 for(int i=0;i<this->Segments.count();i++)
615 {
630 {
616 free(this->Segments.at(i));
631 free(this->Segments.at(i));
617 }
632 }
618 this->Segments.clear();
633 this->Segments.clear();
619 for(int i=0;i<this->SegmentCount;i++)
634 for(int i=0;i<this->SegmentCount;i++)
620 {
635 {
621 GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr));
636 GElf_Phdr* header=(GElf_Phdr*)malloc(sizeof(GElf_Phdr));
622 gelf_getphdr (this->e , i , header );
637 gelf_getphdr (this->e , i , header );
623 this->Segments.append(header);
638 this->Segments.append(header);
624 }
639 }
625 }
640 }
626
641
627
642
628
643
629
644
630
645
631 QString elfparser::getSectionType(int index)
646 QString elfparser::getSectionType(int index)
632 {
647 {
633 QString type("");
648 QString type("");
634 if(this->e!=NULL)
649 if(this->e!=NULL)
635 {
650 {
636 if(index < this->Segments.count())
651 if(index < this->Segments.count())
637 {
652 {
638 switch(this->Segments.at(index)->p_type)
653 switch(this->Segments.at(index)->p_type)
639 {
654 {
640 case SHT_NULL : type = "Section header table entry unused"; break;
655 case SHT_NULL : type = "Section header table entry unused"; break;
641 case SHT_PROGBITS : type = "Program data"; break;
656 case SHT_PROGBITS : type = "Program data"; break;
642 case SHT_SYMTAB : type = "Symbol table"; break;
657 case SHT_SYMTAB : type = "Symbol table"; break;
643 case SHT_STRTAB : type = "String table"; break;
658 case SHT_STRTAB : type = "String table"; break;
644 case SHT_RELA : type = "Relocation entries with addends"; break;
659 case SHT_RELA : type = "Relocation entries with addends"; break;
645 case SHT_HASH : type = "Symbol hash table"; break;
660 case SHT_HASH : type = "Symbol hash table"; break;
646 case SHT_DYNAMIC : type = "Dynamic linking information"; break;
661 case SHT_DYNAMIC : type = "Dynamic linking information"; break;
647 case SHT_NOTE : type = "Notes"; break;
662 case SHT_NOTE : type = "Notes"; break;
648 case SHT_NOBITS :type = "Program space with no data (bss)"; break;
663 case SHT_NOBITS :type = "Program space with no data (bss)"; break;
649 case SHT_REL :type = "Relocation entries, no addends"; break;
664 case SHT_REL :type = "Relocation entries, no addends"; break;
650 case SHT_SHLIB : type = "Reserved"; break;
665 case SHT_SHLIB : type = "Reserved"; break;
651 case SHT_DYNSYM : type = "Dynamic linker symbol table"; break;
666 case SHT_DYNSYM : type = "Dynamic linker symbol table"; break;
652 case SHT_INIT_ARRAY : type = "Array of constructors"; break;
667 case SHT_INIT_ARRAY : type = "Array of constructors"; break;
653 case SHT_FINI_ARRAY : type = "Array of destructors"; break;
668 case SHT_FINI_ARRAY : type = "Array of destructors"; break;
654 case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break;
669 case SHT_PREINIT_ARRAY : type = "Array of pre-constructors"; break;
655 case SHT_GROUP : type = "Section group"; break;
670 case SHT_GROUP : type = "Section group"; break;
656 case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break;
671 case SHT_SYMTAB_SHNDX : type = "Extended section indeces"; break;
657 case SHT_NUM : type = "Number of defined types. "; break;
672 case SHT_NUM : type = "Number of defined types. "; break;
658 case SHT_LOOS : type = "Start OS-specific. "; break;
673 case SHT_LOOS : type = "Start OS-specific. "; break;
659 case SHT_LOSUNW : type = "Sun-specific low bound. "; break;
674 case SHT_LOSUNW : type = "Sun-specific low bound. "; break;
660 case SHT_SUNW_COMDAT : type = " "; break;
675 case SHT_SUNW_COMDAT : type = " "; break;
661 case SHT_SUNW_syminfo : type = " "; break;
676 case SHT_SUNW_syminfo : type = " "; break;
662 case SHT_GNU_verdef : type = "Version definition section. "; break;
677 case SHT_GNU_verdef : type = "Version definition section. "; break;
663 case SHT_GNU_verneed : type = "Version needs section. "; break;
678 case SHT_GNU_verneed : type = "Version needs section. "; break;
664 case SHT_GNU_versym : type = "Version symbol table. "; break;
679 case SHT_GNU_versym : type = "Version symbol table. "; break;
665 case SHT_LOPROC : type = "Start of processor-specific"; break;
680 case SHT_LOPROC : type = "Start of processor-specific"; break;
666 case SHT_HIPROC : type = "End of processor-specific"; break;
681 case SHT_HIPROC : type = "End of processor-specific"; break;
667 case SHT_HIUSER : type = "End of application-specific"; break;
682 case SHT_HIUSER : type = "End of application-specific"; break;
668 }
683 }
669 }
684 }
670 }
685 }
671 return type;
686 return type;
672 }
687 }
673
688
674 bool elfparser::isElf(const QString &File)
689 bool elfparser::isElf(const QString &File)
675 {
690 {
676 int file =0;
691 int file =0;
677 #ifdef _ELF_WINDOWS_
692 #ifdef _ELF_WINDOWS_
678 file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
693 file = open(File.toStdString().c_str(),O_RDONLY|O_BINARY ,0);
679 #else
694 #else
680 file = open(File.toStdString().c_str(),O_RDONLY ,0);
695 file = open(File.toStdString().c_str(),O_RDONLY ,0);
681 #endif
696 #endif
682 char Magic[4];
697 char Magic[4];
683 if(file!=-1)
698 if(file!=-1)
684 {
699 {
685 read(file,Magic,4);
700 read(file,Magic,4);
686 close(file);
701 close(file);
687 if(Magic[0]==0x7f && Magic[1]==0x45 && Magic[2]==0x4c && Magic[3]==0x46)
702 if(Magic[0]==0x7f && Magic[1]==0x45 && Magic[2]==0x4c && Magic[3]==0x46)
688 {
703 {
689 return true;
704 return true;
690 }
705 }
691 }
706 }
692 return false;
707 return false;
693 }
708 }
694
709
695
710
696
711
697
712
698
713
699
714
700
715
701
716
General Comments 0
You need to be logged in to leave comments. Login now