1 #include <errno.h> 2 #include <error.h> 3 #include <stdio.h> 4 #include <fcntl.h> 5 #include <unistd.h> 6 #include <libelf.h> 7 8 int 9 main (int argc __attribute__ ((unused)), char *argv[]) 10 { 11 int fd = open (argv[1], O_RDWR); 12 if (fd < 0) 13 error (2, errno, "open: %s", argv[1]); 14 15 if (elf_version (EV_CURRENT) == EV_NONE) 16 error (1, 0, "libelf version mismatch"); 17 18 Elf *elf = elf_begin (fd, ELF_C_RDWR_MMAP, NULL); 19 if (elf == NULL) 20 error (1, 0, "elf_begin: %s", elf_errmsg (-1)); 21 22 if (elf_update (elf, ELF_C_WRITE) < 0) 23 error (1, 0, "elf_update: %s", elf_errmsg (-1)); 24 25 elf_end (elf); 26 close (fd); 27 28 return 0; 29 } 30