about summary refs log tree commit diff stats
path: root/src/tools/fileutils.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-07-12 13:43:00 -0500
committerptitSeb <sebastien.chev@gmail.com>2021-07-12 13:43:00 -0500
commita66bb7453b335975ae0f55a96e3f9665139d8024 (patch)
tree55d579ac559eb10542e20e514fc7660d461d8df6 /src/tools/fileutils.c
parent5406a040fbf51bec372612a147aea1f80acf97be (diff)
downloadbox64-a66bb7453b335975ae0f55a96e3f9665139d8024.tar.gz
box64-a66bb7453b335975ae0f55a96e3f9665139d8024.zip
Use box86 to launch x86 binary (if box86 is present in same folder as box64)
Diffstat (limited to 'src/tools/fileutils.c')
-rwxr-xr-xsrc/tools/fileutils.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/tools/fileutils.c b/src/tools/fileutils.c
index 18b8dc4d..fa57cd69 100755
--- a/src/tools/fileutils.c
+++ b/src/tools/fileutils.c
@@ -15,6 +15,7 @@
 #include "debug.h"
 #include "fileutils.h"
 
+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";
 
 int FileExist(const char* filename, int flags)
@@ -77,6 +78,23 @@ int FileIsX64ELF(const char* filename)
     return 0;
 }
 
+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);
+    if(sz!=1) {
+        fclose(f);
+        return 0;
+    }
+    fclose(f);
+    if(memcmp(head, x86sign, sizeof(*x86sign))==0)
+        return 1;
+    return 0;
+}
+
 #if defined(RPI) || defined(RK3399) || defined(RK3326)
 void sanitize_mojosetup_gtk_background()
 {