Use /data if possible

This commit is contained in:
Mygod
2020-08-07 09:53:08 +08:00
parent 4e9561fc86
commit 9fae52277e

View File

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