2021-12-13 17:07:00 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <kernaux/elf.h>
|
|
|
|
|
|
|
|
bool KernAux_ELF_Header_is_valid(
|
|
|
|
const struct KernAux_ELF_Header *const header
|
|
|
|
) {
|
|
|
|
if (!(
|
2022-01-23 21:50:16 -05:00
|
|
|
header->magic_0x7f == 0x7f &&
|
2021-12-13 17:07:00 -05:00
|
|
|
header->magic_E == 'E' &&
|
|
|
|
header->magic_L == 'L' &&
|
|
|
|
header->magic_F == 'F' &&
|
|
|
|
header->header_version == 1 &&
|
|
|
|
header->elf_version == 1
|
|
|
|
)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(
|
|
|
|
header->bitness == 1 || // 32 bit
|
|
|
|
header->bitness == 2 // 64 bit
|
|
|
|
)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(
|
|
|
|
header->endianness == 1 || // Little endian
|
|
|
|
header->endianness == 2 // Big endian
|
|
|
|
)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-14 14:13:18 -05:00
|
|
|
if (!(header->os_abi <= 0x12 && header->os_abi != 0x05)) {
|
2021-12-13 17:07:00 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(
|
|
|
|
header->obj_type == 0x00 || // NONE
|
|
|
|
header->obj_type == 0x01 || // REL
|
|
|
|
header->obj_type == 0x02 || // EXEC
|
|
|
|
header->obj_type == 0x03 || // DYN
|
|
|
|
header->obj_type == 0x04 || // CORE
|
2022-01-23 21:50:16 -05:00
|
|
|
header->obj_type == 0xfe00 || // LOOS
|
|
|
|
header->obj_type == 0xfeff || // HIOS
|
|
|
|
header->obj_type == 0xff00 || // LOPROC
|
|
|
|
header->obj_type == 0xffff // HIPROC
|
2021-12-13 17:07:00 -05:00
|
|
|
)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|