c - How can I get the symbol name in struct "Elf64_Rela" -


#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/mman.h> #include <errno.h> #include <fcntl.h> #include <elf.h>   elf64_rela *retab; elf64_rela *retab_end; elf64_ehdr *ehdr; elf64_shdr *shdr; char *strtab;  void elf_open(char *filename) {      int fd = open(filename, o_rdonly);     struct stat sbuf;     fstat(fd, &sbuf);     void *maddr = mmap(null, sbuf.st_size, prot_read, map_shared, fd, 0);     close(fd);       ehdr = maddr;     shdr = (elf64_shdr *)(maddr + ehdr->e_shoff);     (int = 0; < ehdr->e_shnum; i++)      {         if (shdr[i].sh_type == sht_rela)          {                retab = (elf64_rela *)(maddr + shdr[i].sh_offset);             retab_end = (elf64_rela *)((char *)retab + shdr[i].sh_size);             strtab = (char *)(maddr + shdr[shdr[i].sh_link].sh_offset);             break;         }     } }  int main() {     elf_open("lib1.so");     elf64_rela *p = retab;      while(p<retab_end)       {         printf("%x %d\n",p->r_offset,p->r_info);          p++;     } } 

this code .rela.dyn section . don't know hot symbol's name. know elf64_rela structure doesn't have name field. in 'symtab' section, can symbol name using &strtab[p->st_name]. how can do?

typedef struct {     elf64_addr r_offset;     elf64_xword r_info;     elf64_sxword r_addend; } elf64_rela; 

not relocations refer symbols, need check elf64_r_type (p->r_info) first. set of relocations have symbols architecture-specific.

for relocations have symbols, elf64_r_sym (p->r_info) should index of associated symbol in .dynsym section.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -