Let magic mount optional

This commit is contained in:
vvb2060 2024-01-05 18:39:59 +08:00 committed by John Wu
parent 5de597f079
commit ecc74d45d1
3 changed files with 37 additions and 30 deletions

View File

@ -5,6 +5,7 @@ import android.app.Application
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import android.system.Os
import androidx.profileinstaller.ProfileInstaller import androidx.profileinstaller.ProfileInstaller
import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.StubApk import com.topjohnwu.magisk.StubApk
@ -46,6 +47,8 @@ open class App() : Application() {
Timber.e(e) Timber.e(e)
exitProcess(1) exitProcess(1)
} }
Os.setenv("PATH", "${Os.getenv("PATH")}:/debug_ramdisk:/sbin", true)
} }
override fun attachBaseContext(context: Context) { override fun attachBaseContext(context: Context) {

View File

@ -25,16 +25,11 @@ static void setup_mounts() {
char path[PATH_MAX]; char path[PATH_MAX];
// Bind remount module root to clear nosuid // Bind remount module root to clear nosuid
if (access(SECURE_DIR, F_OK) == 0 || SDK_INT < 24) {
ssprintf(path, sizeof(path), "%s/" MODULEMNT, get_magisk_tmp()); ssprintf(path, sizeof(path), "%s/" MODULEMNT, get_magisk_tmp());
xmkdir(SECURE_DIR, 0700);
xmkdir(MODULEROOT, 0755);
xmkdir(path, 0755); xmkdir(path, 0755);
xmount(MODULEROOT, path, nullptr, MS_BIND, nullptr); xmount(MODULEROOT, path, nullptr, MS_BIND, nullptr);
xmount(nullptr, path, nullptr, MS_REMOUNT | MS_BIND | MS_RDONLY, nullptr); xmount(nullptr, path, nullptr, MS_REMOUNT | MS_BIND | MS_RDONLY, nullptr);
xmount(nullptr, path, nullptr, MS_PRIVATE, nullptr); xmount(nullptr, path, nullptr, MS_PRIVATE, nullptr);
chmod(SECURE_DIR, 0700);
}
// Check and mount preinit mirror // Check and mount preinit mirror
char dev_path[64]; char dev_path[64];
@ -181,10 +176,10 @@ static bool magisk_env() {
LOGI("* Initializing Magisk environment\n"); LOGI("* Initializing Magisk environment\n");
preserve_stub_apk();
// Directories in /data/adb // Directories in /data/adb
chmod(SECURE_DIR, 0700);
xmkdir(DATABIN, 0755); xmkdir(DATABIN, 0755);
xmkdir(MODULEROOT, 0755);
xmkdir(SECURE_DIR "/post-fs-data.d", 0755); xmkdir(SECURE_DIR "/post-fs-data.d", 0755);
xmkdir(SECURE_DIR "/service.d", 0755); xmkdir(SECURE_DIR "/service.d", 0755);
restorecon(); restorecon();
@ -275,45 +270,54 @@ static bool check_key_combo() {
* Boot Stage Handlers * * Boot Stage Handlers *
***********************/ ***********************/
extern int disable_deny(); static void disable_zygisk() {
char sql[64];
sprintf(sql, "REPLACE INTO settings (key,value) VALUES('%s',%d)",
DB_SETTING_KEYS[ZYGISK_CONFIG], false);
char *err = db_exec(sql);
db_err(err);
}
bool MagiskD::post_fs_data() const { bool MagiskD::post_fs_data() const {
as_rust().setup_logfile(); as_rust().setup_logfile();
LOGI("** post-fs-data mode running\n"); LOGI("** post-fs-data mode running\n");
unlock_blocks(); preserve_stub_apk();
setup_mounts();
prune_su_access(); prune_su_access();
bool safe_mode = false; bool safe_mode = false;
if (access(SECURE_DIR, F_OK) != 0) { if (access(SECURE_DIR, F_OK) != 0) {
if (SDK_INT < 24) {
xmkdir(SECURE_DIR, 0700);
} else {
LOGE(SECURE_DIR " is not present, abort\n"); LOGE(SECURE_DIR " is not present, abort\n");
goto early_abort; return safe_mode;
}
} }
if (!magisk_env()) { if (!magisk_env()) {
LOGE("* Magisk environment incomplete, abort\n"); LOGE("* Magisk environment incomplete, abort\n");
goto early_abort; return safe_mode;
} }
if (get_prop("persist.sys.safemode", true) == "1" || if (get_prop("persist.sys.safemode", true) == "1" ||
get_prop("ro.sys.safemode") == "1" || check_key_combo()) { get_prop("ro.sys.safemode") == "1" || check_key_combo()) {
safe_mode = true; safe_mode = true;
// Disable all modules and denylist so next boot will be clean // Disable all modules and zygisk so next boot will be clean
disable_modules(); disable_modules();
disable_deny(); disable_zygisk();
} else { return safe_mode;
}
exec_common_scripts("post-fs-data"); exec_common_scripts("post-fs-data");
db_settings dbs; db_settings dbs;
get_db_settings(dbs, ZYGISK_CONFIG); get_db_settings(dbs, ZYGISK_CONFIG);
zygisk_enabled = dbs[ZYGISK_CONFIG]; zygisk_enabled = dbs[ZYGISK_CONFIG];
initialize_denylist(); initialize_denylist();
setup_mounts();
handle_modules(); handle_modules();
}
early_abort:
load_modules(); load_modules();
return safe_mode; return safe_mode;
} }

View File

@ -138,7 +138,7 @@ test_emu() {
emu_pid=$! emu_pid=$!
wait_emu wait_for_boot wait_emu wait_for_boot
adb shell magisk -v adb shell 'PATH=$PATH:/debug_ramdisk magisk -v'
# Install the Magisk app # Install the Magisk app
adb install -r -g out/app-${variant}.apk adb install -r -g out/app-${variant}.apk
@ -149,7 +149,7 @@ test_emu() {
# Install LSPosed # Install LSPosed
if [ $api -ge $lsposed_min_api -a $api -le $atd_max_api ]; then if [ $api -ge $lsposed_min_api -a $api -le $atd_max_api ]; then
adb push out/lsposed.zip /data/local/tmp/lsposed.zip adb push out/lsposed.zip /data/local/tmp/lsposed.zip
adb shell echo 'magisk --install-module /data/local/tmp/lsposed.zip' \| /system/xbin/su adb shell echo 'PATH=$PATH:/debug_ramdisk magisk --install-module /data/local/tmp/lsposed.zip' \| /system/xbin/su
fi fi
adb reboot adb reboot