feature (ELF): defined structs to parse dynamic section

This commit is contained in:
antifallobst 2023-05-31 00:16:25 +02:00
parent 82af1f195b
commit bb19ff02e1
3 changed files with 41 additions and 9 deletions

View File

@ -0,0 +1,23 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef NOXOS_DYNAMIC_H
#define NOXOS_DYNAMIC_H
#include <utils/stdtypes.h>
typedef enum {
ELF_DYNAMIC_TAG_NULL,
ELF_DYNAMIC_TAG_NEEDED,
ELF_DYNAMIC_TAG_PLT_REL_SIZE,
ELF_DYNAMIC_TAG_HASH,
ELF_DYNAMIC_TAG_STRTAB,
ELF_DYNAMIC_TAG_RELA,
ELF_DYNAMIC_TAG_RELA_SIZE
} elf_dynamic_tag_E;
typedef struct {
uint32_t tag;
uint64_t value;
} elf_dynamic_T;
#endif //NOXOS_DYNAMIC_H

View File

@ -13,7 +13,7 @@ typedef enum {
ELF_SECTION_STRING_TABLE,
ELF_SECTION_RELOCATION_A,
ELF_SECTION_HASH,
ELF_SECTION_DYNAMIC_LINK,
ELF_SECTION_DYNAMIC,
ELF_SECTION_NOTE,
ELF_SECTION_NOBITS,

View File

@ -4,14 +4,23 @@
#include <utils/logger.h>
void elf_relocate(elf_executable_T* executable, uint8_t* buffer, void* address) {
elf_section_T* sections = (elf_section_T*)&buffer[executable->header.offset_section_header];
elf_section_T* sections = (elf_section_T*)&buffer[executable->header.offset_section_header];
elf_section_T* section_dynamic = NULL;
for (uint32_t i = 0; i < executable->header.num_section_header_entries; i++) {
if (sections[i].type != ELF_SECTION_RELOCATION_A) continue;
uint32_t num_relocations = sections[i].length / sections[i].entry_size;
elf_section_T* related_section = &sections[sections[i].info];
DEBUG("Found RELA section -> relocations: %d section: 0x%x", num_relocations, related_section);
if (sections[i].type != ELF_SECTION_DYNAMIC) continue;
section_dynamic = &sections[i];
DEBUG("Found DYNAMIC section %d", i);
break;
}
if (section_dynamic == NULL) {
log(LOG_ERROR, "Failed to relocate ELF executable (no .dynamic section found)");
return;
}
// elf_section_T* section_rela = ;
//
// uint32_t num_relocations = sections[i].length / sections[i].entry_size;
// elf_section_T* related_section = &sections[sections[i].info];
// DEBUG("Found RELA section -> relocations: %d section: 0x%x", num_relocations, related_section);
}