Elf64_Shdr *libelf_sht_strtab(void *elf);
char *libelf_sectionname(Elf64_Shdr *section, Elf64_Shdr *strtab);
Elf64_Shdr *libelf_section_n(void *elf, int n);
-Elf64_Shdr *libelf_section(void *elf, int type);
+Elf64_Shdr *libelf_section(void *elf, unsigned int type);
int libelf_type(void *elf);
int libelf_iself(void *elf);
}
Elf64_Shdr *libelf_shdr(void *elf, int n) {
- return 0;
+ return (Elf64_Shdr*)(char *)elf + n;
}
Elf64_Shdr *libelf_sht_strtab(void *elf) {
return (Elf64_Shdr *)((char *)elf + hdr->e_shoff + n * hdr->e_shentsize);
}
-Elf64_Shdr *libelf_section(void *elf, int type) {
+Elf64_Shdr *libelf_section(void *elf, unsigned int type) {
int i;
Elf64_Ehdr *hdr;
Elf64_Shdr *shdr;
return NULL;
}
/* not at least the size of the elf header? */
- if (sbuf.st_size < sizeof(Elf64_Ehdr)) {
+ if ((size_t)sbuf.st_size < sizeof(Elf64_Ehdr)) {
close(elffd);
return NULL;
}
exit(6);
}
- Elf64_Shdr *dsect;
+ Elf64_Shdr *dsect = 0;
/* find program header table */
for (i = 0; i < hdr->e_phnum; i++) {
phdr = (Elf64_Phdr *)((char *)elf + hdr->e_phoff + i * hdr->e_phentsize);
dsect = (Elf64_Shdr *)((char *)elf + phdr->p_offset);
}
}
+ if (!dsect) {
+ /* no dsect, statically linked? */
+ exit(7);
+ }
+
dyn = (Elf64_Dyn *)((char *)elf + dsect->sh_offset);
if (!dyn) {
exit(9);