mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 10:35:26 +00:00
Enable Zygisk
This commit is contained in:
parent
b6298f8602
commit
3b8ce85092
@ -542,6 +542,19 @@ static void inject_magisk_bins(root_node *system) {
|
|||||||
delete bin->extract(init_applet[i]);
|
delete bin->extract(init_applet[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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); \
|
||||||
|
int out = xopen(zbin.data(), O_CREAT | O_WRONLY, 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() {
|
void magic_mount() {
|
||||||
node_entry::mirror_dir = MAGISKTMP + "/" MIRRDIR;
|
node_entry::mirror_dir = MAGISKTMP + "/" MIRRDIR;
|
||||||
node_entry::module_mnt = MAGISKTMP + "/" MODULEMNT "/";
|
node_entry::module_mnt = MAGISKTMP + "/" MODULEMNT "/";
|
||||||
@ -592,7 +605,7 @@ void magic_mount() {
|
|||||||
for (const char *part : { "/vendor", "/product", "/system_ext" }) {
|
for (const char *part : { "/vendor", "/product", "/system_ext" }) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (lstat(part, &st) == 0 && S_ISDIR(st.st_mode)) {
|
if (lstat(part, &st) == 0 && S_ISDIR(st.st_mode)) {
|
||||||
if (auto old = system->extract(part + 1); old) {
|
if (auto old = system->extract(part + 1)) {
|
||||||
auto new_node = new root_node(old);
|
auto new_node = new root_node(old);
|
||||||
root->insert(new_node);
|
root->insert(new_node);
|
||||||
}
|
}
|
||||||
@ -601,6 +614,12 @@ void magic_mount() {
|
|||||||
|
|
||||||
root->prepare();
|
root->prepare();
|
||||||
root->mount();
|
root->mount();
|
||||||
|
|
||||||
|
// Mount on top of modules to enable zygisk
|
||||||
|
string zygisk_bin = MAGISKTMP + "/" ZYGISKBIN;
|
||||||
|
mkdir(zygisk_bin.data(), 0);
|
||||||
|
mount_zygisk(32)
|
||||||
|
mount_zygisk(64)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prepare_modules() {
|
static void prepare_modules() {
|
||||||
|
@ -26,6 +26,7 @@ extern std::string MAGISKTMP;
|
|||||||
#define ROOTOVL INTLROOT "/rootdir"
|
#define ROOTOVL INTLROOT "/rootdir"
|
||||||
#define SHELLPTS INTLROOT "/pts"
|
#define SHELLPTS INTLROOT "/pts"
|
||||||
#define ROOTMNT ROOTOVL "/.mount_list"
|
#define ROOTMNT ROOTOVL "/.mount_list"
|
||||||
|
#define ZYGISKBIN INTLROOT "/zygisk"
|
||||||
|
|
||||||
constexpr const char *applet_names[] = { "su", "resetprop", nullptr };
|
constexpr const char *applet_names[] = { "su", "resetprop", nullptr };
|
||||||
constexpr const char *init_applet[] = { "magiskpolicy", "supolicy", nullptr };
|
constexpr const char *init_applet[] = { "magiskpolicy", "supolicy", nullptr };
|
||||||
|
@ -26,7 +26,7 @@ int fd_pathat(int dirfd, const char *name, char *path, size_t size) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mkdirs(string path, mode_t mode) {
|
int mkdirs(string_view path, mode_t mode) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
for (char *p = path.data() + 1; *p; ++p) {
|
for (char *p = path.data() + 1; *p; ++p) {
|
||||||
if (*p == '/') {
|
if (*p == '/') {
|
||||||
@ -420,7 +420,7 @@ void restore_folder(const char *dir, vector<raw_file> &files) {
|
|||||||
for (raw_file &file : files) {
|
for (raw_file &file : files) {
|
||||||
string path = base + "/" + file.path;
|
string path = base + "/" + file.path;
|
||||||
if (S_ISDIR(file.attr.st.st_mode)) {
|
if (S_ISDIR(file.attr.st.st_mode)) {
|
||||||
mkdirs(path.data(), 0);
|
mkdirs(path, 0);
|
||||||
} else if (S_ISREG(file.attr.st.st_mode)) {
|
} else if (S_ISREG(file.attr.st.st_mode)) {
|
||||||
auto fp = xopen_file(path.data(), "we");
|
auto fp = xopen_file(path.data(), "we");
|
||||||
if (fp) fwrite(file.buf, 1, file.sz, fp.get());
|
if (fp) fwrite(file.buf, 1, file.sz, fp.get());
|
||||||
|
@ -32,7 +32,7 @@ struct raw_file {
|
|||||||
|
|
||||||
ssize_t fd_path(int fd, char *path, size_t size);
|
ssize_t fd_path(int fd, char *path, size_t size);
|
||||||
int fd_pathat(int dirfd, const char *name, char *path, size_t size);
|
int fd_pathat(int dirfd, const char *name, char *path, size_t size);
|
||||||
int mkdirs(std::string path, mode_t mode);
|
int mkdirs(std::string_view path, mode_t mode);
|
||||||
void rm_rf(const char *path);
|
void rm_rf(const char *path);
|
||||||
void mv_path(const char *src, const char *dest);
|
void mv_path(const char *src, const char *dest);
|
||||||
void mv_dir(int src, int dest);
|
void mv_dir(int src, int dest);
|
||||||
|
@ -466,7 +466,7 @@ void *xmmap(void *addr, size_t length, int prot, int flags,
|
|||||||
|
|
||||||
ssize_t xsendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
|
ssize_t xsendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
|
||||||
ssize_t ret = sendfile(out_fd, in_fd, offset, count);
|
ssize_t ret = sendfile(out_fd, in_fd, offset, count);
|
||||||
if (count != ret) {
|
if (ret < 0) {
|
||||||
PLOGE("sendfile");
|
PLOGE("sendfile");
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -247,7 +247,7 @@ static void setup_files(int client, ucred *cred) {
|
|||||||
|
|
||||||
write_int(client, 0);
|
write_int(client, 0);
|
||||||
|
|
||||||
string path = MAGISKTMP + "/zygisk." + basename(buf);
|
string path = MAGISKTMP + "/" ZYGISKBIN "/zygisk." + basename(buf);
|
||||||
cp_afc(buf, (path + ".1.so").data());
|
cp_afc(buf, (path + ".1.so").data());
|
||||||
cp_afc(buf, (path + ".2.so").data());
|
cp_afc(buf, (path + ".2.so").data());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user