diff options
author | norly <ny-git@enpas.org> | 2013-05-30 04:01:51 +0100 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2013-05-30 04:36:39 +0100 |
commit | 4addee4bda6064926b24cd1ae929303003bd9ff1 (patch) | |
tree | 10bad1be5ff2f71981fe87e1c43e171e94dacc8a /src/model/section-in-segment.c | |
parent | eb5a1daba781013ccf168b95510d0f67f0b9c946 (diff) |
Redesign data structures, make basic reladd work.newparser
The memory ELF model is now a tree structure:
ELF +--> PHDRs +--> PHDR +--> Section
| | +--> Section
| | ...
| | \--> Section
| |
| +--> PHDR +--> Section
| | ...
| ...
|
\--> Orphaned sections +--> Section
...
\--> Section
This effectively introduces semantics into the binary blob we are
editing, and allows us to re-layout its contents much more easily
while keeping as close as possible to what is assumed to be the
original semantics.
As a side-effect, a first meta-function had to be introduced
(elfu_mScnForall) in order to traverse all leaves of the tree.
Much old code has been removed given the leaner environment
available now, and automated insertion of .text and .data sections
from object files into executables now works. However nothing else
is inserted (such as string tables or .bss) and no relocation takes
place yet.
Diffstat (limited to 'src/model/section-in-segment.c')
-rw-r--r-- | src/model/section-in-segment.c | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/src/model/section-in-segment.c b/src/model/section-in-segment.c deleted file mode 100644 index 0e513e2..0000000 --- a/src/model/section-in-segment.c +++ /dev/null @@ -1,56 +0,0 @@ -#include <assert.h> -#include <libelf/gelf.h> -#include <libelfu/libelfu.h> - - -/* - * Returns the first section beginning in the segment. - * - * Since sections have to be in the file in mapping order to load them - * as a continuous segment, we only have to search by start offset. - */ -ElfuScn* elfu_mScnFirstInSegment(ElfuElf *me, ElfuPhdr *mp) -{ - ElfuScn *ms; - - assert(me); - assert(mp); - - CIRCLEQ_FOREACH(ms, &me->scnList, elem) { - if ((ms->shdr.sh_offset >= mp->phdr.p_offset) - && (ms->shdr.sh_offset < mp->phdr.p_offset + mp->phdr.p_filesz)) { - return ms; - } - } - - return NULL; -} - - - -/* - * Returns the last section ending in the segment. - * - * Since sections have to be in the file in mapping order to load them - * as a continuous segment, we only have to search by end offset. - */ -ElfuScn* elfu_mScnLastInSegment(ElfuElf *me, ElfuPhdr *mp) -{ - ElfuScn *last = NULL; - ElfuScn *ms; - - assert(me); - assert(mp); - - CIRCLEQ_FOREACH(ms, &me->scnList, elem) { - /* Get section size on disk - for NOBITS sections that is 0 bytes. */ - size_t size = SCNFILESIZE(&ms->shdr); - - if (((ms->shdr.sh_offset + size >= mp->phdr.p_offset) - && (ms->shdr.sh_offset + size <= mp->phdr.p_offset + mp->phdr.p_filesz))) { - last = ms; - } - } - - return last; -} |