[elf] Allow checking for different file types

Previously `elf::file::valid()` only returned true for ELF files of type
`ET_EXEC`, now allow passing in of an expected file type.
This commit is contained in:
Justin C. Miller
2023-08-05 17:37:45 -07:00
parent bbe27c6b53
commit c86c0f2ae6
2 changed files with 18 additions and 5 deletions

View File

@@ -20,22 +20,29 @@ file::file(util::const_buffer data) :
}
bool
file::valid() const
file::valid(elf::filetype type) const
{
if (m_data.count < sizeof(file_header))
return false;
const file_header *fheader = header();
return
bool abi_valid =
fheader->magic == expected_magic &&
fheader->word_size == wordsize::bits64 &&
fheader->endianness == encoding::lsb &&
fheader->os_abi == osabi::sysV &&
fheader->file_type == filetype::executable &&
fheader->machine_type == machine::x64 &&
fheader->ident_version == 1 &&
fheader->version == 1;
if (!abi_valid)
return false;
if (type != filetype::none && fheader->file_type != type)
return false;
return true;
}
uintptr_t