diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-07-12 22:17:50 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-07-12 22:17:50 +0200 |
| commit | 3d656b500833bc3f411f89a4321c6d1ff312be93 (patch) | |
| tree | 43b7e72517310d3d0f3677c8e8b00ab040b371aa /src | |
| parent | d84afba7c86b9bef1083534b37fb40ad758c8486 (diff) | |
| download | box64-3d656b500833bc3f411f89a4321c6d1ff312be93.tar.gz box64-3d656b500833bc3f411f89a4321c6d1ff312be93.zip | |
Fixed ELF Signature detection
Diffstat (limited to 'src')
| -rwxr-xr-x | src/tools/fileutils.c | 20 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibc.c | 8 |
2 files changed, 18 insertions, 10 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; } diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 301062f0..9049851a 100755 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -1547,7 +1547,7 @@ EXPORT int32_t my_execv(x64emu_t* emu, const char* path, char* const argv[]) int self = isProcSelf(path, "exe"); int x64 = FileIsX64ELF(path); int x86 = my_context->box86path?FileIsX86ELF(path):0; - printf_log(LOG_DEBUG, "execv(\"%s\", %p) is x64=%d\n", path, argv, x64); + printf_log(LOG_DEBUG, "execv(\"%s\", %p) is x64=%d x86=%d\n", path, argv, x64, x86); #if 1 if (x64 || x86 || self) { int skip_first = 0; @@ -1560,7 +1560,7 @@ EXPORT int32_t my_execv(x64emu_t* emu, const char* path, char* const argv[]) newargv[0] = x86?emu->context->box86path:emu->context->box64path; memcpy(newargv+1, argv+skip_first, sizeof(char*)*(n+1)); if(self) newargv[1] = emu->context->fullpath; - printf_log(LOG_DEBUG, " => execv(\"%s\", %p [\"%s\", \"%s\", \"%s\"...:%d])\n", emu->context->box64path, newargv, newargv[0], n?newargv[1]:"", (n>1)?newargv[2]:"",n); + printf_log(LOG_DEBUG, " => execv(\"%s\", %p [\"%s\", \"%s\", \"%s\"...:%d])\n", newargv[0], newargv, newargv[0], n?newargv[1]:"", (n>1)?newargv[2]:"",n); int ret = execv(newargv[0], (char* const*)newargv); free(newargv); return ret; @@ -1574,7 +1574,7 @@ EXPORT int32_t my_execve(x64emu_t* emu, const char* path, char* const argv[], ch int self = isProcSelf(path, "exe"); int x64 = FileIsX64ELF(path); int x86 = my_context->box86path?FileIsX86ELF(path):0; - printf_log(LOG_DEBUG, "execv(\"%s\", %p) is x64=%d\n", path, argv, x64); + printf_log(LOG_DEBUG, "execv(\"%s\", %p) is x64=%d x86=%d\n", path, argv, x64, x86); #if 1 if (x64 || x86 || self) { int skip_first = 0; @@ -1587,7 +1587,7 @@ EXPORT int32_t my_execve(x64emu_t* emu, const char* path, char* const argv[], ch newargv[0] = x86?emu->context->box86path:emu->context->box64path; memcpy(newargv+1, argv+skip_first, sizeof(char*)*(n+1)); if(self) newargv[1] = emu->context->fullpath; - printf_log(LOG_DEBUG, " => execv(\"%s\", %p [\"%s\", \"%s\", \"%s\"...:%d])\n", emu->context->box64path, newargv, newargv[0], n?newargv[1]:"", (n>1)?newargv[2]:"",n); + printf_log(LOG_DEBUG, " => execv(\"%s\", %p [\"%s\", \"%s\", \"%s\"...:%d])\n", newargv[0], newargv, newargv[0], n?newargv[1]:"", (n>1)?newargv[2]:"",n); int ret = execve(newargv[0], (char* const*)newargv, envp); free(newargv); return ret; |