about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-03-01 18:02:26 +0100
committerptitSeb <sebastien.chev@gmail.com>2021-03-01 18:02:26 +0100
commita2a78a4edc2e82756d83daf8bbbe2ca26102af47 (patch)
tree5010536c8adda635f138ecb55da6c5e1b813b8e0 /src
parent4079491d5e003c424f1bfa2a3f682185cd0c54a7 (diff)
downloadbox64-a2a78a4edc2e82756d83daf8bbbe2ca26102af47.tar.gz
box64-a2a78a4edc2e82756d83daf8bbbe2ca26102af47.zip
Load elf in memory
Diffstat (limited to 'src')
-rwxr-xr-xsrc/elfs/elfloader.c2
-rwxr-xr-xsrc/include/elfloader.h4
-rwxr-xr-xsrc/main.c11
3 files changed, 14 insertions, 3 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c
index a8a3c928..ebb68138 100755
--- a/src/elfs/elfloader.c
+++ b/src/elfs/elfloader.c
@@ -278,7 +278,6 @@ void FreeElfMemory(elfheader_t* head)
     }
 }
 
-#if 0
 int LoadElfMemory(FILE* f, box64context_t* context, elfheader_t* head)
 {
     for (int i=0; i<head->numPHEntries; ++i) {
@@ -350,6 +349,7 @@ int ReloadElfMemory(FILE* f, box64context_t* context, elfheader_t* head)
     // TLS data are just a copy, no need to re-load it
     return 0;
 }
+#if 0
 int FindR386COPYRel(elfheader_t* h, const char* name, uintptr_t *offs, uint32_t** p)
 {
     if(!h)
diff --git a/src/include/elfloader.h b/src/include/elfloader.h
index 56a51c51..d8caa27b 100755
--- a/src/include/elfloader.h
+++ b/src/include/elfloader.h
@@ -22,8 +22,8 @@ const char* ElfName(elfheader_t* head);
 int CalcLoadAddr(elfheader_t* head);
 int AllocElfMemory(box64context_t* context, elfheader_t* head, int mainbin);
 void FreeElfMemory(elfheader_t* head);
-//int LoadElfMemory(FILE* f, box64context_t* context, elfheader_t* head);
-//int ReloadElfMemory(FILE* f, box64context_t* context, elfheader_t* head);
+int LoadElfMemory(FILE* f, box64context_t* context, elfheader_t* head);
+int ReloadElfMemory(FILE* f, box64context_t* context, elfheader_t* head);
 //int RelocateElf(lib_t *maplib, lib_t* local_maplib, elfheader_t* head);
 //int RelocateElfPlt(lib_t *maplib, lib_t* local_maplib, elfheader_t* head);
 //void CalcStack(elfheader_t* h, uint32_t* stacksz, int* stackalign);
diff --git a/src/main.c b/src/main.c
index c049a27d..1e513351 100755
--- a/src/main.c
+++ b/src/main.c
@@ -750,6 +750,17 @@ int main(int argc, const char **argv, const char **env) {
         FreeCollection(&ld_preload);
         return -1;
     }
+    // Load elf into memory
+    if(LoadElfMemory(f, my_context, elf_header)) {
+        printf_log(LOG_NONE, "Error: loading in memory elf %s\n", my_context->argv[0]);
+        fclose(f);
+        free_contextargv();
+        FreeBox64Context(&my_context);
+        FreeCollection(&ld_preload);
+        return -1;
+    }
+    // can close the file now
+    fclose(f);
 
 
     return 0;