1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-12-04 11:34:42 -05:00

Add function KernelMQ_ELF_Header_is_valid

This commit is contained in:
Alex Kotov 2020-11-25 19:02:15 +05:00
parent 878250df98
commit 579e2d1437
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 25 additions and 16 deletions

View file

@ -32,6 +32,30 @@ struct KernelMQ_ELF_Header {
}
__attribute__((packed));
inline static unsigned char KernelMQ_ELF_Header_is_valid(
const struct KernelMQ_ELF_Header *header
);
unsigned char KernelMQ_ELF_Header_is_valid(
const struct KernelMQ_ELF_Header *const header
) {
return (
header->magic_0x7F == 0x7F &&
header->magic_E == 'E' &&
header->magic_L == 'L' &&
header->magic_F == 'F' &&
header->bitness == 1 &&
header->endianness == 1 &&
header->header_version == 1 &&
header->os_abi == 0 &&
header->obj_type == 2 &&
header->isa == 3 &&
header->elf_version == 1 &&
header->arch_flags == 0 &&
header->header_size == 52
);
}
#ifdef __cplusplus
}
#endif

View file

@ -32,22 +32,7 @@ void init(const struct KernelMQ_Info *const kinfo_ptr)
const struct KernelMQ_ELF_Header *const elf_header =
(void*)kinfo.modules[0].base;
const unsigned char is_elf_header_valid =
elf_header->magic_0x7F == 0x7F &&
elf_header->magic_E == 'E' &&
elf_header->magic_L == 'L' &&
elf_header->magic_F == 'F' &&
elf_header->bitness == 1 &&
elf_header->endianness == 1 &&
elf_header->header_version == 1 &&
elf_header->os_abi == 0 &&
elf_header->obj_type == 2 &&
elf_header->isa == 3 &&
elf_header->elf_version == 1 &&
elf_header->arch_flags == 0 &&
elf_header->header_size == 52;
if (is_elf_header_valid) {
if (KernelMQ_ELF_Header_is_valid(elf_header)) {
const unsigned long real_entrypoint =
kinfo.modules[0].base + elf_header->entrypoint;