2019-12-21 18:36:40 +00:00
|
|
|
#include "ELFSymbolView.h"
|
|
|
|
#include "string_format.h"
|
|
|
|
#include "lexical_cast_ex.h"
|
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QFontMetrics>
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
2022-07-22 17:01:59 -04:00
|
|
|
template <typename ElfType>
|
|
|
|
CELFSymbolView<ElfType>::CELFSymbolView(QMdiSubWindow* parent, QLayout* groupBoxLayout)
|
2019-12-21 18:48:44 +00:00
|
|
|
: QWidget(parent)
|
2019-12-21 18:36:40 +00:00
|
|
|
{
|
|
|
|
QStringList colLabels = {"Name", "Address", "Size", "Type", "Binding", "Section"};
|
|
|
|
|
|
|
|
m_layout = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
m_tableWidget = new QTableWidget(this);
|
|
|
|
m_tableWidget->setRowCount(0);
|
|
|
|
m_tableWidget->setColumnCount(6);
|
|
|
|
m_tableWidget->setHorizontalHeaderLabels(colLabels);
|
2022-08-12 12:15:42 -04:00
|
|
|
m_tableWidget->setSortingEnabled(true);
|
2019-12-21 18:36:40 +00:00
|
|
|
|
|
|
|
m_tableWidget->verticalHeader()->hide();
|
|
|
|
m_tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
|
|
|
|
|
|
|
m_tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
m_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
m_tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
|
|
|
m_layout->addWidget(m_tableWidget);
|
|
|
|
|
|
|
|
groupBoxLayout->addWidget(this);
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2022-07-22 17:01:59 -04:00
|
|
|
template <typename ElfType>
|
|
|
|
void CELFSymbolView<ElfType>::Reset()
|
2019-12-21 18:36:40 +00:00
|
|
|
{
|
|
|
|
m_tableWidget->setRowCount(0);
|
|
|
|
}
|
|
|
|
|
2022-07-22 17:01:59 -04:00
|
|
|
template <typename ElfType>
|
|
|
|
void CELFSymbolView<ElfType>::SetELF(ElfType* pELF)
|
2019-12-21 18:36:40 +00:00
|
|
|
{
|
|
|
|
m_pELF = pELF;
|
|
|
|
PopulateList();
|
|
|
|
}
|
|
|
|
|
2022-07-22 17:01:59 -04:00
|
|
|
template <typename ElfType>
|
|
|
|
void CELFSymbolView<ElfType>::PopulateList()
|
2019-12-21 18:36:40 +00:00
|
|
|
{
|
|
|
|
const char* sectionName = ".symtab";
|
|
|
|
|
2022-03-15 08:13:44 -04:00
|
|
|
auto pSymTab = m_pELF->FindSection(sectionName);
|
2019-12-21 18:36:40 +00:00
|
|
|
if(pSymTab == NULL) return;
|
|
|
|
|
|
|
|
const char* pStrTab = (const char*)m_pELF->GetSectionData(pSymTab->nIndex);
|
|
|
|
if(pStrTab == NULL) return;
|
|
|
|
|
2022-07-25 11:19:56 -04:00
|
|
|
auto symbols = reinterpret_cast<const typename ElfType::SYMBOL*>(m_pELF->FindSectionData(sectionName));
|
|
|
|
unsigned int count = pSymTab->nSize / sizeof(typename ElfType::SYMBOL);
|
2019-12-21 18:36:40 +00:00
|
|
|
|
2022-03-16 19:32:03 -04:00
|
|
|
m_tableWidget->setRowCount(count);
|
2019-12-21 18:36:40 +00:00
|
|
|
|
2022-07-27 10:53:59 -04:00
|
|
|
#define CASE_ELF_ENUM(enumValue) \
|
|
|
|
case ELF::enumValue: \
|
|
|
|
sTemp = #enumValue; \
|
|
|
|
break;
|
|
|
|
|
2022-03-16 19:32:03 -04:00
|
|
|
for(unsigned int i = 0; i < count; i++)
|
2019-12-21 18:36:40 +00:00
|
|
|
{
|
2022-03-16 19:32:03 -04:00
|
|
|
auto symbol = symbols[i];
|
|
|
|
|
2019-12-21 18:36:40 +00:00
|
|
|
int j = 0;
|
|
|
|
std::string sTemp;
|
|
|
|
|
2022-03-16 19:32:03 -04:00
|
|
|
m_tableWidget->setItem(i, j++, new QTableWidgetItem(pStrTab + symbol.nName));
|
|
|
|
m_tableWidget->setItem(i, j++, new QTableWidgetItem(lexical_cast_hex<std::string>(symbol.nValue, 8).c_str()));
|
|
|
|
m_tableWidget->setItem(i, j++, new QTableWidgetItem(lexical_cast_hex<std::string>(symbol.nSize, 8).c_str()));
|
2019-12-21 18:36:40 +00:00
|
|
|
|
2022-03-16 19:32:03 -04:00
|
|
|
switch(symbol.nInfo & 0x0F)
|
2019-12-21 18:36:40 +00:00
|
|
|
{
|
2022-07-27 10:53:59 -04:00
|
|
|
CASE_ELF_ENUM(STT_NOTYPE)
|
|
|
|
CASE_ELF_ENUM(STT_OBJECT)
|
|
|
|
CASE_ELF_ENUM(STT_FUNC)
|
|
|
|
CASE_ELF_ENUM(STT_SECTION)
|
|
|
|
CASE_ELF_ENUM(STT_FILE)
|
2019-12-21 18:36:40 +00:00
|
|
|
default:
|
2022-03-16 19:32:03 -04:00
|
|
|
sTemp = string_format("%i", symbol.nInfo & 0x0F);
|
2019-12-21 18:36:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_tableWidget->setItem(i, j++, new QTableWidgetItem(sTemp.c_str()));
|
|
|
|
|
2022-03-16 19:32:03 -04:00
|
|
|
switch((symbol.nInfo >> 4) & 0xF)
|
2019-12-21 18:36:40 +00:00
|
|
|
{
|
2022-07-27 10:53:59 -04:00
|
|
|
CASE_ELF_ENUM(STB_LOCAL)
|
|
|
|
CASE_ELF_ENUM(STB_GLOBAL)
|
|
|
|
CASE_ELF_ENUM(STB_WEAK)
|
2019-12-21 18:36:40 +00:00
|
|
|
default:
|
2022-03-16 19:32:03 -04:00
|
|
|
sTemp = string_format("%i", (symbol.nInfo >> 4) & 0x0F);
|
2019-12-21 18:36:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_tableWidget->setItem(i, j++, new QTableWidgetItem(sTemp.c_str()));
|
|
|
|
|
2022-03-16 19:32:03 -04:00
|
|
|
switch(symbol.nSectionIndex)
|
2019-12-21 18:36:40 +00:00
|
|
|
{
|
2022-07-27 10:53:59 -04:00
|
|
|
CASE_ELF_ENUM(SHN_UNDEF)
|
|
|
|
CASE_ELF_ENUM(SHN_ABS)
|
2022-09-28 08:37:09 -04:00
|
|
|
CASE_ELF_ENUM(SHN_XINDEX)
|
2019-12-21 18:36:40 +00:00
|
|
|
default:
|
2022-03-16 19:32:03 -04:00
|
|
|
sTemp = string_format("%i", symbol.nSectionIndex);
|
2019-12-21 18:36:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_tableWidget->setItem(i, j++, new QTableWidgetItem(sTemp.c_str()));
|
2022-07-27 10:53:59 -04:00
|
|
|
|
|
|
|
#undef CASE_ELF_ENUM
|
2019-12-21 18:36:40 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-22 17:01:59 -04:00
|
|
|
|
|
|
|
template class CELFSymbolView<CELF32>;
|
|
|
|
template class CELFSymbolView<CELF64>;
|