diff --git a/loader/src/ptracer/monitor.cpp b/loader/src/ptracer/monitor.cpp index f7dff5f..2a524be 100644 --- a/loader/src/ptracer/monitor.cpp +++ b/loader/src/ptracer/monitor.cpp @@ -437,19 +437,27 @@ static bool ensure_daemon_created(bool is_64bit) { } } -#define CHECK_DAEMON_EXIT(abi) \ - if (status##abi.supported && pid == status64.daemon_pid) { \ - char status_str[64]; \ - parse_status(status, status_str, sizeof(status_str)); \ - \ - LOGW("daemon" #abi "pid %d exited: %s", pid, status_str); \ - status##abi.daemon_running = false; \ - \ - if (status##abi.daemon_error_info[0] == '\0') \ - memcpy(status##abi.daemon_error_info, status_str, strlen(status_str)); \ - \ - updateStatus(); \ - continue; \ +#define CHECK_DAEMON_EXIT(abi) \ + if (status##abi.supported && pid == status64.daemon_pid) { \ + char status_str[64]; \ + parse_status(status, status_str, sizeof(status_str)); \ + \ + LOGW("daemon" #abi " pid %d exited: %s", pid, status_str); \ + status##abi.daemon_running = false; \ + \ + if (!status##abi.daemon_error_info) { \ + status##abi.daemon_error_info = (char *)malloc(strlen(status_str) + 1); \ + if (status##abi.daemon_error_info) { \ + LOGE("malloc daemon" #abi " error info failed"); \ + \ + return; \ + } \ + \ + memcpy(status##abi.daemon_error_info, status_str, strlen(status_str) + 1); \ + } \ + \ + updateStatus(); \ + continue; \ } #define PRE_INJECT(abi, is_64) \ @@ -680,7 +688,7 @@ static char post_section[1024]; else if (status ## suffix.zygote_injected) strcat(status_text, "😋 injected, "); \ else strcat(status_text, "❌ not injected, "); \ \ - strcat(status_text, " daemon" # suffix ": "); \ + strcat(status_text, "daemon" # suffix ": "); \ if (status ## suffix.daemon_running) { \ strcat(status_text, "😋 running "); \ \ @@ -706,25 +714,25 @@ static void updateStatus() { switch (tracing_state) { case TRACING: { - strcat(status_text, "😋 tracing "); + strcat(status_text, "😋 tracing"); break; } case STOPPING: [[fallthrough]]; case STOPPED: { - strcat(status_text, "❌ stopped "); + strcat(status_text, "❌ stopped"); break; } case EXITING: { - strcat(status_text, "❌ exited "); + strcat(status_text, "❌ exited"); break; } } if (tracing_state != TRACING && monitor_stop_reason[0] != '\0') { - strcat(status_text, "("); + strcat(status_text, " ("); strcat(status_text, monitor_stop_reason); strcat(status_text, ")"); } @@ -822,26 +830,27 @@ static bool prepare_environment() { return false; } - const char field_name[] = "description="; - - int pre_section_len = 0; - int post_section_len = 0; + bool after_description = false; char line[1024]; while (fgets(line, sizeof(line), orig_prop) != NULL) { - if (strstr(line, field_name) == line) { - strncat(pre_section, "description=", sizeof(pre_section) - pre_section_len); + if (strncmp(line, "description=", strlen("description=")) == 0) { + strcat(pre_section, "description="); + strcat(post_section, line + strlen("description=")); + after_description = true; - pre_section_len += strlen("description="); - } else { - strncat(post_section, line, sizeof(post_section) - post_section_len); - - post_section_len += strlen(line); + continue; } + + if (after_description) strcat(post_section, line); + else strcat(pre_section, line); } fclose(orig_prop); + /* TODO: See if ZYGISK_ENABLED flag is already set, + if so, set a status saying to disable built-in Zygisk. */ +A updateStatus(); return true;