diff options
author | norly <ny-git@enpas.org> | 2013-06-20 23:47:01 +0100 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2013-06-21 00:42:22 +0100 |
commit | e68a6c6cc16279c72e270daae0548ea7c0f11c6e (patch) | |
tree | 1bb268b01d557bf64744c1a0794acea2fad9286b /src/libelfu/modelops | |
parent | fb56823e86ceff5e340a691ef2a6d5df81e02fac (diff) |
LOAD PHDRs at top level, others as children. mPhdrForall().
The reference binaries had to be updated as PHDRs are now reordered.
Diffstat (limited to 'src/libelfu/modelops')
-rw-r--r-- | src/libelfu/modelops/fromFile.c | 2 | ||||
-rw-r--r-- | src/libelfu/modelops/toFile.c | 37 |
2 files changed, 18 insertions, 21 deletions
diff --git a/src/libelfu/modelops/fromFile.c b/src/libelfu/modelops/fromFile.c index e19df7b..c4e8c45 100644 --- a/src/libelfu/modelops/fromFile.c +++ b/src/libelfu/modelops/fromFile.c @@ -340,6 +340,8 @@ ElfuElf* elfu_mFromElf(Elf *e) if (mp->phdr.p_vaddr <= mp2->phdr.p_vaddr && OFFS_END(mp2->phdr.p_vaddr, mp2->phdr.p_memsz) <= OFFS_END(mp->phdr.p_vaddr, mp->phdr.p_memsz)) { + /* Remove from the main list so only LOADs remain there */ + CIRCLEQ_REMOVE(&me->phdrList, mp2, elem); CIRCLEQ_INSERT_TAIL(&mp->childPhdrList, mp2, elemChildPhdr); } } diff --git a/src/libelfu/modelops/toFile.c b/src/libelfu/modelops/toFile.c index ff01390..b42bc08 100644 --- a/src/libelfu/modelops/toFile.c +++ b/src/libelfu/modelops/toFile.c @@ -4,34 +4,22 @@ #include <libelfu/libelfu.h> -static void modelToPhdrs(ElfuElf *me, Elf *e) +static void* modelToPhdr(ElfuElf *me, ElfuPhdr *mp, void *aux1, void *aux2) { - ElfuPhdr *mp; - size_t i; + size_t *i = (size_t*)aux1; + Elf *e = (Elf*)aux2; - /* Count PHDRs */ - i = 0; - CIRCLEQ_FOREACH(mp, &me->phdrList, elem) { - i++; + if (!gelf_update_phdr (e, *i, &mp->phdr)) { + ELFU_WARNELF("gelf_update_phdr"); } - if (!gelf_newphdr(e, i)) { - ELFU_WARNELF("gelf_newphdr"); - } - - /* Copy PHDRs */ - i = 0; - CIRCLEQ_FOREACH(mp, &me->phdrList, elem) { - if (!gelf_update_phdr (e, i, &mp->phdr)) { - ELFU_WARNELF("gelf_update_phdr"); - } + *i += 1; - i++; - } + /* Continue */ + return NULL; } - static void* modelToSection(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2) { Elf_Scn *scnOut; @@ -82,6 +70,8 @@ static void* modelToSection(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2) void elfu_mToElf(ElfuElf *me, Elf *e) { + size_t i = 0; + if (me->symtab) { elfu_mSymtabFlatten(me); } @@ -114,8 +104,13 @@ void elfu_mToElf(ElfuElf *me, Elf *e) /* PHDRs */ - modelToPhdrs(me, e); + if (!gelf_newphdr(e, elfu_mPhdrCount(me))) { + ELFU_WARNELF("gelf_newphdr"); + } + + elfu_mPhdrForall(me, modelToPhdr, &i, e); + /* Done */ elf_flagelf(e, ELF_C_SET, ELF_F_DIRTY); } |