From d217921268e5b2d9e38023c25e55dc315b8e3263 Mon Sep 17 00:00:00 2001 From: norly Date: Sat, 1 Jun 2013 17:42:36 +0100 Subject: Basic 32-bit SYMTAB and REL (not RELA) support --- src/model/section.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'src/model/section.c') diff --git a/src/model/section.c b/src/model/section.c index 4b8b230..a96377c 100644 --- a/src/model/section.c +++ b/src/model/section.c @@ -5,7 +5,7 @@ /* Meta-functions */ -int elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2) +void* elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2) { ElfuPhdr *mp; ElfuScn *ms; @@ -18,7 +18,7 @@ int elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2) } CIRCLEQ_FOREACH(ms, &mp->childScnList, elemChildScn) { - int rv = f(me, ms, aux1, aux2); + void *rv = f(me, ms, aux1, aux2); if (rv) { return rv; @@ -27,14 +27,14 @@ int elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2) } CIRCLEQ_FOREACH(ms, &me->orphanScnList, elemChildScn) { - int rv = f(me, ms, aux1, aux2); + void *rv = f(me, ms, aux1, aux2); if (rv) { return rv; } } - return 0; + return NULL; } @@ -42,18 +42,19 @@ int elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2) /* Counting */ -static int subCounter(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2) +static void* subCounter(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2) { size_t *i = (size_t*)aux1; ElfuScn *otherScn = (ElfuScn*)aux2; if (ms == otherScn) { - return 1; + return ms; } *i += 1; - return 0; + /* Continue */ + return NULL; } @@ -70,7 +71,7 @@ size_t elfu_mScnCount(ElfuElf *me) } -/* Returns the section index equivalent to the model flattened to ELF */ +/* Returns the index a section would have in the flattened ELF */ size_t elfu_mScnIndex(ElfuElf *me, ElfuScn *ms) { /* NULL section *is* counted */ @@ -87,6 +88,29 @@ size_t elfu_mScnIndex(ElfuElf *me, ElfuScn *ms) } +static void* subOldscn(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2) +{ + ElfuScn *otherScn = (ElfuScn*)aux1; + (void)aux2; + + if (ms->oldptr == otherScn) { + return ms; + } + + /* Continue */ + return NULL; +} + +/* Returns the section with oldscn == oldscn */ +ElfuScn* elfu_mScnByOldscn(ElfuElf *me, ElfuScn *oldscn) +{ + assert(me); + assert(oldscn); + + return elfu_mScnForall(me, subOldscn, oldscn, NULL); +} + + /* Convenience */ @@ -108,7 +132,7 @@ char* elfu_mScnName(ElfuElf *me, ElfuScn *ms) } -static int subScnsToArray(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2) +static void* subScnsToArray(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2) { ElfuScn **arr = (ElfuScn**)aux1; size_t *i = (size_t*)aux2; @@ -116,7 +140,8 @@ static int subScnsToArray(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2) arr[(*i)] = ms; *i += 1; - return 0; + /* Continue */ + return NULL; } static int cmpScnOffs(const void *ms1, const void *ms2) -- cgit v1.2.3