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

Commit c834f5f

Browse files
committed
run update-binary in a tmpfs chroot
1 parent 762583c commit c834f5f

File tree

3 files changed

+41
-22
lines changed

3 files changed

+41
-22
lines changed

app/src/main/assets/flash_ak3.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/system/bin/sh
2+
3+
## setup for testing:
4+
unzip -p $Z tools*/busybox > $F/busybox;
5+
unzip -p $Z META-INF/com/google/android/update-binary > $F/update-binary;
6+
##
7+
8+
chmod 755 $F/busybox;
9+
$F/busybox chmod 755 $F/update-binary;
10+
$F/busybox chown root:root $F/busybox $F/update-binary;
11+
12+
TMP=$F/tmp;
13+
14+
$F/busybox umount $TMP 2>/dev/null;
15+
$F/busybox rm -rf $TMP 2>/dev/null;
16+
$F/busybox mkdir -p $TMP;
17+
18+
$F/busybox mount -t tmpfs -o noatime tmpfs $TMP;
19+
$F/busybox mount | $F/busybox grep -q " $TMP " || exit 1;
20+
21+
# update-binary <RECOVERY_API_VERSION> <OUTFD> <ZIPFILE>
22+
AKHOME=$TMP/anykernel $F/busybox ash $F/update-binary 3 1 "$Z";
23+
RC=$?;
24+
25+
$F/busybox umount $TMP;
26+
$F/busybox rm -rf $TMP;
27+
$F/busybox mount -o ro,remount -t auto /;
28+
$F/busybox rm -f $F/update-binary $F/busybox;
29+
30+
# work around libsu not cleanly accepting return or exit as last line
31+
safereturn() { return $RC; }
32+
safereturn;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class MainActivity : ComponentActivity() {
154154
copyAsset("lptools_static")
155155
copyAsset("httools_static")
156156
copyAsset("magiskboot") // version: Magisk 25.2 stable release
157+
copyAsset("flash_ak3.sh")
157158
} catch (e: Exception) {
158159
Log.e(TAG, e.message, e)
159160
setContent {

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ class SlotViewModel(
196196
zip.delete()
197197
}
198198
}
199-
val akHome = File(context.filesDir, "akhome")
200-
if (akHome.exists()) {
201-
Shell.cmd("rm -r $akHome").exec()
202-
}
203199
}
204200

205201
@Suppress("FunctionName")
@@ -509,29 +505,19 @@ class SlotViewModel(
509505
if (!isActive) {
510506
resetSlot()
511507
}
512-
val zip = File(context.filesDir, flashFilename!!)
508+
val zip = File(context.filesDir.canonicalPath, flashFilename!!)
513509
_checkZip(context, zip)
514-
val akHome = File(context.filesDir, "akhome")
515510
try {
516511
if (zip.exists()) {
517-
akHome.mkdir()
518512
_wasFlashSuccess.value = false
519-
if (akHome.exists()) {
520-
val updateBinary = File(akHome, "update-binary")
521-
Shell.cmd("unzip -p \"$zip\" META-INF/com/google/android/update-binary > $akHome/update-binary").exec()
522-
if (updateBinary.exists()) {
523-
val result = Shell.Builder.create().setFlags(Shell.FLAG_MOUNT_MASTER or Shell.FLAG_REDIRECT_STDERR).build().newJob().add("AKHOME=$akHome /system/bin/sh $akHome/update-binary 3 1 \"$zip\"").to(flashOutput).exec()
524-
if (result.isSuccess) {
525-
log(context, "Kernel flashed successfully")
526-
_wasFlashSuccess.value = true
527-
} else {
528-
log(context, "Failed to flash zip", shouldThrow = false)
529-
}
530-
} else {
531-
log(context, "Failed to extract update-binary", shouldThrow = true)
532-
}
513+
val files = File(context.filesDir.canonicalPath)
514+
val flashScript = File(files, "flash_ak3.sh")
515+
val result = Shell.Builder.create().setFlags(Shell.FLAG_MOUNT_MASTER or Shell.FLAG_REDIRECT_STDERR).build().newJob().add("F=$files Z=\"$zip\" /system/bin/sh $flashScript").to(flashOutput).exec()
516+
if (result.isSuccess) {
517+
log(context, "Kernel flashed successfully")
518+
_wasFlashSuccess.value = true
533519
} else {
534-
log(context, "Failed to create temporary folder", shouldThrow = true)
520+
log(context, "Failed to flash zip", shouldThrow = false)
535521
}
536522
clearTmp(context)
537523
} else {

0 commit comments

Comments
 (0)