1 #include <stdlib.h>
2 #include <common.h>
3 #include <debug.h>
4
map_over_sections(Elf * elf,section_match_fn_t match,void * user_data)5 void map_over_sections(Elf *elf,
6 section_match_fn_t match,
7 void *user_data)
8 {
9 Elf_Scn* section = NULL;
10 while ((section = elf_nextscn(elf, section)) != NULL) {
11 if (match(elf, section, user_data))
12 return;
13 }
14 }
15
map_over_segments(Elf * elf,segment_match_fn_t match,void * user_data)16 void map_over_segments(Elf *elf,
17 segment_match_fn_t match,
18 void *user_data)
19 {
20 Elf32_Ehdr *ehdr;
21 Elf32_Phdr *phdr;
22 int index;
23
24 ehdr = elf32_getehdr(elf);
25 phdr = elf32_getphdr(elf);
26
27 INFO("Scanning over %d program segments...\n",
28 ehdr->e_phnum);
29
30 for (index = ehdr->e_phnum; index; index--) {
31 if (match(elf, phdr++, user_data))
32 return;
33 }
34 }
35
36