Make zygisk survive zygote restarts

Close #4777
This commit is contained in:
topjohnwu
2021-10-27 01:53:16 -07:00
parent 4c747c4148
commit ea75a09f95
14 changed files with 339 additions and 174 deletions

View File

@ -10,14 +10,15 @@ using namespace std;
using main_fun = int (*)(int, char *[]);
static main_fun applet_main[] = { su_client_main, resetprop_main, nullptr };
constexpr const char *applets[] = { "su", "resetprop", "zygisk", nullptr };
static main_fun applet_mains[] = { su_client_main, resetprop_main, zygisk_main, nullptr };
static int call_applet(int argc, char *argv[]) {
// Applets
string_view base = basename(argv[0]);
for (int i = 0; applet_names[i]; ++i) {
if (base == applet_names[i]) {
return (*applet_main[i])(argc, argv);
for (int i = 0; applets[i]; ++i) {
if (base == applets[i]) {
return (*applet_mains[i])(argc, argv);
}
}
if (str_starts(base, "app_process")) {

View File

@ -34,6 +34,3 @@ void exec_common_scripts(const char *stage);
void exec_module_scripts(const char *stage, const std::vector<std::string_view> &modules);
void install_apk(const char *apk);
[[noreturn]] void install_module(const char *file);
// Zygisk companion entrypoint
[[noreturn]] void zygiskd(int socket);

View File

@ -157,6 +157,7 @@ static void handle_request_async(int client, int code, const sock_cred &cred) {
reboot();
break;
case ZYGISK_REQUEST:
case ZYGISK_PASSTHROUGH:
zygisk_handler(client, &cred);
break;
default:

View File

@ -39,7 +39,6 @@ Advanced Options (Internal APIs):
--sqlite SQL exec SQL commands to Magisk database
--path print Magisk tmpfs mount path
--denylist ARGS denylist config CLI
--companion FD start zygisk root companion
Available applets:
)EOF");
@ -128,8 +127,6 @@ int magisk_main(int argc, char *argv[]) {
return 0;
} else if (argc >= 3 && argv[1] == "--install-module"sv) {
install_module(argv[2]);
} else if (argc >= 3 && argv[1] == "--companion"sv) {
zygiskd(parse_int(argv[2]));
}
#if 0
/* Entry point for testing stuffs */

View File

@ -550,18 +550,21 @@ struct module_info {
};
static vector<module_info> *modules;
int app_process_32 = -1;
int app_process_64 = -1;
#define mount_zygisk(bit) \
if (access("/system/bin/app_process" #bit, F_OK) == 0) { \
string zbin = zygisk_bin + "/app_process" #bit; \
string mbin = MAGISKTMP + "/magisk" #bit; \
int src = xopen(mbin.data(), O_RDONLY | O_CLOEXEC); \
int out = xopen(zbin.data(), O_CREAT | O_WRONLY | O_CLOEXEC, 0); \
xsendfile(out, src, nullptr, INT_MAX); \
close(src); \
close(out); \
clone_attr("/system/bin/app_process" #bit, zbin.data()); \
bind_mount(zbin.data(), "/system/bin/app_process" #bit); \
#define mount_zygisk(bit) \
if (access("/system/bin/app_process" #bit, F_OK) == 0) { \
app_process_##bit = xopen("/system/bin/app_process" #bit, O_RDONLY | O_CLOEXEC); \
string zbin = zygisk_bin + "/app_process" #bit; \
string mbin = MAGISKTMP + "/magisk" #bit; \
int src = xopen(mbin.data(), O_RDONLY | O_CLOEXEC); \
int out = xopen(zbin.data(), O_CREAT | O_WRONLY | O_CLOEXEC, 0); \
xsendfile(out, src, nullptr, INT_MAX); \
close(src); \
close(out); \
clone_attr("/system/bin/app_process" #bit, zbin.data()); \
bind_mount(zbin.data(), "/system/bin/app_process" #bit); \
}
void magic_mount() {