diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt index d06550bc1..3087fe835 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt @@ -145,7 +145,7 @@ abstract class MagiskInstallImpl protected constructor( } // Extract scripts - for (script in listOf("util_functions.sh", "boot_patch.sh", "addon.d.sh", "stub.apk")) { + for (script in listOf("util_functions.sh", "boot_patch.sh", "addon.d.sh")) { val dest = File(installDir, script) context.assets.open(script).writeTo(dest) } diff --git a/build.py b/build.py index 2918a76fb..9764b72aa 100755 --- a/build.py +++ b/build.py @@ -664,11 +664,6 @@ def push_files(files: list[Path], push_apk: bool = False): to_push = list(files) with ZipFile(apk) as zf: - # Extract stub.apk - stub = tmp / "stub.apk" - stub.write_bytes(zf.read("assets/stub.apk")) - to_push.append(stub) - # Extract assets/*.sh for name in zf.namelist(): if name.startswith("assets/") and name.endswith(".sh") and name.count("/") == 1: diff --git a/native/src/core/bootstages.rs b/native/src/core/bootstages.rs index 9df44d2c8..e408d0cb1 100644 --- a/native/src/core/bootstages.rs +++ b/native/src/core/bootstages.rs @@ -116,8 +116,6 @@ impl MagiskD { setup_logfile(); info!("** post-fs-data mode running"); - self.preserve_stub_apk(); - // Check secure dir if !cstr!(SECURE_DIR).exists() { error!("* {} is not present, abort", SECURE_DIR); @@ -190,7 +188,6 @@ impl MagiskD { } setup_preinit_dir(); - self.ensure_manager(); if self.zygisk_enabled.load(Ordering::Relaxed) { self.zygisk.lock().reset(true); } diff --git a/native/src/core/include/core.hpp b/native/src/core/include/core.hpp index 93847b926..9a1a88687 100644 --- a/native/src/core/include/core.hpp +++ b/native/src/core/include/core.hpp @@ -69,7 +69,6 @@ bool read_vector(int fd, std::vector &vec) { } // Scripting -void install_apk(Utf8CStr apk); void uninstall_pkg(Utf8CStr pkg); void exec_common_scripts(Utf8CStr stage); void exec_module_scripts(Utf8CStr stage, const rust::Vec &module_list); diff --git a/native/src/core/lib.rs b/native/src/core/lib.rs index 5c7b705e8..0c44e4830 100644 --- a/native/src/core/lib.rs +++ b/native/src/core/lib.rs @@ -162,7 +162,6 @@ pub mod ffi { fn exec_script(script: Utf8CStrRef); fn exec_common_scripts(stage: Utf8CStrRef); fn exec_module_scripts(state: Utf8CStrRef, modules: &Vec); - fn install_apk(apk: Utf8CStrRef); fn uninstall_pkg(apk: Utf8CStrRef); fn install_module(zip: Utf8CStrRef); diff --git a/native/src/core/package.rs b/native/src/core/package.rs index c71d58c38..c5efd721e 100644 --- a/native/src/core/package.rs +++ b/native/src/core/package.rs @@ -1,6 +1,5 @@ use crate::consts::{APP_DATA_DIR, APP_PACKAGE_NAME, MAGISK_VER_CODE, TRUSTED_CERT}; use crate::daemon::{AID_APP_END, AID_APP_START, MagiskD, to_app_id}; -use crate::ffi::{get_magisk_tmp, install_apk}; #[cfg(all(feature = "check-signature", not(debug_assertions)))] use crate::ffi::uninstall_pkg; use base::WalkResult::{Abort, Continue, Skip}; @@ -192,7 +191,6 @@ enum Status { #[derive(Default)] pub struct ManagerInfo { - stub_apk_fd: Option, tracked_files: BTreeMap, } @@ -249,42 +247,12 @@ impl ManagerInfo { Status::Installed } - fn install_stub(&mut self) { - if let Some(ref mut stub_fd) = self.stub_apk_fd { - // Copy the stub APK - let tmp_apk = cstr!("/data/stub.apk"); - let result = || -> LoggedResult<()> { - { - let mut tmp_apk_file = tmp_apk.create( - OFlag::O_WRONLY | OFlag::O_CREAT | OFlag::O_TRUNC | OFlag::O_CLOEXEC, - 0o600, - )?; - io::copy(stub_fd, &mut tmp_apk_file)?; - } - // Seek the fd back to start - stub_fd.seek(SeekFrom::Start(0))?; - Ok(()) - }(); - if result.is_ok() { - install_apk(tmp_apk); - } - } - } - - fn get_manager( - &mut self, - daemon: &MagiskD, - user: i32, - #[allow(unused_mut)] mut install: bool, - ) -> (i32, &str) { + fn get_manager(&mut self, user: i32) -> (i32, &str) { if let Some(file) = self.tracked_files.get(&user) && file.is_same() { // no APK if &file.path == PACKAGES_XML { - if install && !daemon.is_emulator { - self.install_stub(); - } return (-1, ""); } // orig APK is still the same @@ -306,7 +274,7 @@ impl ManagerInfo { }; } #[cfg(all(feature = "check-signature", not(debug_assertions)))] - Status::CertMismatch => install = true, + Status::CertMismatch => {} Status::NotInstalled => {} } @@ -314,46 +282,23 @@ impl ManagerInfo { self.tracked_files .insert(user, TrackedFile::new(PACKAGES_XML.into())); - if install && !daemon.is_emulator { - self.install_stub(); - } (-1, "") } } impl MagiskD { - pub fn preserve_stub_apk(&self) { - let mut info = self.manager_info.lock(); - let apk = cstr::buf::default() - .join_path(get_magisk_tmp()) - .join_path("stub.apk"); - info.stub_apk_fd = apk.open(OFlag::O_RDONLY | OFlag::O_CLOEXEC).ok(); - apk.remove().log_ok(); - } - pub fn get_manager_uid(&self, user: i32) -> i32 { let mut info = self.manager_info.lock(); - let (uid, _) = info.get_manager(self, user, false); + let (uid, _) = info.get_manager(user); uid } - pub fn get_manager(&self, user: i32, install: bool) -> (i32, String) { + pub fn get_manager(&self, user: i32) -> (i32, String) { let mut info = self.manager_info.lock(); - let (uid, pkg) = info.get_manager(self, user, install); + let (uid, pkg) = info.get_manager(user); (uid, pkg.to_string()) } - pub fn ensure_manager(&self) { - let mut info = self.manager_info.lock(); - for user in self.get_users() { - let (_, pkg) = info.get_manager(self, user, false); - if !pkg.is_empty() { - return; - } - } - let _ = info.get_manager(self, 0, true); - } - // app_id = app_no + AID_APP_START // app_no range: [0, 9999] pub fn get_app_no_list(&self) -> BitSet { diff --git a/native/src/core/scripting.cpp b/native/src/core/scripting.cpp index ad2356a09..c22777b03 100644 --- a/native/src/core/scripting.cpp +++ b/native/src/core/scripting.cpp @@ -232,21 +232,6 @@ void exec_module_scripts(Utf8CStr stage, const rust::Vec &module_lis PFS_DONE() } -constexpr char install_script[] = R"EOF( -APK=%s -log -t Magisk "pm_install: $APK" -log -t Magisk "pm_install: $(pm install --user current -g -r $APK 2>&1)" -appops set --user current %s REQUEST_INSTALL_PACKAGES allow -rm -f $APK -)EOF"; - -void install_apk(Utf8CStr apk) { - setfilecon(apk.c_str(), MAGISK_FILE_CON); - char cmds[sizeof(install_script) + 4096]; - ssprintf(cmds, sizeof(cmds), install_script, apk.c_str(), JAVA_PACKAGE_NAME); - exec_command_async("/system/bin/sh", "-c", cmds); -} - constexpr char uninstall_script[] = R"EOF( PKG=%s log -t Magisk "pm_uninstall: $PKG" diff --git a/native/src/core/su/daemon.rs b/native/src/core/su/daemon.rs index 8e2c254a8..0f8a54954 100644 --- a/native/src/core/su/daemon.rs +++ b/native/src/core/su/daemon.rs @@ -190,10 +190,10 @@ impl MagiskD { let mut settings = RootSettings::default(); self.get_root_settings(eval_uid, &mut settings)?; - let (mut mgr_uid, mut mgr_pkg) = self.get_manager(to_user_id(eval_uid), true); + let (mut mgr_uid, mut mgr_pkg) = self.get_manager(to_user_id(eval_uid)); if mgr_pkg.is_empty() && to_app_id(eval_uid) < AID_APP_START { for user in self.get_users() { - let (id, pkg) = self.get_manager(user, true); + let (id, pkg) = self.get_manager(user); if !pkg.is_empty() { mgr_uid = id; mgr_pkg = pkg; diff --git a/native/src/init/rootdir.cpp b/native/src/init/rootdir.cpp index c3d1f02a9..3110cd70e 100644 --- a/native/src/init/rootdir.cpp +++ b/native/src/init/rootdir.cpp @@ -233,7 +233,6 @@ static void recreate_sbin(const char *mirror, bool use_bind_mount) { static void extract_files(bool sbin) { const char *magisk_xz = sbin ? "/sbin/magisk.xz" : "magisk.xz"; - const char *stub_xz = sbin ? "/sbin/stub.xz" : "stub.xz"; const char *init_ld_xz = sbin ? "/sbin/init-ld.xz" : "init-ld.xz"; if (access(magisk_xz, F_OK) == 0) { @@ -243,13 +242,6 @@ static void extract_files(bool sbin) { unxz(fd, magisk); close(fd); } - if (access(stub_xz, F_OK) == 0) { - mmap_data stub(stub_xz); - unlink(stub_xz); - int fd = xopen("stub.apk", O_WRONLY | O_CREAT, 0); - unxz(fd, stub); - close(fd); - } if (access(init_ld_xz, F_OK) == 0) { mmap_data init_ld(init_ld_xz); unlink(init_ld_xz); diff --git a/scripts/avd_patch.sh b/scripts/avd_patch.sh index 065140f7b..94474b5fd 100644 --- a/scripts/avd_patch.sh +++ b/scripts/avd_patch.sh @@ -56,7 +56,6 @@ API=$(getprop ro.build.version.sdk) cat config ./magiskboot compress=xz magisk magisk.xz -./magiskboot compress=xz stub.apk stub.xz ./magiskboot compress=xz init-ld init-ld.xz ./magiskboot cpio ramdisk.cpio \ @@ -64,7 +63,6 @@ cat config "mkdir 0750 overlay.d" \ "mkdir 0750 overlay.d/sbin" \ "add 0644 overlay.d/sbin/magisk.xz magisk.xz" \ -"add 0644 overlay.d/sbin/stub.xz stub.xz" \ "add 0644 overlay.d/sbin/init-ld.xz init-ld.xz" \ "patch" \ "backup ramdisk.cpio.orig" \ diff --git a/scripts/avd_setup.sh b/scripts/avd_setup.sh index f90b43443..03d11d38e 100644 --- a/scripts/avd_setup.sh +++ b/scripts/avd_setup.sh @@ -114,7 +114,7 @@ mkdir /data/adb/modules 2>/dev/null mkdir /data/adb/post-fs-data.d 2>/dev/null mkdir /data/adb/service.d 2>/dev/null -MAGISK_FILES="magisk magiskpolicy stub.apk" +MAGISK_FILES="magisk magiskpolicy" if [ -e /system/bin/linker ] && [ -e /system/bin/linker64 ]; then MAGISK_FILES="$MAGISK_FILES magisk32" fi diff --git a/scripts/boot_patch.sh b/scripts/boot_patch.sh index 86da7fb41..e04f2e394 100644 --- a/scripts/boot_patch.sh +++ b/scripts/boot_patch.sh @@ -21,7 +21,6 @@ # magisk binary The magisk binary. # magiskboot binary A tool to manipulate boot images. # init-ld binary The library that will be LD_PRELOAD of /init -# stub.apk binary The stub Magisk app to embed into ramdisk. # ####################################################################################### @@ -167,7 +166,6 @@ $BOOTMODE && [ -z "$PREINITDEVICE" ] && PREINITDEVICE=$(./magisk --preinit-devic # Compress to save precious ramdisk space ./magiskboot compress=xz magisk magisk.xz -./magiskboot compress=xz stub.apk stub.xz ./magiskboot compress=xz init-ld init-ld.xz echo "KEEPVERITY=$KEEPVERITY" > config @@ -185,7 +183,6 @@ fi "mkdir 0750 overlay.d" \ "mkdir 0750 overlay.d/sbin" \ "add 0644 overlay.d/sbin/magisk.xz magisk.xz" \ -"add 0644 overlay.d/sbin/stub.xz stub.xz" \ "add 0644 overlay.d/sbin/init-ld.xz init-ld.xz" \ "patch" \ "$SKIP_BACKUP backup ramdisk.cpio.orig" \