From 3e764fdc45d6413622855fe784a0cb76386a2cd3 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 19 Jun 2022 20:50:15 +0200 Subject: Change process name (hidding box64, helps mesa find the correct hack for some binaries) --- src/main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src') diff --git a/src/main.c b/src/main.c index 96cd8ee2..b13fa827 100755 --- a/src/main.c +++ b/src/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef DYNAREC #ifdef ARM64 #include @@ -1292,6 +1293,28 @@ int main(int argc, const char **argv, char **env) { printf_log(LOG_INFO, "BOX64: Using tcmalloc_minimal.so.4, and it's in the LD_PRELOAD command\n"); } } + // change process name + { + char* p = strrchr(my_context->argv[0], '/'); + if(p) + ++p; + else + p = my_context->argv[0]; + if(prctl(PR_SET_NAME, p)==-1) + printf_log(LOG_NONE, "Error setting process name (%s)\n", strerror(errno)); + else + printf_log(LOG_INFO, "Rename process to \"%s\"\n", p); + // and now all change the argv (so libs libs mesa find the correct program names) + char* endp = (char*)argv[argc-1]; + while(*endp) + ++endp; // find last argv[] address + uintptr_t diff = prog - argv[0]; // this is the difference we need to compensate + for(p=(char*)prog; p<=endp; ++p) + *(p - diff) = *p; // copy all element at argv[nextarg] to argv[0] + memset(endp - diff, 0, diff); // fill reminder with NULL + for(int i=nextarg; i