From 115f4ff541839f7a97f9413e1ac3ff7695c24c9e Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 1 Aug 2020 15:59:39 +0200 Subject: Switched to PIE flat binaries --- src/features/elf.c | 39 --------------------------------------- src/features/load.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 39 deletions(-) delete mode 100644 src/features/elf.c create mode 100644 src/features/load.c (limited to 'src/features') 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 -#include -#include -#include -#include -#include - -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 +#include +#include + +void bin_load(char *path) +{ + char *data = read_file(path); + + void (*entry)(); + *(void **)(&entry) = data + 0xfe; + + entry(); +} -- cgit v1.2.3