From 532b1697a60ed9a684b5f82b752208317aaaf1d6 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 8 Sep 2022 09:59:58 +0200 Subject: When running x86_64 bash, using x86_64 bash to run script automaticaly (for #402) --- src/tools/fileutils.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/tools') 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() { -- cgit 1.4.1