Quantcast
Viewing all articles
Browse latest Browse all 22130

ELF: How to print the r_info field?

I want to list the name of all relocation entries which have the type R_X86_64_JUMP_SLOT. Here's what I have so far:

char *str = (char *) (mapped_file + dynstr->sh_offset);

Elf64_Rela *reloc_entry = (Elf64_Rela *) (mapped_file + rela_plt->sh_offset);

for (i = 0; i < rela_plt->sh_size / sizeof(Elf64_Rela); ++i)
{
       if (ELF64_R_TYPE(reloc_entry[i].r_info) == R_X86_64_JUMP_SLOT)
                printf("name: %s\n", str + ELF64_R_SYM(reloc_entry[i].r_info));

}

The ELF64_R_TYPE macro is working fine but I'm having problems retrieving the relocation name with ELF64_R_SYM.

readelf shows the relocations correctly:

Relocation section '.rela.plt' at offset 0x588 contains 3 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000004018  000200000007 R_X86_64_JUMP_SLO 0000000000000000 puts@GLIBC_2.2.5 + 0
000000004020  000300000007 R_X86_64_JUMP_SLO 0000000000000000 printf@GLIBC_2.2.5 + 0
000000004028  000600000007 R_X86_64_JUMP_SLO 0000000000000000 malloc@GLIBC_2.2.5 + 0

My code for some reason doesn't print the symbol name, instead it prints:

name: ibc.so.6
name: bc.so.6
name: so.6

what am I doing wrong?


Viewing all articles
Browse latest Browse all 22130

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>