feature (ELF): defined structs to parse dynamic section
This commit is contained in:
parent
82af1f195b
commit
bb19ff02e1
|
@ -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
|
|
@ -13,7 +13,7 @@ typedef enum {
|
||||||
ELF_SECTION_STRING_TABLE,
|
ELF_SECTION_STRING_TABLE,
|
||||||
ELF_SECTION_RELOCATION_A,
|
ELF_SECTION_RELOCATION_A,
|
||||||
ELF_SECTION_HASH,
|
ELF_SECTION_HASH,
|
||||||
ELF_SECTION_DYNAMIC_LINK,
|
ELF_SECTION_DYNAMIC,
|
||||||
ELF_SECTION_NOTE,
|
ELF_SECTION_NOTE,
|
||||||
ELF_SECTION_NOBITS,
|
ELF_SECTION_NOBITS,
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,22 @@
|
||||||
|
|
||||||
void elf_relocate(elf_executable_T* executable, uint8_t* buffer, void* address) {
|
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++) {
|
for (uint32_t i = 0; i < executable->header.num_section_header_entries; i++) {
|
||||||
if (sections[i].type != ELF_SECTION_RELOCATION_A) continue;
|
if (sections[i].type != ELF_SECTION_DYNAMIC) continue;
|
||||||
|
section_dynamic = §ions[i];
|
||||||
uint32_t num_relocations = sections[i].length / sections[i].entry_size;
|
DEBUG("Found DYNAMIC section %d", i);
|
||||||
elf_section_T* related_section = §ions[sections[i].info];
|
break;
|
||||||
|
|
||||||
DEBUG("Found RELA section -> relocations: %d section: 0x%x", num_relocations, related_section);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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 = §ions[sections[i].info];
|
||||||
|
|
||||||
|
// DEBUG("Found RELA section -> relocations: %d section: 0x%x", num_relocations, related_section);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue