int gelf_update_ehdr(Elf *elf, GElf_Ehdr *src) { char *tmp; if (!elf || !src) { return 0; } elf_assert(elf->e_magic == ELF_MAGIC); tmp = _elf_getehdr(elf, elf->e_class); if (!tmp) { return 0; } if (elf->e_class == ELFCLASS64) { *(Elf64_Ehdr*)tmp = *src; } else if (elf->e_class == ELFCLASS32) { Elf32_Ehdr *dst = (Elf32_Ehdr*)tmp; memcpy(dst->e_ident, src->e_ident, EI_NIDENT); check_and_copy(Elf32_Half, dst, src, e_type, 0); check_and_copy(Elf32_Half, dst, src, e_machine, 0); check_and_copy(Elf32_Word, dst, src, e_version, 0); check_and_copy(Elf32_Addr, dst, src, e_entry, 0); check_and_copy(Elf32_Off, dst, src, e_phoff, 0); check_and_copy(Elf32_Off, dst, src, e_shoff, 0); check_and_copy(Elf32_Word, dst, src, e_flags, 0); check_and_copy(Elf32_Half, dst, src, e_ehsize, 0); check_and_copy(Elf32_Half, dst, src, e_phentsize, 0); check_and_copy(Elf32_Half, dst, src, e_phnum, 0); check_and_copy(Elf32_Half, dst, src, e_shentsize, 0); check_and_copy(Elf32_Half, dst, src, e_shnum, 0); check_and_copy(Elf32_Half, dst, src, e_shstrndx, 0); } else if (valid_class(elf->e_class)) { seterr(ERROR_UNIMPLEMENTED); return 0; } else { seterr(ERROR_UNKNOWN_CLASS); return 0; } return 1; }
Elf64_Ehdr* elf64_getehdr(Elf *elf) { return (Elf64_Ehdr*)_elf_getehdr(elf, ELFCLASS64); }
Elf32_Ehdr* elf32_getehdr(Elf *elf) { return (Elf32_Ehdr*)_elf_getehdr(elf, ELFCLASS32); }