elfview imgui : added segment headers
This commit is contained in:
parent
cda7c67e36
commit
6511b280cf
|
@ -9,11 +9,10 @@ ElfViewer::ElfViewer(Elf* elf)
|
|||
//function to display Self/Elf window
|
||||
void ElfViewer::display(bool enabled)
|
||||
{
|
||||
enum
|
||||
{
|
||||
SELF_HEADER,
|
||||
ELF_HEADER
|
||||
};
|
||||
int SELF_HEADER = 0;
|
||||
int ELF_HEADER = 1;
|
||||
int SEG_HEADER_START = 100;
|
||||
|
||||
static int selected = -1;
|
||||
ImGui::Begin("Self/Elf Viewer", &enabled);
|
||||
|
||||
|
@ -30,6 +29,15 @@ void ElfViewer::display(bool enabled)
|
|||
|
||||
if (ImGui::TreeNode("Self Segment Header"))
|
||||
{
|
||||
const auto* self = elf->GetSElfHeader();
|
||||
for (u16 i = 0; i < self->segment_count; i++)
|
||||
{
|
||||
if (ImGui::TreeNodeEx((void*)(intptr_t)i, ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen, "%d", i))
|
||||
{
|
||||
if (ImGui::IsItemClicked())
|
||||
selected = SEG_HEADER_START+i;
|
||||
}
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
ImGui::TreeNodeEx("Self Id Header", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen, "Self Id Header");
|
||||
|
@ -46,12 +54,10 @@ void ElfViewer::display(bool enabled)
|
|||
if (ImGui::TreeNode("Elf Program Headers"))
|
||||
{
|
||||
const auto* elf_header = elf->GetElfHeader();
|
||||
const auto* program_header = elf->GetProgramHeader();
|
||||
for (u16 i = 0; i < elf_header->e_phnum; i++)
|
||||
{
|
||||
if (ImGui::TreeNode((void*)(intptr_t)i, "%d", i))
|
||||
if (ImGui::TreeNodeEx((void*)(intptr_t)i,ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen, "%d", i))
|
||||
{
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
ImGui::TreePop();
|
||||
|
@ -70,6 +76,10 @@ void ElfViewer::display(bool enabled)
|
|||
if (selected == SELF_HEADER) {
|
||||
ImGui::TextWrapped(elf->SElfHeaderStr().c_str());
|
||||
}
|
||||
if (selected >= 100 && selected < 200)
|
||||
{
|
||||
ImGui::TextWrapped(elf->SELFSegHeader(selected-100).c_str());
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::End();
|
||||
|
||||
|
|
|
@ -275,17 +275,9 @@ void Elf::DebugDump() {
|
|||
spdlog::set_formatter(std::move(f));
|
||||
spdlog::info(SElfHeaderStr());
|
||||
spdlog::info("\n");
|
||||
|
||||
spdlog::info("SELF segments:\n");
|
||||
|
||||
for (int i = 0; i < m_self->segment_count; i++)
|
||||
for (u16 i = 0; i < m_self->segment_count; i++)
|
||||
{
|
||||
auto segment_header = m_self_segments[i];
|
||||
spdlog::info(" [{}]\n", i);
|
||||
spdlog::info(" flags ............: {:#018x}\n", segment_header.flags);
|
||||
spdlog::info(" file offset ......: {:#018x}\n", segment_header.file_offset);
|
||||
spdlog::info(" file size ........: {}\n", segment_header.file_size);
|
||||
spdlog::info(" memory size ......: {}\n", segment_header.memory_size);
|
||||
spdlog::info(SELFSegHeader(i));
|
||||
}
|
||||
spdlog::info("\n");
|
||||
|
||||
|
@ -436,3 +428,13 @@ std::string Elf::SElfHeaderStr() {
|
|||
header+= fmt::format("padding3 ...........: {:#010x}\n", m_self->padding3);
|
||||
return header;
|
||||
}
|
||||
std::string Elf::SELFSegHeader(u16 no)
|
||||
{
|
||||
auto segment_header = m_self_segments[no];
|
||||
std::string header = fmt::format("======SEGMENT HEADER {} ========\n", no);
|
||||
header += fmt::format("flags ............: {:#018x}\n", segment_header.flags);
|
||||
header += fmt::format("file offset ......: {:#018x}\n", segment_header.file_offset);
|
||||
header += fmt::format("file size ........: {}\n", segment_header.file_size);
|
||||
header += fmt::format("memory size ......: {}\n", segment_header.memory_size);
|
||||
return header;
|
||||
}
|
|
@ -293,10 +293,12 @@ public:
|
|||
bool isSelfFile() const;
|
||||
bool isElfFile() const;
|
||||
void DebugDump();
|
||||
[[nodiscard]] const self_header* GetSElfHeader() const { return m_self; }
|
||||
[[nodiscard]] const elf_header* GetElfHeader() const { return m_elf_header; }
|
||||
[[nodiscard]] const elf_program_header* GetProgramHeader() const { return m_elf_phdr; }
|
||||
|
||||
[[nodiscard]] const self_segment_header* GetSegmentHeader() const { return m_self_segments; }
|
||||
std::string SElfHeaderStr();
|
||||
std::string SELFSegHeader(u16 no);
|
||||
private:
|
||||
|
||||
void Reset();
|
||||
|
|
Loading…
Reference in New Issue