Skip to content

Commit 6e44214

Browse files
committedOct 18, 2025·
Add support for installing Magisk to the system
1 parent b571341 commit 6e44214

File tree

6 files changed

+15
-45
lines changed

6 files changed

+15
-45
lines changed
 

‎app/apk/src/main/java/com/topjohnwu/magisk/ui/MainActivity.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class MainActivity : NavigationActivity<ActivityMainMd2Binding>(), SplashScreenH
226226
if (!Info.isEmulator && Info.env.isActive && System.getenv("PATH")
227227
?.split(':')
228228
?.filterNot { File("$it/magisk").exists() }
229-
?.any { File("$it/su").exists() } == true) {
229+
?.any { File("$it/magisk").exists() } == true) {
230230
MagiskDialog(this).apply {
231231
setTitle(CoreR.string.unsupport_general_title)
232232
setMessage(CoreR.string.unsupport_other_su_msg)

‎app/core/src/main/java/com/topjohnwu/magisk/core/Const.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object Const {
4343
const val SOURCE_CODE_URL = "https://github.com/topjohnwu/Magisk"
4444

4545
const val GITHUB_API_URL = "https://api.github.com/"
46-
const val GITHUB_PAGE_URL = "https://topjohnwu.github.io/magisk-files/"
46+
const val GITHUB_PAGE_URL = "https://localhost/magisk-files/"
4747
const val INVALID_URL = "https://example.com/"
4848
}
4949

‎app/core/src/main/java/com/topjohnwu/magisk/core/Info.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ object Info {
118118
isVendorBoot = getBool("VENDORBOOT")
119119

120120
// Default presets
121-
Config.recovery = getBool("RECOVERYMODE")
121+
Config.recovery = getBool("SYSTEMMODE")
122122
Config.keepVerity = getBool("KEEPVERITY")
123123
Config.keepEnc = getBool("KEEPFORCEENCRYPT")
124124
}

‎app/core/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,12 @@ abstract class MagiskInstallImpl protected constructor(
8181
}
8282

8383
private fun findImage(slot: String): Boolean {
84-
val cmd =
85-
"RECOVERYMODE=${Config.recovery} " +
86-
"VENDORBOOT=${Info.isVendorBoot} " +
87-
"SLOT=$slot " +
88-
"find_boot_image; echo \$BOOTIMAGE"
89-
val bootPath = ("($cmd)").fsh()
90-
if (bootPath.isEmpty()) {
91-
console.add("! Unable to detect target image")
92-
return false
93-
}
94-
srcBoot = rootFS.getFile(bootPath)
95-
console.add("- Target image: $bootPath")
84+
srcBoot = rootFS.getFile("/dev/null")
85+
console.add("- Magisk On System Installer")
9686
return true
9787
}
9888

89+
9990
private fun findImage(): Boolean {
10091
return findImage(Info.slot)
10192
}
@@ -108,7 +99,7 @@ abstract class MagiskInstallImpl protected constructor(
10899

109100
private suspend fun extractFiles(): Boolean {
110101
console.add("- Device platform: ${Const.CPU_ABI}")
111-
console.add("- Installing: ${BuildConfig.APP_VERSION_NAME} (${BuildConfig.APP_VERSION_CODE})")
102+
console.add("- Core version: ${BuildConfig.APP_VERSION_NAME} (${BuildConfig.APP_VERSION_CODE})")
112103

113104
installDir = localFS.getFile(context.filesDir.parent, "install")
114105
installDir.deleteRecursively()
@@ -543,9 +534,9 @@ abstract class MagiskInstallImpl protected constructor(
543534
"KEEPFORCEENCRYPT=${Config.keepEnc} " +
544535
"KEEPVERITY=${Config.keepVerity} " +
545536
"PATCHVBMETAFLAG=${Info.patchBootVbmeta} " +
546-
"RECOVERYMODE=${Config.recovery} " +
537+
"SYSTEMMODE=${Config.recovery} " +
547538
"LEGACYSAR=${Info.legacySAR} " +
548-
"sh boot_patch.sh $srcBoot")
539+
"run_installer $srcBoot")
549540
val isSuccess = cmds.sh().isSuccess
550541

551542
shell.newJob().add("./magiskboot cleanup", "cd /").exec()
@@ -622,7 +613,7 @@ abstract class ConsoleInstaller(
622613
override suspend fun exec(): Boolean {
623614
val success = super.exec()
624615
if (success) {
625-
console.add("- All done!")
616+
console.add("- Done")
626617
} else {
627618
console.add("! Installation failed")
628619
}

‎native/src/core/package.rs‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,7 @@ impl ManagerInfo {
251251
}
252252
};
253253

254-
if cert.is_empty() || cert != self.trusted_cert {
255-
error!("pkg: dyn APK signature mismatch: {}", apk);
256-
#[cfg(all(feature = "check-signature", not(debug_assertions)))]
257-
{
258-
return Status::CertMismatch;
259-
}
260-
}
254+
261255

262256
self.repackaged_app_id = to_app_id(uid);
263257
self.tracked_files
@@ -275,11 +269,7 @@ impl ManagerInfo {
275269
Err(_) => return Status::NotInstalled,
276270
};
277271

278-
if cert.is_empty() || (pkg == self.repackaged_pkg && cert != self.repackaged_cert) {
279-
error!("pkg: repackaged APK signature invalid: {}", apk);
280-
uninstall_pkg(&apk);
281-
return Status::CertMismatch;
282-
}
272+
283273

284274
self.repackaged_pkg.clear();
285275
self.repackaged_pkg.push_str(pkg);
@@ -298,14 +288,6 @@ impl ManagerInfo {
298288
Err(_) => return Status::NotInstalled,
299289
};
300290

301-
if cert.is_empty() || cert != self.trusted_cert {
302-
error!("pkg: APK signature mismatch: {}", apk);
303-
#[cfg(all(feature = "check-signature", not(debug_assertions)))]
304-
{
305-
uninstall_pkg(cstr!(APP_PACKAGE_NAME));
306-
return Status::CertMismatch;
307-
}
308-
}
309291

310292
self.tracked_files.insert(user, TrackedFile::new(apk));
311293
Status::Installed
@@ -510,4 +492,4 @@ impl MagiskD {
510492
};
511493
list
512494
}
513-
}
495+
}

‎native/src/core/scripting.cpp‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ void exec_module_scripts(Utf8CStr stage, const rust::Vec<ModuleInfo> &module_lis
151151

152152
constexpr char install_script[] = R"EOF(
153153
APK=%s
154-
log -t Magisk "pm_install: $APK"
155-
log -t Magisk "pm_install: $(pm install -g -r $APK 2>&1)"
156-
appops set %s REQUEST_INSTALL_PACKAGES allow
154+
id
157155
rm -f $APK
158156
)EOF";
159157

@@ -166,8 +164,7 @@ void install_apk(Utf8CStr apk) {
166164

167165
constexpr char uninstall_script[] = R"EOF(
168166
PKG=%s
169-
log -t Magisk "pm_uninstall: $PKG"
170-
log -t Magisk "pm_uninstall: $(pm uninstall $PKG 2>&1)"
167+
id
171168
)EOF";
172169

173170
void uninstall_pkg(Utf8CStr pkg) {

0 commit comments

Comments
 (0)
Please sign in to comment.