#include "ELFHeaderView.h" #include "string_format.h" #include "lexical_cast_ex.h" #include #include template CELFHeaderView::CELFHeaderView(QMdiSubWindow* parent, QLayout* groupBoxLayout) : QWidget(parent) { std::vector labelsStr = {"Type:", "Machine:", "Version:", "Entry Point:", "Flags:", "Header Size:", "Program Header Table Offset:", "Program Header Size:", "Program Header Count:", "Section Header Table Offset:", "Section Header Size:", "Section Header Count:", "Section Header String Table Index:"}; m_layout = new QVBoxLayout(this); auto label = new QLabel(this); QFontMetrics metric(label->font()); delete label; auto labelWidth = metric.horizontalAdvance(labelsStr.back().c_str()) + 10; for(auto labelStr : labelsStr) { auto horizontalLayout = new QHBoxLayout(); auto label = new QLabel(this); label->setText(labelStr.c_str()); label->setFixedWidth(labelWidth); horizontalLayout->addWidget(label); auto lineEdit = new QLineEdit(this); lineEdit->setReadOnly(true); m_editFields.push_back(lineEdit); horizontalLayout->addWidget(lineEdit); m_layout->addLayout(horizontalLayout); } m_layout->addStretch(); groupBoxLayout->addWidget(this); hide(); } template void CELFHeaderView::Reset() { for(auto editField : m_editFields) { editField->clear(); } } template void CELFHeaderView::SetELF(ElfType* pELF) { m_pELF = pELF; FillInformation(); } template void CELFHeaderView::FillInformation() { int i = 0; std::string sTemp; const auto* pH = &m_pELF->GetHeader(); #define CASE_ELF_ENUM(enumValue) \ case ELF::enumValue: \ sTemp = #enumValue; \ break; switch(pH->nType) { CASE_ELF_ENUM(ET_NONE) CASE_ELF_ENUM(ET_REL) CASE_ELF_ENUM(ET_EXEC) CASE_ELF_ENUM(ET_DYN) CASE_ELF_ENUM(ET_CORE) default: sTemp = string_format(("Unknown (%i)"), pH->nType); break; } m_editFields[i++]->setText(sTemp.c_str()); switch(pH->nCPU) { CASE_ELF_ENUM(EM_NONE) CASE_ELF_ENUM(EM_M32) CASE_ELF_ENUM(EM_SPARC) CASE_ELF_ENUM(EM_386) CASE_ELF_ENUM(EM_68K) CASE_ELF_ENUM(EM_88K) CASE_ELF_ENUM(EM_860) CASE_ELF_ENUM(EM_MIPS) CASE_ELF_ENUM(EM_PPC64) CASE_ELF_ENUM(EM_SPU) CASE_ELF_ENUM(EM_ARM) CASE_ELF_ENUM(EM_X86_64) default: sTemp = string_format(("Unknown (%i)"), pH->nCPU); break; } m_editFields[i++]->setText(sTemp.c_str()); switch(pH->nVersion) { CASE_ELF_ENUM(EV_NONE) CASE_ELF_ENUM(EV_CURRENT) default: sTemp = string_format(("Unknown (%i)"), pH->nVersion); break; } m_editFields[i++]->setText(sTemp.c_str()); #undef CASE_ELF_ENUM m_editFields[i++]->setText((("0x") + lexical_cast_hex(pH->nEntryPoint, 8)).c_str()); m_editFields[i++]->setText((("0x") + lexical_cast_hex(pH->nFlags, 8)).c_str()); m_editFields[i++]->setText((("0x") + lexical_cast_hex(pH->nSize, 8)).c_str()); m_editFields[i++]->setText((("0x") + lexical_cast_hex(pH->nProgHeaderStart, 8)).c_str()); m_editFields[i++]->setText((("0x") + lexical_cast_hex(pH->nProgHeaderEntrySize, 8)).c_str()); m_editFields[i++]->setText(lexical_cast_uint(pH->nProgHeaderCount).c_str()); m_editFields[i++]->setText((("0x") + lexical_cast_hex(pH->nSectHeaderStart, 8)).c_str()); m_editFields[i++]->setText((("0x") + lexical_cast_hex(pH->nSectHeaderEntrySize, 8)).c_str()); m_editFields[i++]->setText(lexical_cast_uint(pH->nSectHeaderCount).c_str()); m_editFields[i++]->setText(lexical_cast_uint(pH->nSectHeaderStringTableIndex).c_str()); } template class CELFHeaderView; template class CELFHeaderView;