summaryrefslogtreecommitdiffstats
path: root/tools/soslim/common.c
blob: b90cf419944477208e01b7d23c841c03f98362d3 (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 <stdlib.h>
#include <common.h>
#include <debug.h>

void map_over_sections(Elf *elf, 
                       section_match_fn_t match,
                       void *user_data)
{
    Elf_Scn* section = NULL;
    while ((section = elf_nextscn(elf, section)) != NULL) {
        if (match(elf, section, user_data))
            return;
    }
}   

void map_over_segments(Elf *elf, 
                       segment_match_fn_t match, 
                       void *user_data)
{
    Elf32_Ehdr *ehdr; 
    Elf32_Phdr *phdr; 
    int index;

    ehdr = elf32_getehdr(elf);
    phdr = elf32_getphdr(elf);

    INFO("Scanning over %d program segments...\n", 
         ehdr->e_phnum);

    for (index = ehdr->e_phnum; index; index--) {
        if (match(elf, phdr++, user_data))
            return;
    }
}