Print ELF header/segments/sections
[centaur.git] / src / lookup / section-name.c
1 #include <libelf.h>
2 #include <gelf.h>
3
4 #include <libelfu/libelfu.h>
5
6
7 char* elfu_sectionName(Elf *e, Elf_Scn *scn)
8 {
9   size_t shstrndx;
10   GElf_Shdr shdr;
11
12   if (elf_getshdrstrndx(e, &shstrndx) != 0) {
13     return NULL;
14   }
15
16   if (gelf_getshdr(scn, &shdr) != &shdr) {
17     return NULL;
18   }
19
20   /* elf_strptr returns NULL if there was an error */
21   return elf_strptr(e, shstrndx, shdr.sh_name);
22 }