Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.

Commit b08a8a2

Browse files
committed
Pack magiskboot to support other root solutions
1 parent 13ccf53 commit b08a8a2

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

app/src/main/assets/magiskboot

316 KB
Binary file not shown.

app/src/main/java/com/github/capntrips/kernelflasher/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class MainActivity : ComponentActivity() {
153153
Shell.cmd("cd $filesDir").exec()
154154
copyAsset("lptools_static")
155155
copyAsset("httools_static")
156+
copyAsset("magiskboot") // version: Magisk 25.2 stable release
156157
} catch (e: Exception) {
157158
Log.e(TAG, e.message, e)
158159
setContent {

app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotViewModel.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class SlotViewModel(
6767
private var inInit = true
6868
private var _error: String? = null
6969

70+
private val STOCK_MAGISKBOOT = "/data/adb/magisk/magiskboot"
71+
private var magiskboot: String = STOCK_MAGISKBOOT
72+
7073
val sha1: String
7174
get() = _sha1!!
7275
val flashOutput: List<String>
@@ -89,7 +92,12 @@ class SlotViewModel(
8992
}
9093

9194
fun refresh(context: Context) {
92-
Shell.cmd("/data/adb/magisk/magiskboot unpack $boot").exec()
95+
// init magiskboot
96+
if (!File(STOCK_MAGISKBOOT).exists()) {
97+
magiskboot = context.filesDir.absolutePath + File.separator + "magiskboot"
98+
}
99+
100+
Shell.cmd("$magiskboot unpack $boot").exec()
93101

94102
val ramdisk = File(context.filesDir, "ramdisk.cpio")
95103

@@ -108,18 +116,18 @@ class SlotViewModel(
108116
}
109117
}
110118

111-
val magiskboot = fileSystemManager.getFile("/data/adb/magisk/magiskboot")
119+
val magiskboot = fileSystemManager.getFile(magiskboot)
112120
if (magiskboot.exists()) {
113121
if (ramdisk.exists()) {
114-
when (Shell.cmd("/data/adb/magisk/magiskboot cpio ramdisk.cpio test").exec().code) {
115-
0 -> _sha1 = Shell.cmd("/data/adb/magisk/magiskboot sha1 $boot").exec().out.firstOrNull()
116-
1 -> _sha1 = Shell.cmd("/data/adb/magisk/magiskboot cpio ramdisk.cpio sha1").exec().out.firstOrNull()
122+
when (Shell.cmd("$magiskboot cpio ramdisk.cpio test").exec().code) {
123+
0 -> _sha1 = Shell.cmd("$magiskboot sha1 $boot").exec().out.firstOrNull()
124+
1 -> _sha1 = Shell.cmd("$magiskboot cpio ramdisk.cpio sha1").exec().out.firstOrNull()
117125
else -> log(context, "Invalid boot.img", shouldThrow = true)
118126
}
119127
} else {
120128
log(context, "Invalid boot.img", shouldThrow = true)
121129
}
122-
Shell.cmd("/data/adb/magisk/magiskboot cleanup").exec()
130+
Shell.cmd("$magiskboot cleanup").exec()
123131
} else {
124132
log(context, "magiskboot is missing", shouldThrow = true)
125133
}
@@ -238,15 +246,15 @@ class SlotViewModel(
238246

239247
@Suppress("FunctionName", "SameParameterValue")
240248
private fun _getKernel(context: Context) {
241-
Shell.cmd("/data/adb/magisk/magiskboot unpack $boot").exec()
249+
Shell.cmd("$magiskboot unpack $boot").exec()
242250
val kernel = File(context.filesDir, "kernel")
243251
if (kernel.exists()) {
244252
val result = Shell.cmd("strings kernel | grep -E -m1 'Linux version.*#' | cut -d\\ -f3-").exec().out
245253
if (result.isNotEmpty()) {
246254
kernelVersion = result[0].replace("""\(.+\)""".toRegex(), "").replace("""\s+""".toRegex(), " ")
247255
}
248256
}
249-
Shell.cmd("/data/adb/magisk/magiskboot cleanup").exec()
257+
Shell.cmd("$magiskboot cleanup").exec()
250258
}
251259

252260
fun getKernel(context: Context) {

0 commit comments

Comments
 (0)