From eb5a1daba781013ccf168b95510d0f67f0b9c946 Mon Sep 17 00:00:00 2001 From: norly Date: Tue, 28 May 2013 23:34:51 +0100 Subject: [PATCH] Implement orphaned sections Orphaned sections are not (fully) included in any LOAD PHDR and can thus be moved and stripped at will without changing the memory image of the program. --- include/libelfu/modeltypes.h | 1 + src/model/dump.c | 9 +++++++++ src/model/fromFile.c | 3 +++ 3 files changed, 13 insertions(+) diff --git a/include/libelfu/modeltypes.h b/include/libelfu/modeltypes.h index e8a9c01..bea9322 100644 --- a/include/libelfu/modeltypes.h +++ b/include/libelfu/modeltypes.h @@ -37,6 +37,7 @@ typedef struct { CIRCLEQ_HEAD(ScnList, ElfuScn) scnList; CIRCLEQ_HEAD(PhdrList, ElfuPhdr) phdrList; + CIRCLEQ_HEAD(OrphanScnList, ElfuScn) orphanScnList; ElfuScn *shstrtab; } ElfuElf; diff --git a/src/model/dump.c b/src/model/dump.c index 882ba0a..67a498a 100644 --- a/src/model/dump.c +++ b/src/model/dump.c @@ -209,6 +209,15 @@ void elfu_mDumpElf(ElfuElf *me) ELFU_INFO("\n"); + ELFU_INFO("Orphaned sections:\n"); + CIRCLEQ_FOREACH(ms, &me->orphanScnList, elemChildScn) { + ELFU_INFO(" * %-17s @ %8jx\n", + elfu_mScnName(me, ms), + ms->shdr.sh_addr); + } + ELFU_INFO("\n"); + + ELFU_INFO("Sections:\n"); ELFU_INFO(" # Name sh_type sh_addr sh_offset sh_size ES Fl Al sh_link sh_info \n"); ELFU_INFO(" | | | | | | | | | | \n"); diff --git a/src/model/fromFile.c b/src/model/fromFile.c index fd6aba0..cb09352 100644 --- a/src/model/fromFile.c +++ b/src/model/fromFile.c @@ -167,6 +167,7 @@ ElfuElf* elfu_mFromElf(Elf *e) /* General stuff */ CIRCLEQ_INIT(&me->scnList); CIRCLEQ_INIT(&me->phdrList); + CIRCLEQ_INIT(&me->orphanScnList); me->shstrtab = NULL; me->elfclass = gelf_getclass(e); @@ -286,6 +287,8 @@ ElfuElf* elfu_mFromElf(Elf *e) if (parent) { CIRCLEQ_INSERT_TAIL(&parent->childScnList, ms, elemChildScn); + } else { + CIRCLEQ_INSERT_TAIL(&me->orphanScnList, ms, elemChildScn); } } -- 2.30.2