summaryrefslogtreecommitdiff
path: root/src/copy/ehdr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/copy/ehdr.c')
-rw-r--r--src/copy/ehdr.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/copy/ehdr.c b/src/copy/ehdr.c
new file mode 100644
index 0000000..b7c6232
--- /dev/null
+++ b/src/copy/ehdr.c
@@ -0,0 +1,52 @@
+#include <stdio.h>
+
+#include <libelf.h>
+#include <gelf.h>
+
+#include <libelfu/libelfu.h>
+
+
+void elfu_copyEhdr(Elf *eo, Elf *ei)
+{
+ int elfclass;
+ GElf_Ehdr ehdr, ehdrOut;
+
+ elfclass = gelf_getclass(ei);
+ if (elfclass == ELFCLASSNONE) {
+ fprintf(stderr, "getclass() failed: %s\n", elf_errmsg(-1));
+ }
+
+ if (!gelf_getehdr(ei, &ehdr)) {
+ fprintf(stderr, "gelf_getehdr() failed: %s\n", elf_errmsg(-1));
+ return;
+ }
+
+ if (!gelf_newehdr(eo, elfclass)) {
+ fprintf(stderr, "gelf_newehdr() failed: %s\n", elf_errmsg(-1));
+ }
+
+ if (!gelf_getehdr(ei, &ehdrOut)) {
+ fprintf(stderr, "gelf_getehdr() failed: %s\n", elf_errmsg(-1));
+ return;
+ }
+
+ ehdrOut.e_ident[EI_DATA] = ehdr.e_ident[EI_DATA];
+ ehdrOut.e_type = ehdr.e_type;
+ ehdrOut.e_machine = ehdr.e_machine;
+ ehdrOut.e_version = ehdr.e_version;
+ ehdrOut.e_entry = ehdr.e_entry; // FIXME
+ /* e_phoff */
+ /* e_shoff */
+ ehdrOut.e_flags = ehdr.e_flags;
+ /* e_ehsize */
+ /* e_phentsize */
+ /* e_phnum */
+ /* e_shentsize */
+ /* s_shnum */
+ ehdrOut.e_shstrndx = ehdr.e_shstrndx; // FIXME
+
+
+ if (!gelf_update_ehdr(eo, &ehdrOut)) {
+ fprintf(stderr, "gelf_update_ehdr() failed: %s\n", elf_errmsg(-1));
+ }
+}