about summary refs log tree commit diff stats
path: root/src/tools
diff options
context:
space:
mode:
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;
 }