Skip to content

Commit

Permalink
fix: merge conflicts
Browse files Browse the repository at this point in the history
This commit fixes the conflicts between "main" and "add/zygiskd-c99".
  • Loading branch information
ThePedroo committed Aug 15, 2024
2 parents d51acdd + 763e94b commit b6c83c0
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 29 deletions.
54 changes: 54 additions & 0 deletions loader/src/common/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,60 @@ namespace zygiskd {

info->pid = socket_utils::read_u32(fd);

info->modules = (struct zygote_modules *)malloc(sizeof(struct zygote_modules));
if (info->modules == NULL) {
info->modules->modules_count = 0;

close(fd);

return;
}

info->modules->modules_count = socket_utils::read_usize(fd);

if (info->modules->modules_count == 0) {
info->modules->modules = NULL;

close(fd);

return;
}

info->modules->modules = (char **)malloc(sizeof(char *) * info->modules->modules_count);
if (info->modules->modules == NULL) {
free(info->modules);
info->modules = NULL;
info->modules->modules_count = 0;

close(fd);

return;
}

for (size_t i = 0; i < info->modules->modules_count; i++) {
/* INFO by ThePedroo: Ugly solution to read with std::string existance (temporary) */
std::string name = socket_utils::read_string(fd);

char module_path[PATH_MAX];
snprintf(module_path, sizeof(module_path), "/data/adb/modules/%s/module.prop", name.c_str());

FILE *module_prop = fopen(module_path, "r");
if (module_prop == NULL) {
info->modules->modules[i] = strdup(name.c_str());
} else {
char line[1024];
while (fgets(line, sizeof(line), module_prop) != NULL) {
if (strncmp(line, "name=", 5) == 0) {
info->modules->modules[i] = strndup(line + 5, strlen(line) - 6);

break;
}
}

fclose(module_prop);
}
}

close(fd);
} else info->running = false;
}
Expand Down
6 changes: 6 additions & 0 deletions loader/src/include/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class UniqueFd {
Fd fd_ = -1;
};

struct zygote_modules {
char **modules;
size_t modules_count;
};

enum zygote_root_impl {
ZYGOTE_ROOT_IMPL_NONE,
ZYGOTE_ROOT_IMPL_APATCH,
Expand All @@ -50,6 +55,7 @@ enum zygote_root_impl {
};

struct zygote_info {
struct zygote_modules *modules;
enum zygote_root_impl root_impl;
pid_t pid;
bool running;
Expand Down
4 changes: 3 additions & 1 deletion loader/src/injector/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,9 @@ void ZygiskContext::app_specialize_pre() {
}

if ((info_flags & (PROCESS_IS_MANAGER | PROCESS_ROOT_IS_MAGISK)) == (PROCESS_IS_MANAGER | PROCESS_ROOT_IS_MAGISK)) {
LOGI("Manager process detected, not touching.\n");
LOGI("Manager process detected. Notifying that Zygisk has been enabled.\n");

setenv("ZYGISK_ENABLED", "1", 1);
} else {
run_modules_pre();
}
Expand Down
52 changes: 47 additions & 5 deletions loader/src/ptracer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ int main(int argc, char **argv) {

return 0;
} else if (argc >= 2 && strcmp(argv[1], "version") == 0) {
printf("ReZygisk Tracer %s\n", ZKSU_VERSION);
/* INFO: Noop*/

return 0;
} else if (argc >= 2 && strcmp(argv[1], "info") == 0) {
printf("ReZygisk Tracer %s\n", ZKSU_VERSION);

struct zygote_info info;
zygiskd::GetInfo(&info);

Expand Down Expand Up @@ -84,11 +82,55 @@ int main(int argc, char **argv) {
}
}

printf("Is the daemon running: %s\n", info.running ? "yes" : "no");
#ifdef __LP64__
printf("Daemon64 running: %d\n", status64.daemon_running);
printf("Zygote64 injected: %s\n", status64.zygote_injected ? "yes" : "no");
#else
printf("Daemon32 running: %s\n", status32.daemon_running ? "yes" : "no");
printf("Zygote32 injected: %s\n", status32.zygote_injected ? "yes" : "no");
#endif

switch (tracing_state) {
case TRACING: {
printf("Tracing state: TRACING\n");

break;
}
case STOPPING: {
printf("Tracing state: STOPPING\n");
printf("Stop reason: %s\n", monitor_stop_reason);

break;
}
case STOPPED: {
printf("Tracing state: STOPPED\n");
printf("Stop reason: %s\n", monitor_stop_reason);

break;
}
case EXITING: {
printf("Tracing state: EXITING\n");

break;
}
}

if (info.modules->modules_count != 0) {
printf("Modules: %zu\n", info.modules->modules_count);

for (size_t i = 0; i < info.modules->modules_count; i++) {
printf(" - %s\n", info.modules->modules[i]);

free(info.modules->modules[i]);
}

free(info.modules->modules);
} else {
printf("Modules: N/A\n");
}

return 0;
} else {
printf("ReZygisk Tracer %s\n", ZKSU_VERSION);
printf(
"Available commands:\n"
" - monitor\n"
Expand Down
24 changes: 4 additions & 20 deletions loader/src/ptracer/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@

static void updateStatus();

enum TracingState {
TRACING = 1,
STOPPING,
STOPPED,
EXITING
};

static char monitor_stop_reason[32];
char monitor_stop_reason[32];

constexpr char SOCKET_NAME[] = "init_monitor";

Expand Down Expand Up @@ -110,20 +103,11 @@ struct EventLoop {
}
};

static TracingState tracing_state = TRACING;
TracingState tracing_state = TRACING;
static char prop_path[PATH_MAX];

struct Status {
bool supported = false;
bool zygote_injected = false;
bool daemon_running = false;
pid_t daemon_pid = -1;
char *daemon_info;
char *daemon_error_info;
};

static Status status64;
static Status status32;
Status status64;
Status status32;

struct SocketHandler : public EventHandler {
int sock_fd_;
Expand Down
23 changes: 23 additions & 0 deletions loader/src/ptracer/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@

#include <stdbool.h>

extern char monitor_stop_reason[32];

enum TracingState {
TRACING = 1,
STOPPING,
STOPPED,
EXITING
};

extern TracingState tracing_state;

struct Status {
bool supported = false;
bool zygote_injected = false;
bool daemon_running = false;
pid_t daemon_pid = -1;
char *daemon_info;
char *daemon_error_info;
};

extern Status status64;
extern Status status32;

void init_monitor();

bool trace_zygote(int pid);
Expand Down
2 changes: 2 additions & 0 deletions loader/src/ptracer/ptracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ bool inject_on_main(int pid, const char *lib_path) {

LOGE("dlerror info %s", err);

free(err);

return false;
}

Expand Down
7 changes: 4 additions & 3 deletions module/src/sepolicy.rule
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
allow * tmpfs * *
allow zygote appdomain_tmpfs dir *
allow zygote tmpfs file *
allow zygote appdomain_tmpfs file *

type magisk_file file_type
typeattribute magisk_file mlstrustedobject

allow * magisk_file file *
allow * magisk_file dir *
allow * magisk_file fifo_file *
Expand All @@ -12,9 +12,10 @@ allow * magisk_file lnk_file *
allow * magisk_file sock_file *

allow system_server system_server process execmem
allow zygote zygote process execmem

allow zygote adb_data_file dir search
allow zygote mnt_vendor_file dir search
allow zygote system_file dir mounton
allow zygote labeledfs filesystem mount
allow zygote fs_type filesystem unmount
allow zygote zygote process execmem

0 comments on commit b6c83c0

Please sign in to comment.