You've already forked ReZygisk
mirror of
https://github.com/PerformanC/ReZygisk.git
synced 2025-09-06 06:37:01 +00:00
improve: module.prop parsing code; fix: deferecing a NULL pointer
This commit both improves the code that parses "module.prop" file of ReZygisk, reducing its complexity greatly and also making it smaller, and also fixes an issue where ReZygisk would deference a NULL pointer, leading to crashes in Zygiskd crash.
This commit is contained in:
@@ -437,19 +437,27 @@ static bool ensure_daemon_created(bool is_64bit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_DAEMON_EXIT(abi) \
|
#define CHECK_DAEMON_EXIT(abi) \
|
||||||
if (status##abi.supported && pid == status64.daemon_pid) { \
|
if (status##abi.supported && pid == status64.daemon_pid) { \
|
||||||
char status_str[64]; \
|
char status_str[64]; \
|
||||||
parse_status(status, status_str, sizeof(status_str)); \
|
parse_status(status, status_str, sizeof(status_str)); \
|
||||||
\
|
\
|
||||||
LOGW("daemon" #abi "pid %d exited: %s", pid, status_str); \
|
LOGW("daemon" #abi " pid %d exited: %s", pid, status_str); \
|
||||||
status##abi.daemon_running = false; \
|
status##abi.daemon_running = false; \
|
||||||
\
|
\
|
||||||
if (status##abi.daemon_error_info[0] == '\0') \
|
if (!status##abi.daemon_error_info) { \
|
||||||
memcpy(status##abi.daemon_error_info, status_str, strlen(status_str)); \
|
status##abi.daemon_error_info = (char *)malloc(strlen(status_str) + 1); \
|
||||||
\
|
if (status##abi.daemon_error_info) { \
|
||||||
updateStatus(); \
|
LOGE("malloc daemon" #abi " error info failed"); \
|
||||||
continue; \
|
\
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
memcpy(status##abi.daemon_error_info, status_str, strlen(status_str) + 1); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
updateStatus(); \
|
||||||
|
continue; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PRE_INJECT(abi, is_64) \
|
#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 if (status ## suffix.zygote_injected) strcat(status_text, "😋 injected, "); \
|
||||||
else strcat(status_text, "❌ not injected, "); \
|
else strcat(status_text, "❌ not injected, "); \
|
||||||
\
|
\
|
||||||
strcat(status_text, " daemon" # suffix ": "); \
|
strcat(status_text, "daemon" # suffix ": "); \
|
||||||
if (status ## suffix.daemon_running) { \
|
if (status ## suffix.daemon_running) { \
|
||||||
strcat(status_text, "😋 running "); \
|
strcat(status_text, "😋 running "); \
|
||||||
\
|
\
|
||||||
@@ -706,25 +714,25 @@ static void updateStatus() {
|
|||||||
|
|
||||||
switch (tracing_state) {
|
switch (tracing_state) {
|
||||||
case TRACING: {
|
case TRACING: {
|
||||||
strcat(status_text, "😋 tracing ");
|
strcat(status_text, "😋 tracing");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STOPPING: [[fallthrough]];
|
case STOPPING: [[fallthrough]];
|
||||||
case STOPPED: {
|
case STOPPED: {
|
||||||
strcat(status_text, "❌ stopped ");
|
strcat(status_text, "❌ stopped");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXITING: {
|
case EXITING: {
|
||||||
strcat(status_text, "❌ exited ");
|
strcat(status_text, "❌ exited");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tracing_state != TRACING && monitor_stop_reason[0] != '\0') {
|
if (tracing_state != TRACING && monitor_stop_reason[0] != '\0') {
|
||||||
strcat(status_text, "(");
|
strcat(status_text, " (");
|
||||||
strcat(status_text, monitor_stop_reason);
|
strcat(status_text, monitor_stop_reason);
|
||||||
strcat(status_text, ")");
|
strcat(status_text, ")");
|
||||||
}
|
}
|
||||||
@@ -822,26 +830,27 @@ static bool prepare_environment() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char field_name[] = "description=";
|
bool after_description = false;
|
||||||
|
|
||||||
int pre_section_len = 0;
|
|
||||||
int post_section_len = 0;
|
|
||||||
|
|
||||||
char line[1024];
|
char line[1024];
|
||||||
while (fgets(line, sizeof(line), orig_prop) != NULL) {
|
while (fgets(line, sizeof(line), orig_prop) != NULL) {
|
||||||
if (strstr(line, field_name) == line) {
|
if (strncmp(line, "description=", strlen("description=")) == 0) {
|
||||||
strncat(pre_section, "description=", sizeof(pre_section) - pre_section_len);
|
strcat(pre_section, "description=");
|
||||||
|
strcat(post_section, line + strlen("description="));
|
||||||
|
after_description = true;
|
||||||
|
|
||||||
pre_section_len += strlen("description=");
|
continue;
|
||||||
} else {
|
|
||||||
strncat(post_section, line, sizeof(post_section) - post_section_len);
|
|
||||||
|
|
||||||
post_section_len += strlen(line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (after_description) strcat(post_section, line);
|
||||||
|
else strcat(pre_section, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(orig_prop);
|
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();
|
updateStatus();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user