initial commit
This commit is contained in:
41
src/elf.h
Normal file
41
src/elf.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#define ELF_MAGIC_0 0x7f
|
||||
#define ELF_MAGIC_1 'E'
|
||||
#define ELF_MAGIC_2 'L'
|
||||
#define ELF_MAGIC_3 'F'
|
||||
|
||||
#define ELFCLASS32 1
|
||||
#define ELFDATA2LSB 1
|
||||
|
||||
#define SHT_NOBITS 8u
|
||||
#define SHT_SYMTAB 2u
|
||||
#define SHF_ALLOC 0x2u
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
LOAD_OK = 1,
|
||||
LOAD_ERR_OPEN = -1,
|
||||
LOAD_ERR_SMALL_FILE = -2,
|
||||
LOAD_ERR_NOT_ELF = -3,
|
||||
LOAD_ERR_UNSUPPORTED_FORMAT = -4,
|
||||
LOAD_ERR_INVALID_SHT = -5,
|
||||
LOAD_ERR_SHT_OUT_OF_BOUNDS = -6,
|
||||
LOAD_ERR_SECTION_TOO_LARGE = -7,
|
||||
LOAD_ERR_SECTION_FILE_BOUNDS = -8,
|
||||
LOAD_ERR_OOM = -9,
|
||||
LOAD_ERR_SYMTAB_MISSING = -10,
|
||||
LOAD_ERR_STRTAB_INVALID = -11,
|
||||
LOAD_ERR_SYMBOL_NOT_FOUND = -12,
|
||||
LOAD_ERR_SYMBOL_INVALID_SECTION = -13,
|
||||
LOAD_ERR_SYMBOL_OUT_OF_RANGE = -14
|
||||
};
|
||||
|
||||
uint16_t read_u16_le(const uint8_t* data);
|
||||
uint32_t read_u32_le(const uint8_t* data);
|
||||
uint32_t align_up(uint32_t value, uint32_t align);
|
||||
int load_elf_object_sections(const char* path, uint8_t* memory, uint32_t mem_size);
|
||||
int resolve_elf_symbol_memory_offset(const char* path, const char* symbol_name,
|
||||
uint32_t mem_size, uint32_t* out_offset);
|
||||
|
||||
Reference in New Issue
Block a user