blob: 8bb93a39922052f4ee484a96b9956b886ffbe996 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <string.h>
#include <libelfu/libelfu.h>
Elf_Scn* elfu_eScnByName(Elf *e, char *name)
{
size_t shstrndx;
Elf_Scn *scn;
if (elf_getshdrstrndx(e, &shstrndx) != 0) {
return NULL;
}
scn = elf_getscn(e, 1);
while (scn) {
GElf_Shdr shdr;
char *curname;
if (gelf_getshdr(scn, &shdr) != &shdr) {
return NULL;
}
/* elf_strptr returns NULL if there was an error */
curname = elf_strptr(e, shstrndx, shdr.sh_name);
/* strcmp... but we really have no bounds on the lengths here */
if (!strcmp(curname, name)) {
return scn;
}
scn = elf_nextscn(e, scn);
}
return NULL;
}
|