about summary refs log tree commit diff stats
path: root/src/tools/fileutils.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2022-09-08 09:59:58 +0200
committerptitSeb <sebastien.chev@gmail.com>2022-09-08 09:59:58 +0200
commit532b1697a60ed9a684b5f82b752208317aaaf1d6 (patch)
treeccb81b39e9f4e09e1c8f73e2e14d5c000aa93bc2 /src/tools/fileutils.c
parenta3f63a12f9102794ce1d94c972064f10a25e944b (diff)
downloadbox64-532b1697a60ed9a684b5f82b752208317aaaf1d6.tar.gz
box64-532b1697a60ed9a684b5f82b752208317aaaf1d6.zip
When running x86_64 bash, using x86_64 bash to run script automaticaly (for #402)
Diffstat (limited to 'src/tools/fileutils.c')
-rwxr-xr-xsrc/tools/fileutils.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/tools/fileutils.c b/src/tools/fileutils.c
index 80a0ec60..06299fc0 100755
--- a/src/tools/fileutils.c
+++ b/src/tools/fileutils.c
@@ -15,10 +15,10 @@
 #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";
 static const char* x86lib  = "\x7f" "ELF" "\x01" "\x01" "\x01" "\x03" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x02" "\x00" "\x03" "\x00";
 static const char* x64lib  = "\x7f" "ELF" "\x02" "\x01" "\x01" "\x03" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x00" "\x02" "\x00" "\x3e" "\x00";
+static const char* bashsign= "#!/bin/bash";
+static const char* shsign  = "#!/bin/sh";
 
 int FileExist(const char* filename, int flags)
 {
@@ -99,6 +99,24 @@ int FileIsX86ELF(const char* filename)
     return 0;
 }
 
+int FileIsShell(const char* filename)
+{
+    FILE *f = fopen(filename, "rb");
+    if(!f)
+        return 0;
+    char head[20] = {0};
+    int sz = fread(head, strlen(bashsign), 1, f);
+    fclose(f);
+    if(sz!=1) {
+        return 0;
+    if(memcmp(head, bashsign, strlen(bashsign))==0)
+        return 1;
+    }
+    if(memcmp(head, shsign, strlen(shsign))==0)
+        return 1;
+    return 0;
+}
+
 #if defined(RPI) || defined(RK3399) || defined(RK3326)
 void sanitize_mojosetup_gtk_background()
 {