diff options
author | Marvin Borner | 2020-08-01 15:59:39 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-01 15:59:39 +0200 |
commit | 115f4ff541839f7a97f9413e1ac3ff7695c24c9e (patch) | |
tree | d98602bba5a8b4321ae124d221f77e99008e9cd1 /src/features | |
parent | 46fb7dcf479ac85361d8eaae5af3ea27a6b93a2d (diff) |
Switched to PIE flat binaries
Diffstat (limited to 'src/features')
-rw-r--r-- | src/features/elf.c | 39 | ||||
-rw-r--r-- | src/features/load.c | 13 |
2 files changed, 13 insertions, 39 deletions
diff --git a/src/features/elf.c b/src/features/elf.c deleted file mode 100644 index f92f399..0000000 --- a/src/features/elf.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <assert.h> -#include <def.h> -#include <elf.h> -#include <fs.h> -#include <mem.h> -#include <str.h> - -int elf_verify(struct elf_header *h) -{ - return (h->ident[0] == ELF_MAG && !strncmp((char *)&h->ident[1], "ELF", 3) && - h->ident[4] == ELF_32 && h->ident[5] == ELF_LITTLE && h->ident[6] == ELF_CURRENT && - h->machine == ELF_386 && (h->type == ET_REL || h->type == ET_EXEC)); -} - -void elf_load(char *path) -{ - u32 *data = read_file(path); - - struct elf_header *h = (struct elf_header *)data; - assert(elf_verify(h)); - - struct elf_program_header *p = (struct elf_program_header *)((u32)data + h->phoff); - struct elf_program_header *p_end = - (struct elf_program_header *)((u32)p + (h->phentsize * h->phnum)); - - u32 offset = (p->vaddr - p->paddr); - while (p < p_end) { - printf("\nheader: 0x%x\n", p->paddr); - printf("filesz: %d\n", p->filesz); - /* memcpy(p->paddr, (u32)data + p->offset, p->filesz); */ - memcpy((u32 *)p->paddr, (u32 *)((u32)data + p->offset), p->filesz); - p++; - } - - void (*entry)(); - entry = (void (*)())(h->entry - offset); - - entry(); -} diff --git a/src/features/load.c b/src/features/load.c new file mode 100644 index 0000000..37ed6ad --- /dev/null +++ b/src/features/load.c @@ -0,0 +1,13 @@ +#include <def.h> +#include <fs.h> +#include <print.h> + +void bin_load(char *path) +{ + char *data = read_file(path); + + void (*entry)(); + *(void **)(&entry) = data + 0xfe; + + entry(); +} |