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
|
//function to display Self/Elf window
|
||||||
void ElfViewer::display(bool enabled)
|
void ElfViewer::display(bool enabled)
|
||||||
{
|
{
|
||||||
enum
|
int SELF_HEADER = 0;
|
||||||
{
|
int ELF_HEADER = 1;
|
||||||
SELF_HEADER,
|
int SEG_HEADER_START = 100;
|
||||||
ELF_HEADER
|
|
||||||
};
|
|
||||||
static int selected = -1;
|
static int selected = -1;
|
||||||
ImGui::Begin("Self/Elf Viewer", &enabled);
|
ImGui::Begin("Self/Elf Viewer", &enabled);
|
||||||
|
|
||||||
|
@ -30,6 +29,15 @@ void ElfViewer::display(bool enabled)
|
||||||
|
|
||||||
if (ImGui::TreeNode("Self Segment Header"))
|
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::TreePop();
|
||||||
}
|
}
|
||||||
ImGui::TreeNodeEx("Self Id Header", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen, "Self Id Header");
|
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"))
|
if (ImGui::TreeNode("Elf Program Headers"))
|
||||||
{
|
{
|
||||||
const auto* elf_header = elf->GetElfHeader();
|
const auto* elf_header = elf->GetElfHeader();
|
||||||
const auto* program_header = elf->GetProgramHeader();
|
|
||||||
for (u16 i = 0; i < elf_header->e_phnum; i++)
|
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();
|
ImGui::TreePop();
|
||||||
|
@ -70,6 +76,10 @@ void ElfViewer::display(bool enabled)
|
||||||
if (selected == SELF_HEADER) {
|
if (selected == SELF_HEADER) {
|
||||||
ImGui::TextWrapped(elf->SElfHeaderStr().c_str());
|
ImGui::TextWrapped(elf->SElfHeaderStr().c_str());
|
||||||
}
|
}
|
||||||
|
if (selected >= 100 && selected < 200)
|
||||||
|
{
|
||||||
|
ImGui::TextWrapped(elf->SELFSegHeader(selected-100).c_str());
|
||||||
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|
|
@ -275,17 +275,9 @@ void Elf::DebugDump() {
|
||||||
spdlog::set_formatter(std::move(f));
|
spdlog::set_formatter(std::move(f));
|
||||||
spdlog::info(SElfHeaderStr());
|
spdlog::info(SElfHeaderStr());
|
||||||
spdlog::info("\n");
|
spdlog::info("\n");
|
||||||
|
for (u16 i = 0; i < m_self->segment_count; i++)
|
||||||
spdlog::info("SELF segments:\n");
|
|
||||||
|
|
||||||
for (int i = 0; i < m_self->segment_count; i++)
|
|
||||||
{
|
{
|
||||||
auto segment_header = m_self_segments[i];
|
spdlog::info(SELFSegHeader(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("\n");
|
spdlog::info("\n");
|
||||||
|
|
||||||
|
@ -436,3 +428,13 @@ std::string Elf::SElfHeaderStr() {
|
||||||
header+= fmt::format("padding3 ...........: {:#010x}\n", m_self->padding3);
|
header+= fmt::format("padding3 ...........: {:#010x}\n", m_self->padding3);
|
||||||
return header;
|
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 isSelfFile() const;
|
||||||
bool isElfFile() const;
|
bool isElfFile() const;
|
||||||
void DebugDump();
|
void DebugDump();
|
||||||
|
[[nodiscard]] const self_header* GetSElfHeader() const { return m_self; }
|
||||||
[[nodiscard]] const elf_header* GetElfHeader() const { return m_elf_header; }
|
[[nodiscard]] const elf_header* GetElfHeader() const { return m_elf_header; }
|
||||||
[[nodiscard]] const elf_program_header* GetProgramHeader() const { return m_elf_phdr; }
|
[[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 SElfHeaderStr();
|
||||||
|
std::string SELFSegHeader(u16 no);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
Loading…
Reference in New Issue