10 #define SIZEOF_VOID_P 4
11 #if SIZEOF_VOID_P == 8
12 typedef Elf64_Ehdr Elf_Ehdr;
13 #elif SIZEOF_VOID_P == 4
14 typedef Elf32_Ehdr Elf_Ehdr;
16 #error "Unknown void* size"
19 static int read_elf_header(Elf_Ehdr * header, const char *filepath)
21 int fd = open(filepath, O_RDONLY);
24 bool read_failed = read(fd, header, sizeof(*header)) != sizeof(*header);
26 return read_failed ? -EIO : 0;
29 static int elf_type(const char *filepath)
32 int err = read_elf_header(&header, filepath);
33 return err ? err : header.e_type;
36 uint32_t get_binary_type(const char *path)
38 int type = elf_type(path);
42 return BINARY_TYPE_PIE;
44 return BINARY_TYPE_NO_PIE;
46 return BINARY_TYPE_UNKNOWN;