Workaround zip extraction bug on older devices

This commit is contained in:
topjohnwu 2021-01-27 03:00:09 -08:00
parent c538a77937
commit 2a5f5b1bba

View File

@ -43,8 +43,7 @@ import java.io.*
import java.nio.ByteBuffer import java.nio.ByteBuffer
import java.security.SecureRandom import java.security.SecureRandom
import java.util.* import java.util.*
import java.util.zip.ZipEntry import java.util.zip.ZipFile
import java.util.zip.ZipInputStream
abstract class MagiskInstallImpl protected constructor( abstract class MagiskInstallImpl protected constructor(
protected val console: MutableList<String> = NOPList.getInstance(), protected val console: MutableList<String> = NOPList.getInstance(),
@ -111,22 +110,14 @@ abstract class MagiskInstallImpl protected constructor(
try { try {
// Extract binaries // Extract binaries
if (isRunningAsStub) { if (isRunningAsStub) {
ZipInputStream(DynAPK.current(context).inputStream().buffered()).use { zi -> val zf = ZipFile(DynAPK.current(context))
lateinit var ze: ZipEntry zf.entries().asSequence().filter {
while (zi.nextEntry?.let { ze = it } != null) { !it.isDirectory && it.name.startsWith("lib/${Const.CPU_ABI_32}/")
if (ze.isDirectory) }.forEach {
continue val n = it.name.substring(it.name.lastIndexOf('/') + 1)
val name = n.substring(3, n.length - 3)
val name = if (ze.name.startsWith("lib/${Const.CPU_ABI_32}/")) { val dest = File(binDir, name)
val n = ze.name.substring(ze.name.lastIndexOf('/') + 1) zf.getInputStream(it).writeTo(dest)
n.substring(3, n.length - 3)
} else {
continue
}
val dest = File(binDir, name)
dest.outputStream().use { zi.copyTo(it) }
}
} }
} else { } else {
val libs = Const.NATIVE_LIB_DIR.listFiles { _, name -> val libs = Const.NATIVE_LIB_DIR.listFiles { _, name ->