2020-03-25 03:04:18 +03:00
|
|
|
#ifndef __LIB__ELF_H__
|
|
|
|
#define __LIB__ELF_H__
|
|
|
|
|
2020-03-25 23:05:14 +03:00
|
|
|
#include <stdint.h>
|
2021-04-15 05:32:49 +03:00
|
|
|
#include <stdbool.h>
|
2022-06-29 10:34:14 +03:00
|
|
|
#include <lib/elsewhere.h>
|
2020-03-25 03:04:18 +03:00
|
|
|
|
2020-08-11 18:43:39 +03:00
|
|
|
#define FIXED_HIGHER_HALF_OFFSET_64 ((uint64_t)0xffffffff80000000)
|
|
|
|
|
2021-07-15 14:34:24 +03:00
|
|
|
#define ELF_PF_X 1
|
|
|
|
#define ELF_PF_W 2
|
|
|
|
#define ELF_PF_R 4
|
|
|
|
|
|
|
|
struct elf_range {
|
|
|
|
uint64_t base;
|
|
|
|
uint64_t length;
|
|
|
|
uint64_t permissions;
|
|
|
|
};
|
|
|
|
|
2021-09-09 11:40:07 +03:00
|
|
|
struct elf_section_hdr_info {
|
|
|
|
uint32_t section_entry_size;
|
|
|
|
uint32_t str_section_idx;
|
2021-09-10 11:02:54 +03:00
|
|
|
uint32_t num;
|
2022-06-19 00:40:34 +03:00
|
|
|
uint32_t section_offset;
|
2021-09-09 11:40:07 +03:00
|
|
|
};
|
|
|
|
|
2021-03-28 16:46:59 +03:00
|
|
|
int elf_bits(uint8_t *elf);
|
2020-04-18 19:01:29 +03:00
|
|
|
|
2022-06-29 08:48:10 +03:00
|
|
|
int elf64_load(uint8_t *elf, uint64_t *entry_point, uint64_t *top, uint64_t *_slide, uint32_t alloc_type, bool kaslr, struct elf_range **ranges, uint64_t *ranges_count, bool fully_virtual, uint64_t *physical_base, uint64_t *virtual_base, uint64_t *image_size, bool *is_reloc);
|
2021-03-28 16:46:59 +03:00
|
|
|
int elf64_load_section(uint8_t *elf, void *buffer, const char *name, size_t limit, uint64_t slide);
|
2021-09-12 05:54:37 +03:00
|
|
|
struct elf_section_hdr_info* elf64_section_hdr_info(uint8_t *elf);
|
2020-04-18 19:01:29 +03:00
|
|
|
|
2022-06-29 08:48:10 +03:00
|
|
|
int elf32_load(uint8_t *elf, uint32_t *entry_point, uint32_t *top, uint32_t alloc_type);
|
2021-03-28 16:46:59 +03:00
|
|
|
int elf32_load_section(uint8_t *elf, void *buffer, const char *name, size_t limit);
|
2021-09-12 05:54:37 +03:00
|
|
|
struct elf_section_hdr_info* elf32_section_hdr_info(uint8_t *elf);
|
2020-03-25 03:04:18 +03:00
|
|
|
|
2022-06-29 09:16:22 +03:00
|
|
|
bool elf32_load_elsewhere(uint8_t *elf, uint64_t *entry_point,
|
|
|
|
struct elsewhere_range **ranges,
|
2022-06-29 11:27:04 +03:00
|
|
|
uint64_t *ranges_count);
|
2022-06-29 09:16:22 +03:00
|
|
|
bool elf64_load_elsewhere(uint8_t *elf, uint64_t *entry_point,
|
|
|
|
struct elsewhere_range **ranges,
|
2022-06-29 11:27:04 +03:00
|
|
|
uint64_t *ranges_count);
|
2022-06-29 09:16:22 +03:00
|
|
|
|
2021-11-02 00:37:20 +03:00
|
|
|
struct elf64_hdr {
|
|
|
|
uint8_t ident[16];
|
|
|
|
uint16_t type;
|
|
|
|
uint16_t machine;
|
|
|
|
uint32_t version;
|
|
|
|
uint64_t entry;
|
|
|
|
uint64_t phoff;
|
|
|
|
uint64_t shoff;
|
|
|
|
uint32_t flags;
|
|
|
|
uint16_t hdr_size;
|
|
|
|
uint16_t phdr_size;
|
|
|
|
uint16_t ph_num;
|
|
|
|
uint16_t shdr_size;
|
|
|
|
uint16_t sh_num;
|
|
|
|
uint16_t shstrndx;
|
|
|
|
};
|
|
|
|
struct elf64_shdr {
|
|
|
|
uint32_t sh_name;
|
|
|
|
uint32_t sh_type;
|
|
|
|
uint64_t sh_flags;
|
|
|
|
uint64_t sh_addr;
|
|
|
|
uint64_t sh_offset;
|
|
|
|
uint64_t sh_size;
|
|
|
|
uint32_t sh_link;
|
|
|
|
uint32_t sh_info;
|
|
|
|
uint64_t sh_addralign;
|
|
|
|
uint64_t sh_entsize;
|
|
|
|
};
|
|
|
|
struct elf64_sym {
|
|
|
|
uint32_t st_name;
|
|
|
|
uint8_t st_info;
|
|
|
|
uint8_t st_other;
|
|
|
|
uint16_t st_shndx;
|
|
|
|
uint64_t st_value;
|
|
|
|
uint64_t st_size;
|
|
|
|
};
|
|
|
|
|
2020-03-25 03:04:18 +03:00
|
|
|
#endif
|