From 2a5f5b1bba933ba8300aabb7dc8a22f0c2c801e8 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 27 Jan 2021 03:00:09 -0800 Subject: [PATCH] Workaround zip extraction bug on older devices --- .../magisk/core/tasks/MagiskInstaller.kt | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt index e34fce356..df37e396d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt @@ -43,8 +43,7 @@ import java.io.* import java.nio.ByteBuffer import java.security.SecureRandom import java.util.* -import java.util.zip.ZipEntry -import java.util.zip.ZipInputStream +import java.util.zip.ZipFile abstract class MagiskInstallImpl protected constructor( protected val console: MutableList = NOPList.getInstance(), @@ -111,22 +110,14 @@ abstract class MagiskInstallImpl protected constructor( try { // Extract binaries if (isRunningAsStub) { - ZipInputStream(DynAPK.current(context).inputStream().buffered()).use { zi -> - lateinit var ze: ZipEntry - while (zi.nextEntry?.let { ze = it } != null) { - if (ze.isDirectory) - continue - - val name = if (ze.name.startsWith("lib/${Const.CPU_ABI_32}/")) { - val n = ze.name.substring(ze.name.lastIndexOf('/') + 1) - n.substring(3, n.length - 3) - } else { - continue - } - - val dest = File(binDir, name) - dest.outputStream().use { zi.copyTo(it) } - } + val zf = ZipFile(DynAPK.current(context)) + zf.entries().asSequence().filter { + !it.isDirectory && it.name.startsWith("lib/${Const.CPU_ABI_32}/") + }.forEach { + val n = it.name.substring(it.name.lastIndexOf('/') + 1) + val name = n.substring(3, n.length - 3) + val dest = File(binDir, name) + zf.getInputStream(it).writeTo(dest) } } else { val libs = Const.NATIVE_LIB_DIR.listFiles { _, name ->