Revert "Use /data if possible"

This reverts commit 9fae52277e.
This commit is contained in:
Mygod
2020-08-07 23:15:57 +08:00
parent fbe67dc574
commit f1bead4316

View File

@@ -157,38 +157,28 @@ class RootServer @JvmOverloads constructor(private val warnLogger: (String) -> U
} }
val token2 = UUID.randomUUID().toString() val token2 = UUID.randomUUID().toString()
val uuid by lazy { val persistence = File(context.codeCacheDir, ".librootkotlinx-uuid")
val persistence = File(context.codeCacheDir, ".librootkotlinx-uuid") val uuid = context.packageName + '@' + if (persistence.canRead()) persistence.readText() else {
context.packageName + '@' + if (persistence.canRead()) persistence.readText() else { UUID.randomUUID().toString().also { persistence.writeText(it) }
UUID.randomUUID().toString().also { persistence.writeText(it) }
}
} }
// to workaround Samsung's stupid kernel patch, we need to relocate outside of /data: https://github.com/Chainfire/librootjava/issues/19 // to workaround Samsung's stupid kernel patch, we need to relocate outside of /data: https://github.com/Chainfire/librootjava/issues/19
val (baseDir, relocated) = if (Build.VERSION.SDK_INT < 29) "/dev" to "/dev/app_process_$uuid" else { val (baseDir, relocated) = if (Build.VERSION.SDK_INT < 29) "/dev" to "/dev/app_process_$uuid" else {
val cachePath = context.codeCacheDir.canonicalPath val apexPath = "/apex/$uuid"
if (cachePath.startsWith("/data/")) { writer.writeBytes("[ -d $apexPath ] || " +
val relocated = File(context.codeCacheDir, "relocated") "mkdir $apexPath && " +
relocated.mkdir() // we need to mount a new tmpfs to override noexec flag
check(relocated.isDirectory) "mount -t tmpfs -o size=1M tmpfs $apexPath || exit 1\n")
relocated.absolutePath to File(relocated, "app_process").absolutePath // unfortunately native ld.config.txt only recognizes /data,/system,/system_ext as system directories;
} else { // to link correctly, we need to add our path to the linker config too
val apexPath = "/apex/$uuid" val ldConfig = "$apexPath/etc/ld.config.txt"
writer.writeBytes("[ -d $apexPath ] || " + val masterLdConfig = if (Build.VERSION.SDK_INT == 29) {
"mkdir $apexPath && " + "/system/etc/ld.config.29.txt"
// we need to mount a new tmpfs to override noexec flag } else "/linkerconfig/ld.config.txt"
"mount -t tmpfs -o size=1M tmpfs $apexPath || exit 1\n") writer.writeBytes("[ -f $ldConfig ] || " +
// unfortunately native ld.config.txt only recognizes /data,/system,/system_ext as system directories; "mkdir -p $apexPath/etc && " +
// to link correctly, we need to add our path to the linker config too "echo dir.system = $apexPath >$ldConfig && " +
val ldConfig = "$apexPath/etc/ld.config.txt" "cat $masterLdConfig >>$ldConfig || exit 1\n")
val masterLdConfig = if (Build.VERSION.SDK_INT == 29) { "$apexPath/bin" to "$apexPath/bin/app_process"
"/system/etc/ld.config.29.txt"
} else "/linkerconfig/ld.config.txt"
writer.writeBytes("[ -f $ldConfig ] || " +
"mkdir -p $apexPath/etc && " +
"echo dir.system = $apexPath >$ldConfig && " +
"cat $masterLdConfig >>$ldConfig || exit 1\n")
"$apexPath/bin" to "$apexPath/bin/app_process"
}
} }
writer.writeBytes("[ -f $relocated ] || " + writer.writeBytes("[ -f $relocated ] || " +
"mkdir -p $baseDir && " + "mkdir -p $baseDir && " +