I want to get the full contents of any sections in an ELF file,
I can get the name of the content with this code:
int fd;
int counter;
int filesize;
void *data;
char *strtab;
Elf64_Ehdr *elf;
Elf64_Shdr *shdr;
counter = 0;
fd = open(av[1], O_RDONLY);
if (fd == -1) {
perror("open : ");
return (84);
}
filesize = lseek(fd, 0, SEEK_END);
data = mmap(NULL, filesize, PROT_READ, MAP_SHARED, fd, 0);
if (data != NULL) {
elf = (Elf64_Ehdr *)(data);
shdr = (Elf64_Shdr *)(data + elf->e_shoff);
strtab = (char *)(data + shdr[elf->e_shstrndx].sh_offset);
while(counter < elf->e_shnum) {
printf("Contents of section %s:\n", &strtab[shdr[counter].sh_name]);
counter ++;
}
return (EXIT_SUCCESS);
}
perror("mmap : ");
return (EXIT_FAILURE);
I found that the shdr
structure contain many pieces of information but I want the information given by the objdump -s a.out
command and I can’t find the structure that gives all the information.
Can you help me to find a lead or a name of a structure where I can find this information, please?