summaryrefslogtreecommitdiff
path: root/include/libelfu
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2013-05-30 04:01:51 +0100
committernorly <ny-git@enpas.org>2013-05-30 04:36:39 +0100
commit4addee4bda6064926b24cd1ae929303003bd9ff1 (patch)
tree10bad1be5ff2f71981fe87e1c43e171e94dacc8a /include/libelfu
parenteb5a1daba781013ccf168b95510d0f67f0b9c946 (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 'include/libelfu')
-rw-r--r--include/libelfu/generic.h4
-rw-r--r--include/libelfu/libelfu.h1
-rw-r--r--include/libelfu/modelops.h26
-rw-r--r--include/libelfu/modeltypes.h46
-rw-r--r--include/libelfu/types.h41
5 files changed, 53 insertions, 65 deletions
diff --git a/include/libelfu/generic.h b/include/libelfu/generic.h
index 6a06634..c8a9c79 100644
--- a/include/libelfu/generic.h
+++ b/include/libelfu/generic.h
@@ -3,6 +3,10 @@
#include <libelf/gelf.h>
+
+#define ROUNDUP(x, align) ((x) + ((align) - ((x) % (align))) % (align))
+
+
#define OFFS_END(off, sz) ((off) + (sz))
#define OVERLAPPING(off1, sz1, off2, sz2) \
diff --git a/include/libelfu/libelfu.h b/include/libelfu/libelfu.h
index cc55282..328a75d 100644
--- a/include/libelfu/libelfu.h
+++ b/include/libelfu/libelfu.h
@@ -6,7 +6,6 @@
#include <libelfu/generic.h>
#include <libelfu/elfops.h>
-#include <libelfu/modeltypes.h>
#include <libelfu/modelops.h>
#include <libelfu/debug.h>
diff --git a/include/libelfu/modelops.h b/include/libelfu/modelops.h
index 31a4ed9..9495aca 100644
--- a/include/libelfu/modelops.h
+++ b/include/libelfu/modelops.h
@@ -4,19 +4,19 @@
#include <elf.h>
#include <libelf/gelf.h>
-#include <libelfu/modeltypes.h>
+#include <libelfu/types.h>
-size_t elfu_mScnIndex(ElfuElf *me, ElfuScn *ms);
-size_t elfu_mCountScns(ElfuElf *me);
-size_t elfu_mCountPhdrs(ElfuElf *me);
+size_t elfu_mPhdrCount(ElfuElf *me);
-char* elfu_mScnName(ElfuElf *me, ElfuScn *ms);
-ElfuScn* elfu_mScnFirstInSegment(ElfuElf *me, ElfuPhdr *mp);
-ElfuScn* elfu_mScnLastInSegment(ElfuElf *me, ElfuPhdr *mp);
+typedef int (SectionHandlerFunc)(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2);
+int elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2);
+size_t elfu_mScnCount(ElfuElf *me);
+size_t elfu_mScnIndex(ElfuElf *me, ElfuScn *ms);
+char* elfu_mScnName(ElfuElf *me, ElfuScn *ms);
+ElfuScn** elfu_mScnSortedByOffset(ElfuElf *me, size_t *count);
-ElfuScn* elfu_mScnByType(ElfuElf *me, Elf32_Word type);
int elfu_mCheck(ElfuElf *me);
@@ -31,16 +31,6 @@ void elfu_mDumpElf(ElfuElf *me);
ElfuElf* elfu_mFromElf(Elf *e);
void elfu_mToElf(ElfuElf *me, Elf *e);
-
- void elfu_mExpandNobits(ElfuElf *me, GElf_Off off);
-
-GElf_Xword elfu_mInsertSpaceBefore(ElfuElf *me, GElf_Off off, GElf_Xword size);
-GElf_Xword elfu_mInsertSpaceAfter(ElfuElf *me, GElf_Off off, GElf_Xword size);
-
-void elfu_mInsertScnInChainBefore(ElfuElf *me, ElfuScn *oldscn, ElfuScn *newscn);
-void elfu_mInsertScnInChainAfter(ElfuElf *me, ElfuScn *oldscn, ElfuScn *newscn);
-
-
void elfu_mReladd(ElfuElf *me, ElfuElf *mrel);
#endif
diff --git a/include/libelfu/modeltypes.h b/include/libelfu/modeltypes.h
deleted file mode 100644
index bea9322..0000000
--- a/include/libelfu/modeltypes.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef __LIBELFU_MODELTYPES_H__
-#define __LIBELFU_MODELTYPES_H__
-
-#include <sys/queue.h>
-
-#include <elf.h>
-#include <libelf/gelf.h>
-
-
-typedef struct ElfuScn {
- GElf_Shdr shdr;
-
- Elf_Data data;
-
- struct ElfuScn *linkptr;
- struct ElfuScn *infoptr;
-
- CIRCLEQ_ENTRY(ElfuScn) elemChildScn;
- CIRCLEQ_ENTRY(ElfuScn) elem;
-} ElfuScn;
-
-
-typedef struct ElfuPhdr {
- GElf_Phdr phdr;
-
- CIRCLEQ_HEAD(ChildScnList, ElfuScn) childScnList;
- CIRCLEQ_HEAD(ChildPhdrList, ElfuPhdr) childPhdrList;
-
- CIRCLEQ_ENTRY(ElfuPhdr) elemChildPhdr;
- CIRCLEQ_ENTRY(ElfuPhdr) elem;
-} ElfuPhdr;
-
-
-typedef struct {
- int elfclass;
- GElf_Ehdr ehdr;
-
- CIRCLEQ_HEAD(ScnList, ElfuScn) scnList;
- CIRCLEQ_HEAD(PhdrList, ElfuPhdr) phdrList;
- CIRCLEQ_HEAD(OrphanScnList, ElfuScn) orphanScnList;
-
- ElfuScn *shstrtab;
-} ElfuElf;
-
-
-#endif
diff --git a/include/libelfu/types.h b/include/libelfu/types.h
index a59efca..a06d470 100644
--- a/include/libelfu/types.h
+++ b/include/libelfu/types.h
@@ -1,6 +1,47 @@
#ifndef __LIBELFU_TYPES_H__
#define __LIBELFU_TYPES_H__
+#include <sys/queue.h>
+
+#include <elf.h>
+#include <libelf/gelf.h>
+
+
+typedef struct ElfuScn {
+ GElf_Shdr shdr;
+
+ Elf_Data data;
+
+ struct ElfuScn *linkptr;
+ struct ElfuScn *infoptr;
+
+ struct ElfuScn *oldptr;
+
+ CIRCLEQ_ENTRY(ElfuScn) elemChildScn;
+ CIRCLEQ_ENTRY(ElfuScn) elem;
+} ElfuScn;
+
+
+typedef struct ElfuPhdr {
+ GElf_Phdr phdr;
+
+ CIRCLEQ_HEAD(ChildScnList, ElfuScn) childScnList;
+ CIRCLEQ_HEAD(ChildPhdrList, ElfuPhdr) childPhdrList;
+
+ CIRCLEQ_ENTRY(ElfuPhdr) elemChildPhdr;
+ CIRCLEQ_ENTRY(ElfuPhdr) elem;
+} ElfuPhdr;
+
+
+typedef struct {
+ int elfclass;
+ GElf_Ehdr ehdr;
+
+ CIRCLEQ_HEAD(PhdrList, ElfuPhdr) phdrList;
+ CIRCLEQ_HEAD(OrphanScnList, ElfuScn) orphanScnList;
+
+ ElfuScn *shstrtab;
+} ElfuElf;
#endif