#include "woody.h" int ident_error(void) { return wdy_error("file format not recognized (invalid ELF Ident)"); } int is_valid_elf_magic_number(char *ident) { return !ft_strncmp(ident, ELFMAG, SELFMAG); } int is_valid_arch(char arch) { return arch == ELFCLASS64 || arch == ELFCLASS32; } int is_valid_data_format(unsigned char data_format) { return data_format == ELFDATA2MSB || data_format == ELFDATA2LSB; } int is_valid_version(unsigned char version) { return version == EV_CURRENT; } int check_ident(t_map file) { char *ident = (char *)fetch(file, 0, EI_NIDENT); if (!ident) { return ident_error(); } if (!is_valid_elf_magic_number(ident) || !is_valid_arch(ident[EI_CLASS]) || !is_valid_data_format(ident[EI_DATA]) || !is_valid_version(ident[EI_VERSION])) { return ident_error(); } return RET_OK; }