mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
Remove stub embedding from native and scripts
Remove stub.apk and stub.xz extraction, compression, ramdisk embedding, and daemon auto-installation from native components (magiskinit, magiskd, scripting), installation scripts, MagiskInstaller, and build.py. Assisted-by: Gemini 4 Argon
This commit is contained in:
@@ -145,7 +145,7 @@ abstract class MagiskInstallImpl protected constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract scripts
|
// 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)
|
val dest = File(installDir, script)
|
||||||
context.assets.open(script).writeTo(dest)
|
context.assets.open(script).writeTo(dest)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -664,11 +664,6 @@ def push_files(files: list[Path], push_apk: bool = False):
|
|||||||
to_push = list(files)
|
to_push = list(files)
|
||||||
|
|
||||||
with ZipFile(apk) as zf:
|
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
|
# Extract assets/*.sh
|
||||||
for name in zf.namelist():
|
for name in zf.namelist():
|
||||||
if name.startswith("assets/") and name.endswith(".sh") and name.count("/") == 1:
|
if name.startswith("assets/") and name.endswith(".sh") and name.count("/") == 1:
|
||||||
|
|||||||
@@ -116,8 +116,6 @@ impl MagiskD {
|
|||||||
setup_logfile();
|
setup_logfile();
|
||||||
info!("** post-fs-data mode running");
|
info!("** post-fs-data mode running");
|
||||||
|
|
||||||
self.preserve_stub_apk();
|
|
||||||
|
|
||||||
// Check secure dir
|
// Check secure dir
|
||||||
if !cstr!(SECURE_DIR).exists() {
|
if !cstr!(SECURE_DIR).exists() {
|
||||||
error!("* {} is not present, abort", SECURE_DIR);
|
error!("* {} is not present, abort", SECURE_DIR);
|
||||||
@@ -190,7 +188,6 @@ impl MagiskD {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup_preinit_dir();
|
setup_preinit_dir();
|
||||||
self.ensure_manager();
|
|
||||||
if self.zygisk_enabled.load(Ordering::Relaxed) {
|
if self.zygisk_enabled.load(Ordering::Relaxed) {
|
||||||
self.zygisk.lock().reset(true);
|
self.zygisk.lock().reset(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ bool read_vector(int fd, std::vector<T> &vec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scripting
|
// Scripting
|
||||||
void install_apk(Utf8CStr apk);
|
|
||||||
void uninstall_pkg(Utf8CStr pkg);
|
void uninstall_pkg(Utf8CStr pkg);
|
||||||
void exec_common_scripts(Utf8CStr stage);
|
void exec_common_scripts(Utf8CStr stage);
|
||||||
void exec_module_scripts(Utf8CStr stage, const rust::Vec<ModuleInfo> &module_list);
|
void exec_module_scripts(Utf8CStr stage, const rust::Vec<ModuleInfo> &module_list);
|
||||||
|
|||||||
@@ -162,7 +162,6 @@ pub mod ffi {
|
|||||||
fn exec_script(script: Utf8CStrRef);
|
fn exec_script(script: Utf8CStrRef);
|
||||||
fn exec_common_scripts(stage: Utf8CStrRef);
|
fn exec_common_scripts(stage: Utf8CStrRef);
|
||||||
fn exec_module_scripts(state: Utf8CStrRef, modules: &Vec<ModuleInfo>);
|
fn exec_module_scripts(state: Utf8CStrRef, modules: &Vec<ModuleInfo>);
|
||||||
fn install_apk(apk: Utf8CStrRef);
|
|
||||||
fn uninstall_pkg(apk: Utf8CStrRef);
|
fn uninstall_pkg(apk: Utf8CStrRef);
|
||||||
fn install_module(zip: Utf8CStrRef);
|
fn install_module(zip: Utf8CStrRef);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use crate::consts::{APP_DATA_DIR, APP_PACKAGE_NAME, MAGISK_VER_CODE, TRUSTED_CERT};
|
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::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)))]
|
#[cfg(all(feature = "check-signature", not(debug_assertions)))]
|
||||||
use crate::ffi::uninstall_pkg;
|
use crate::ffi::uninstall_pkg;
|
||||||
use base::WalkResult::{Abort, Continue, Skip};
|
use base::WalkResult::{Abort, Continue, Skip};
|
||||||
@@ -192,7 +191,6 @@ enum Status {
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ManagerInfo {
|
pub struct ManagerInfo {
|
||||||
stub_apk_fd: Option<File>,
|
|
||||||
tracked_files: BTreeMap<i32, TrackedFile>,
|
tracked_files: BTreeMap<i32, TrackedFile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,42 +247,12 @@ impl ManagerInfo {
|
|||||||
Status::Installed
|
Status::Installed
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_stub(&mut self) {
|
fn get_manager(&mut self, user: i32) -> (i32, &str) {
|
||||||
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) {
|
|
||||||
if let Some(file) = self.tracked_files.get(&user)
|
if let Some(file) = self.tracked_files.get(&user)
|
||||||
&& file.is_same()
|
&& file.is_same()
|
||||||
{
|
{
|
||||||
// no APK
|
// no APK
|
||||||
if &file.path == PACKAGES_XML {
|
if &file.path == PACKAGES_XML {
|
||||||
if install && !daemon.is_emulator {
|
|
||||||
self.install_stub();
|
|
||||||
}
|
|
||||||
return (-1, "");
|
return (-1, "");
|
||||||
}
|
}
|
||||||
// orig APK is still the same
|
// orig APK is still the same
|
||||||
@@ -306,7 +274,7 @@ impl ManagerInfo {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
#[cfg(all(feature = "check-signature", not(debug_assertions)))]
|
#[cfg(all(feature = "check-signature", not(debug_assertions)))]
|
||||||
Status::CertMismatch => install = true,
|
Status::CertMismatch => {}
|
||||||
Status::NotInstalled => {}
|
Status::NotInstalled => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,46 +282,23 @@ impl ManagerInfo {
|
|||||||
self.tracked_files
|
self.tracked_files
|
||||||
.insert(user, TrackedFile::new(PACKAGES_XML.into()));
|
.insert(user, TrackedFile::new(PACKAGES_XML.into()));
|
||||||
|
|
||||||
if install && !daemon.is_emulator {
|
|
||||||
self.install_stub();
|
|
||||||
}
|
|
||||||
(-1, "")
|
(-1, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MagiskD {
|
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 {
|
pub fn get_manager_uid(&self, user: i32) -> i32 {
|
||||||
let mut info = self.manager_info.lock();
|
let mut info = self.manager_info.lock();
|
||||||
let (uid, _) = info.get_manager(self, user, false);
|
let (uid, _) = info.get_manager(user);
|
||||||
uid
|
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 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())
|
(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_id = app_no + AID_APP_START
|
||||||
// app_no range: [0, 9999]
|
// app_no range: [0, 9999]
|
||||||
pub fn get_app_no_list(&self) -> BitSet {
|
pub fn get_app_no_list(&self) -> BitSet {
|
||||||
|
|||||||
@@ -232,21 +232,6 @@ void exec_module_scripts(Utf8CStr stage, const rust::Vec<ModuleInfo> &module_lis
|
|||||||
PFS_DONE()
|
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(
|
constexpr char uninstall_script[] = R"EOF(
|
||||||
PKG=%s
|
PKG=%s
|
||||||
log -t Magisk "pm_uninstall: $PKG"
|
log -t Magisk "pm_uninstall: $PKG"
|
||||||
|
|||||||
@@ -190,10 +190,10 @@ impl MagiskD {
|
|||||||
let mut settings = RootSettings::default();
|
let mut settings = RootSettings::default();
|
||||||
self.get_root_settings(eval_uid, &mut settings)?;
|
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 {
|
if mgr_pkg.is_empty() && to_app_id(eval_uid) < AID_APP_START {
|
||||||
for user in self.get_users() {
|
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() {
|
if !pkg.is_empty() {
|
||||||
mgr_uid = id;
|
mgr_uid = id;
|
||||||
mgr_pkg = pkg;
|
mgr_pkg = pkg;
|
||||||
|
|||||||
@@ -233,7 +233,6 @@ static void recreate_sbin(const char *mirror, bool use_bind_mount) {
|
|||||||
|
|
||||||
static void extract_files(bool sbin) {
|
static void extract_files(bool sbin) {
|
||||||
const char *magisk_xz = sbin ? "/sbin/magisk.xz" : "magisk.xz";
|
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";
|
const char *init_ld_xz = sbin ? "/sbin/init-ld.xz" : "init-ld.xz";
|
||||||
|
|
||||||
if (access(magisk_xz, F_OK) == 0) {
|
if (access(magisk_xz, F_OK) == 0) {
|
||||||
@@ -243,13 +242,6 @@ static void extract_files(bool sbin) {
|
|||||||
unxz(fd, magisk);
|
unxz(fd, magisk);
|
||||||
close(fd);
|
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) {
|
if (access(init_ld_xz, F_OK) == 0) {
|
||||||
mmap_data init_ld(init_ld_xz);
|
mmap_data init_ld(init_ld_xz);
|
||||||
unlink(init_ld_xz);
|
unlink(init_ld_xz);
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ API=$(getprop ro.build.version.sdk)
|
|||||||
cat config
|
cat config
|
||||||
|
|
||||||
./magiskboot compress=xz magisk magisk.xz
|
./magiskboot compress=xz magisk magisk.xz
|
||||||
./magiskboot compress=xz stub.apk stub.xz
|
|
||||||
./magiskboot compress=xz init-ld init-ld.xz
|
./magiskboot compress=xz init-ld init-ld.xz
|
||||||
|
|
||||||
./magiskboot cpio ramdisk.cpio \
|
./magiskboot cpio ramdisk.cpio \
|
||||||
@@ -64,7 +63,6 @@ cat config
|
|||||||
"mkdir 0750 overlay.d" \
|
"mkdir 0750 overlay.d" \
|
||||||
"mkdir 0750 overlay.d/sbin" \
|
"mkdir 0750 overlay.d/sbin" \
|
||||||
"add 0644 overlay.d/sbin/magisk.xz magisk.xz" \
|
"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" \
|
"add 0644 overlay.d/sbin/init-ld.xz init-ld.xz" \
|
||||||
"patch" \
|
"patch" \
|
||||||
"backup ramdisk.cpio.orig" \
|
"backup ramdisk.cpio.orig" \
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ mkdir /data/adb/modules 2>/dev/null
|
|||||||
mkdir /data/adb/post-fs-data.d 2>/dev/null
|
mkdir /data/adb/post-fs-data.d 2>/dev/null
|
||||||
mkdir /data/adb/service.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
|
if [ -e /system/bin/linker ] && [ -e /system/bin/linker64 ]; then
|
||||||
MAGISK_FILES="$MAGISK_FILES magisk32"
|
MAGISK_FILES="$MAGISK_FILES magisk32"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
# magisk binary The magisk binary.
|
# magisk binary The magisk binary.
|
||||||
# magiskboot binary A tool to manipulate boot images.
|
# magiskboot binary A tool to manipulate boot images.
|
||||||
# init-ld binary The library that will be LD_PRELOAD of /init
|
# 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
|
# Compress to save precious ramdisk space
|
||||||
./magiskboot compress=xz magisk magisk.xz
|
./magiskboot compress=xz magisk magisk.xz
|
||||||
./magiskboot compress=xz stub.apk stub.xz
|
|
||||||
./magiskboot compress=xz init-ld init-ld.xz
|
./magiskboot compress=xz init-ld init-ld.xz
|
||||||
|
|
||||||
echo "KEEPVERITY=$KEEPVERITY" > config
|
echo "KEEPVERITY=$KEEPVERITY" > config
|
||||||
@@ -185,7 +183,6 @@ fi
|
|||||||
"mkdir 0750 overlay.d" \
|
"mkdir 0750 overlay.d" \
|
||||||
"mkdir 0750 overlay.d/sbin" \
|
"mkdir 0750 overlay.d/sbin" \
|
||||||
"add 0644 overlay.d/sbin/magisk.xz magisk.xz" \
|
"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" \
|
"add 0644 overlay.d/sbin/init-ld.xz init-ld.xz" \
|
||||||
"patch" \
|
"patch" \
|
||||||
"$SKIP_BACKUP backup ramdisk.cpio.orig" \
|
"$SKIP_BACKUP backup ramdisk.cpio.orig" \
|
||||||
|
|||||||
Reference in New Issue
Block a user