more work on elf header

This commit is contained in:
georgemoralis 2023-04-04 09:29:49 +03:00
parent e37e047c0e
commit f58bb4abab
2 changed files with 28 additions and 0 deletions

View File

@ -98,6 +98,12 @@ void Elf::Open(const std::string& file_name)
m_elf_header = load_elf_header(*m_f);
if (!isElfFile())
{
delete m_elf_header;
m_elf_header = nullptr;
}
DebugDump();
}
@ -134,6 +140,27 @@ bool Elf::isSelfFile() const
return true;
}
bool Elf::isElfFile() const
{
if (m_f == nullptr)
{
return false;
}
if (m_elf_header == nullptr)
{
return false;
}
if (m_elf_header->e_ident[0] != '\x7f' || m_elf_header->e_ident[1] != '\x45' || m_elf_header->e_ident[2] != '\x4c' ||
m_elf_header->e_ident[3] != '\x46')
{
printf("Not an ELF file magic is wrong!\n");
return false;
}
return true;
}
void Elf::DebugDump() {
printf("SELF header:\n");
printf(" magic ..............: 0x%08" PRIx32 "\n", m_self->magic);

View File

@ -95,6 +95,7 @@ public:
void Open(const std::string & file_name);
bool isSelfFile() const;
bool isElfFile() const;
void DebugDump();
private: