From 7607a87617a827f5cfe019a2c561e4d88bae0a61 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 16 Jul 2023 10:54:32 +0200 Subject: Added wrapped execle (for #850) --- src/wrapped/wrappedlibc.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index cb218412..ff20404e 100755 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -2089,7 +2089,7 @@ EXPORT int32_t my_execl(x64emu_t* emu, const char* path) int x64 = FileIsX64ELF(path); int x86 = my_context->box86path?FileIsX86ELF(path):0; int script = (my_context->bashpath && FileIsShell(path))?1:0; - printf_log(LOG_DEBUG, "execl(\"%s\", ...), IsX86=%d, self=%d\n", path, x64, self); + printf_log(LOG_DEBUG, "execle(\"%s\", ...), IsX86=%d, self=%d\n", path, x64, self); // count argv... int i=0; while(getVargN(emu, i+1)) ++i; @@ -2102,12 +2102,42 @@ EXPORT int32_t my_execl(x64emu_t* emu, const char* path) for (int k=0; kcontext->fullpath; - printf_log(LOG_DEBUG, " => execl(\"%s\", %p [\"%s\", \"%s\"...:%d])\n", newargv[0], newargv, newargv[1], i?newargv[2]:"", i); + printf_log(LOG_DEBUG, " => execle(\"%s\", %p [\"%s\", \"%s\"...:%d])\n", newargv[0], newargv, newargv[1], i?newargv[2]:"", i); int ret = execv(newargv[0], newargv); box_free(newargv); return ret; } +EXPORT int32_t my_execle(x64emu_t* emu, const char* path) +{ + int self = isProcSelf(path, "exe"); + int x64 = FileIsX64ELF(path); + int x86 = my_context->box86path?FileIsX86ELF(path):0; + int script = (my_context->bashpath && FileIsShell(path))?1:0; + printf_log(LOG_DEBUG, "execl(\"%s\", ...), IsX86=%d, self=%d\n", path, x64, self); + // hack to update the environ var if needed + // count argv... + int i=0; + while(getVargN(emu, i+1)) ++i; + int toadd = script?2:((x64||self)?1:0); + char** newargv = (char**)box_calloc(i+toadd+1, sizeof(char*)); + char** envp = (char**)getVargN(emu, i+2); + if(envp == my_context->envv && environ) { + envp = environ; + } + int j=0; + if ((x64 || x86 || script || self)) + newargv[j++] = x86?emu->context->box86path:emu->context->box64path; + if(script) newargv[j++] = emu->context->bashpath; + for (int k=0; kcontext->fullpath; + printf_log(LOG_DEBUG, " => execle(\"%s\", %p [\"%s\", \"%s\"...:%d], %p)\n", newargv[0], newargv, newargv[1], i?newargv[2]:"", i, envp); + int ret = execve(newargv[0], newargv, envp); + box_free(newargv); + return ret; +} + EXPORT int32_t my_execlp(x64emu_t* emu, const char* path) { // need to use BOX64_PATH / PATH here... -- cgit 1.4.1