Make zygote notifier more reliable
This commit is contained in:
parent
6226f875ff
commit
82c864d57e
@ -583,7 +583,7 @@ static void dump_logs() {
|
||||
sprintf(buf, "/system/bin/%s", app);
|
||||
if (lstat(buf, &st) == 0 && S_ISREG(st.st_mode)) {
|
||||
clone_attr(buf, MAGISKTMP "/app_process");
|
||||
bind_mount(MAGISKTMP "/app_process", buf);
|
||||
bind_mount(MAGISKTMP "/app_process", buf, false);
|
||||
}
|
||||
}
|
||||
unblock_boot_process();
|
||||
|
@ -129,6 +129,7 @@ int app_process_main(int argc, char *argv[]) {
|
||||
int fd = connect_daemon();
|
||||
write_int(fd, ZYGOTE_NOTIFY);
|
||||
write_string(fd, path);
|
||||
read_int(fd);
|
||||
close(fd);
|
||||
} else {
|
||||
// Redirect to system mirror
|
||||
|
@ -80,7 +80,6 @@ void install_apk(const char *apk);
|
||||
|
||||
void magiskhide_handler(int client);
|
||||
void zygote_notify(int client, struct ucred *cred);
|
||||
void zygote_notify(int pid);
|
||||
|
||||
/*************
|
||||
* Superuser *
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
static pthread_t proc_monitor_thread;
|
||||
pthread_t proc_monitor_thread;
|
||||
|
||||
static const char *prop_key[] =
|
||||
{ "ro.boot.vbmeta.device_state", "ro.boot.verifiedbootstate", "ro.boot.flash.locked",
|
||||
@ -328,21 +328,3 @@ void auto_start_magiskhide() {
|
||||
}
|
||||
}
|
||||
|
||||
int next_zygote = -1;
|
||||
|
||||
void zygote_notify(int pid) {
|
||||
if (hide_enabled) {
|
||||
MutexGuard lock(monitor_lock);
|
||||
next_zygote = pid;
|
||||
pthread_kill(proc_monitor_thread, SIGZYGOTE);
|
||||
}
|
||||
}
|
||||
|
||||
void zygote_notify(int client, struct ucred *cred) {
|
||||
char *path = read_string(client);
|
||||
close(client);
|
||||
zygote_notify(cred->pid);
|
||||
usleep(100000);
|
||||
xmount(MAGISKTMP "/app_process", path, nullptr, MS_BIND, nullptr);
|
||||
free(path);
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef MAGISK_HIDE_H
|
||||
#define MAGISK_HIDE_H
|
||||
#pragma once
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
@ -54,6 +53,7 @@ static inline int parse_int(const char *s) {
|
||||
return val;
|
||||
}
|
||||
|
||||
extern pthread_t proc_monitor_thread;
|
||||
extern bool hide_enabled;
|
||||
extern pthread_mutex_t monitor_lock;
|
||||
extern std::set<std::pair<std::string, std::string>> hide_set;
|
||||
@ -75,5 +75,3 @@ enum {
|
||||
HIDE_ITEM_NOT_EXIST,
|
||||
HIDE_NO_NS
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -241,6 +241,32 @@ static void term_thread(int) {
|
||||
//#define PTRACE_LOG(fmt, args...) LOGD("PID=[%d] " fmt, pid, ##args)
|
||||
#define PTRACE_LOG(...)
|
||||
|
||||
int next_zygote = -1;
|
||||
|
||||
void zygote_notify(int client, struct ucred *cred) {
|
||||
char *path = read_string(client);
|
||||
|
||||
xptrace(PTRACE_ATTACH, cred->pid);
|
||||
// Wait for attach
|
||||
waitpid(cred->pid, nullptr, __WALL | __WNOTHREAD);
|
||||
xptrace(PTRACE_CONT, cred->pid);
|
||||
write_int(client, 0);
|
||||
close(client);
|
||||
// Wait for exec
|
||||
waitpid(cred->pid, nullptr, __WALL | __WNOTHREAD);
|
||||
xptrace(PTRACE_DETACH, cred->pid);
|
||||
|
||||
if (hide_enabled) {
|
||||
MutexGuard lock(monitor_lock);
|
||||
next_zygote = cred->pid;
|
||||
pthread_kill(proc_monitor_thread, SIGZYGOTE);
|
||||
}
|
||||
|
||||
// Remount zygote notifier ASAP
|
||||
xmount(MAGISKTMP "/app_process", path, nullptr, MS_BIND, nullptr);
|
||||
free(path);
|
||||
}
|
||||
|
||||
static bool check_pid(int pid) {
|
||||
char path[128];
|
||||
char cmdline[1024];
|
||||
|
Loading…
Reference in New Issue
Block a user