diff options
author | norly <ny-git@enpas.org> | 2013-02-23 15:41:35 +0000 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2013-02-23 15:42:42 +0000 |
commit | 5b7078265bb864ddec23162b2dfc5c02dacb0e1d (patch) | |
tree | f8973076c5f93c0e8e31d432b32a808c72bdb8db /src/elfops/first-section-in-segment.c | |
parent | 6f12fafdc4102a9b8c3ffee060cab48f50f4c37d (diff) |
Move ELF-related files together
Diffstat (limited to 'src/elfops/first-section-in-segment.c')
-rw-r--r-- | src/elfops/first-section-in-segment.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/elfops/first-section-in-segment.c b/src/elfops/first-section-in-segment.c new file mode 100644 index 0000000..58065a5 --- /dev/null +++ b/src/elfops/first-section-in-segment.c @@ -0,0 +1,36 @@ +#include <stdlib.h> + +#include <libelf.h> +#include <gelf.h> + +#include <libelfu/libelfu.h> + + +/* + * Returns the section that starts at the same point in the file as + * the segment AND is wholly contained in the memory image. + * + * If no section fits, NULL is returned. + */ +Elf_Scn* elfu_firstSectionInSegment(Elf *e, GElf_Phdr *phdr) +{ + Elf_Scn *scn; + + scn = elf_getscn(e, 1); + while (scn) { + GElf_Shdr shdr; + + if (gelf_getshdr(scn, &shdr) != &shdr) { + return NULL; + } + + if (shdr.sh_offset == phdr->p_offset + && elfu_segmentContainsSection(phdr, &shdr)) { + return scn; + } + + scn = elf_nextscn(e, scn); + } + + return NULL; +} |