#pragma once #include #include #include #include #ifdef __x86_64__ # define elf_validate elf64_validate # define elf_size elf64_size #endif struct linear_buffer { char *base; size_t length; }; struct elf64_image { struct linear_buffer buffer; struct { Elf64_Ehdr *file; Elf64_Phdr *segments; Elf64_Shdr *sections; } headers; }; bool elf64_validate(Elf64_Ehdr const *ehdr, unsigned type, unsigned machine); bool elf64_validate_fd(int fd, unsigned type, unsigned machine); size_t elf64_size(Elf64_Ehdr const *ehdr, Elf64_Phdr *phdr); size_t elf64_size_fd(int fd); ssize_t elf64_load_segments(int fd, size_t buffer_size, char buffer[buffer_size]); void *elf64_dt_ptr(char *base, Elf64_Dyn *dyntab, unsigned long dt_type); uintptr_t elf64_dt_val(Elf64_Dyn *dyntab, unsigned long dt_type); struct elf64_image elf64_open(const char *path);