summaryrefslogtreecommitdiff
path: root/src/copy/elf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/copy/elf.c')
-rw-r--r--src/copy/elf.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/copy/elf.c b/src/copy/elf.c
new file mode 100644
index 0000000..445f98c
--- /dev/null
+++ b/src/copy/elf.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+#include <libelf.h>
+#include <gelf.h>
+
+#include <libelfu/libelfu.h>
+
+
+void elfu_copyEhdr(Elf *eo, Elf *ei);
+void elfu_copySections(Elf *eo, Elf *ei);
+void elfu_copySegments1(Elf *eo, Elf *ei);
+void elfu_copySegments2(Elf *eo, Elf *ei);
+
+
+void elfu_copyElf(Elf *eo, Elf *ei)
+{
+ elfu_copyEhdr(eo, ei);
+ elfu_copySections(eo, ei);
+ elfu_copySegments1(eo, ei);
+
+ /* Calculate file structure so we have section offsets */
+ if (elf_update(eo, ELF_C_NULL) < 0) {
+ fprintf(stderr, "elf_update(NULL) failed: %s\n", elf_errmsg(-1));
+ }
+
+ /* Update the segment offsets and lengths */
+ elfu_copySegments2(eo, ei);
+
+ elfu_fixupPhdrSelfRef(eo);
+}