about summary refs log tree commit diff stats
path: root/src/tools
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-07-12 22:17:50 +0200
committerptitSeb <sebastien.chev@gmail.com>2021-07-12 22:17:50 +0200
commit3d656b500833bc3f411f89a4321c6d1ff312be93 (patch)
tree43b7e72517310d3d0f3677c8e8b00ab040b371aa /src/tools
parentd84afba7c86b9bef1083534b37fb40ad758c8486 (diff)
downloadbox64-3d656b500833bc3f411f89a4321c6d1ff312be93.tar.gz
box64-3d656b500833bc3f411f89a4321c6d1ff312be93.zip
Fixed ELF Signature detection
Diffstat (limited to 'src/tools')
-rwxr-xr-xsrc/tools/fileutils.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/tools/fileutils.c b/src/tools/fileutils.c
index fa57cd69..fe927398 100755
--- a/src/tools/fileutils.c
+++ b/src/tools/fileutils.c
@@ -17,6 +17,8 @@
 
 static const char* x86sign = "\x7f" "ELF" "\x01" "\x01" "\x01" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x02" "\x00" "\x03" "\x00";
 static const char* x64sign = "\x7f" "ELF" "\x02" "\x01" "\x01" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x02" "\x00" "\x3e" "\x00";
+static const char* x86lib  = "\x7f" "ELF" "\x01" "\x01" "\x01" "\x03" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x03" "\x00" "\x03" "\x00";
+static const char* x64lib  = "\x7f" "ELF" "\x02" "\x01" "\x01" "\x03" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x03" "\x00" "\x3e" "\x00";
 
 int FileExist(const char* filename, int flags)
 {
@@ -66,14 +68,17 @@ int FileIsX64ELF(const char* filename)
     FILE *f = fopen(filename, "rb");
     if(!f)
         return 0;
-    char head[sizeof(*x64sign)] = {0};
-    int sz = fread(head, sizeof(*x64sign), 1, f);
+    char head[20] = {0};
+    int sz = fread(head, 20, 1, f);
     if(sz!=1) {
         fclose(f);
         return 0;
     }
     fclose(f);
-    if(memcmp(head, x64sign, sizeof(*x64sign))==0)
+    if(memcmp(head, x64sign, 20)==0)
+        return 1;
+    head[7] = x64lib[7];   // this one changes
+    if(memcmp(head, x64lib, 20)==0)
         return 1;
     return 0;
 }
@@ -83,14 +88,17 @@ int FileIsX86ELF(const char* filename)
     FILE *f = fopen(filename, "rb");
     if(!f)
         return 0;
-    char head[sizeof(*x86sign)] = {0};
-    int sz = fread(head, sizeof(*x86sign), 1, f);
+    char head[20] = {0};
+    int sz = fread(head, 20, 1, f);
     if(sz!=1) {
         fclose(f);
         return 0;
     }
     fclose(f);
-    if(memcmp(head, x86sign, sizeof(*x86sign))==0)
+    if(memcmp(head, x86sign, 20)==0)
+        return 1;
+    head[7] = x64lib[7];
+    if(memcmp(head, x86lib, 20)==0)
         return 1;
     return 0;
 }