int elf_getshstrtab(const char *, size_t, const char **, size_t *);
int elf_getsymtab(const char *, const char *, size_t,
const Elf_Sym **, size_t *);
-int elf_getstrtab(const char *, const char *, size_t,
- const char **, size_t *);
+int elf_getsection(const char *, const char *, const char *,
+ size_t, const char **, size_t *);
#ifdef ZLIB
char *decompress(const char *, size_t, off_t);
warnx("symbol table not found");
/* Find string table location and size. */
- if (elf_getstrtab(p, shstrtab, shstrtabsize, &strtab, &strtabsize))
+ if (elf_getsection(p, ELF_STRTAB, shstrtab, shstrtabsize, &strtab, &strtabsize))
warnx("string table not found");
/* Find CTF section and dump it. */
}
int
-elf_getstrtab(const char *p, const char *shstrtab, size_t shstrtabsize,
- const char **strtab, size_t *strtabsize)
+elf_getsection(const char *p, const char *sname, const char *shstrtab,
+ size_t shstrtabsize, const char **sdata, size_t *ssize)
{
Elf_Ehdr *eh = (Elf_Ehdr *)p;
Elf_Shdr *sh;
for (i = 0; i < eh->e_shnum; i++) {
sh = (Elf_Shdr *)(p + eh->e_shoff + i * eh->e_shentsize);
- if (sh->sh_type != SHT_STRTAB)
- continue;
-
if ((sh->sh_link >= eh->e_shnum) ||
(sh->sh_name >= shstrtabsize))
continue;
- if (strncmp(shstrtab + sh->sh_name, ELF_STRTAB,
- strlen(ELF_STRTAB)) == 0) {
- if (strtab != NULL)
- *strtab = p + sh->sh_offset;
- if (strtabsize != NULL)
- *strtabsize = sh->sh_size;
+ if (strncmp(shstrtab + sh->sh_name, sname,
+ strlen(sname)) == 0) {
+ if (sdata != NULL)
+ *sdata = p + sh->sh_offset;
+ if (ssize != NULL)
+ *ssize = sh->sh_size;
return 0;
}