Refine locating ld.config.txt
This commit is contained in:
@@ -171,13 +171,10 @@ class RootServer @JvmOverloads constructor(private val warnLogger: (String) -> U
|
|||||||
// unfortunately native ld.config.txt only recognizes /data,/system,/system_ext as system directories;
|
// unfortunately native ld.config.txt only recognizes /data,/system,/system_ext as system directories;
|
||||||
// to link correctly, we need to add our path to the linker config too
|
// to link correctly, we need to add our path to the linker config too
|
||||||
val ldConfig = "$apexPath/etc/ld.config.txt"
|
val ldConfig = "$apexPath/etc/ld.config.txt"
|
||||||
val masterLdConfig = if (Build.VERSION.SDK_INT == 29) {
|
|
||||||
"/system/etc/ld.config.29.txt"
|
|
||||||
} else "/linkerconfig/ld.config.txt"
|
|
||||||
writer.writeBytes("[ -f $ldConfig ] || " +
|
writer.writeBytes("[ -f $ldConfig ] || " +
|
||||||
"mkdir -p $apexPath/etc && " +
|
"mkdir -p $apexPath/etc && " +
|
||||||
"echo dir.system = $apexPath >$ldConfig && " +
|
"echo dir.system = $apexPath >$ldConfig && " +
|
||||||
"cat $masterLdConfig >>$ldConfig || exit 1\n")
|
"cat $genericLdConfigFilePath >>$ldConfig || exit 1\n")
|
||||||
"$apexPath/bin" to "$apexPath/bin/app_process"
|
"$apexPath/bin" to "$apexPath/bin/app_process"
|
||||||
}
|
}
|
||||||
writer.writeBytes("[ -f $relocated ] || " +
|
writer.writeBytes("[ -f $relocated ] || " +
|
||||||
|
|||||||
@@ -4,13 +4,37 @@ package be.mygod.librootkotlinx
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
import android.os.Parcel
|
import android.os.Parcel
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.util.*
|
import android.util.*
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class NoShellException(cause: Throwable) : Exception("Root missing", cause)
|
class NoShellException(cause: Throwable) : Exception("Root missing", cause)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on: https://android.googlesource.com/platform/bionic/+/aff9a34/linker/linker.cpp#3397
|
||||||
|
*/
|
||||||
|
@get:RequiresApi(29)
|
||||||
|
val genericLdConfigFilePath: String get() {
|
||||||
|
"/system/etc/ld.config.${Build.VERSION.SDK_INT}.txt".let { if (File(it).isFile) return it }
|
||||||
|
if (Build.VERSION.SDK_INT >= 30) "/linkerconfig/ld.config.txt".let {
|
||||||
|
check(File(it).isFile) { "failed to find generated linker configuration from \"$it\"" }
|
||||||
|
return it
|
||||||
|
}
|
||||||
|
val prop = Class.forName("android.os.SystemProperties")
|
||||||
|
if (prop.getDeclaredMethod("getBoolean", String::class.java, Boolean::class.java).invoke(null,
|
||||||
|
"ro.vndk.lite", false) as Boolean) return "/system/etc/ld.config.vndk_lite.txt"
|
||||||
|
when (val version = prop.getDeclaredMethod("get", String::class.java, String::class.java).invoke(null,
|
||||||
|
"ro.vndk.version", "") as String) {
|
||||||
|
"", "current" -> { }
|
||||||
|
else -> "/system/etc/ld.config.$version.txt".let { if (File(it).isFile) return it }
|
||||||
|
}
|
||||||
|
return "/system/etc/ld.config.txt"
|
||||||
|
}
|
||||||
|
|
||||||
val systemContext by lazy {
|
val systemContext by lazy {
|
||||||
val classActivityThread = Class.forName("android.app.ActivityThread")
|
val classActivityThread = Class.forName("android.app.ActivityThread")
|
||||||
val activityThread = classActivityThread.getMethod("systemMain").invoke(null)
|
val activityThread = classActivityThread.getMethod("systemMain").invoke(null)
|
||||||
|
|||||||
Reference in New Issue
Block a user