Refactoring to lazy
This commit is contained in:
@@ -11,24 +11,18 @@ object AppProcess {
|
|||||||
/**
|
/**
|
||||||
* Based on: https://android.googlesource.com/platform/bionic/+/aff9a34/linker/linker.cpp#3397
|
* Based on: https://android.googlesource.com/platform/bionic/+/aff9a34/linker/linker.cpp#3397
|
||||||
*/
|
*/
|
||||||
@get:RequiresApi(29)
|
@get:RequiresApi(28)
|
||||||
val genericLdConfigFilePath: String get() {
|
val genericLdConfigFilePath: String get() {
|
||||||
val classVMRuntime = Class.forName("dalvik.system.VMRuntime")
|
"/system/etc/ld.config.$currentInstructionSet.txt".let { if (File(it).isFile) return it }
|
||||||
val abiString = classVMRuntime.getDeclaredMethod("getCurrentInstructionSet").invoke(
|
|
||||||
classVMRuntime.getDeclaredMethod("getRuntime").invoke(null))
|
|
||||||
"/system/etc/ld.config.$abiString.txt".let { if (File(it).isFile) return it }
|
|
||||||
if (Build.VERSION.SDK_INT >= 30) "/linkerconfig/ld.config.txt".let {
|
if (Build.VERSION.SDK_INT >= 30) "/linkerconfig/ld.config.txt".let {
|
||||||
check(File(it).isFile) { "failed to find generated linker configuration from \"$it\"" }
|
check(File(it).isFile) { "failed to find generated linker configuration from \"$it\"" }
|
||||||
return it
|
return it
|
||||||
}
|
}
|
||||||
val prop = Class.forName("android.os.SystemProperties")
|
if (isVndkLite) {
|
||||||
if (prop.getDeclaredMethod("getBoolean", String::class.java, Boolean::class.java).invoke(null,
|
"/system/etc/ld.config.vndk_lite.txt".let { if (File(it).isFile) return it }
|
||||||
"ro.vndk.lite", false) as Boolean) "/system/etc/ld.config.vndk_lite.txt".let {
|
} else when (vndkVersion) {
|
||||||
if (File(it).isFile) return it
|
|
||||||
} else when (val version = prop.getDeclaredMethod("get", String::class.java, String::class.java).invoke(null,
|
|
||||||
"ro.vndk.version", "") as String) {
|
|
||||||
"", "current" -> { }
|
"", "current" -> { }
|
||||||
else -> "/system/etc/ld.config.$version.txt".let { if (File(it).isFile) return it }
|
else -> "/system/etc/ld.config.$vndkVersion.txt".let { if (File(it).isFile) return it }
|
||||||
}
|
}
|
||||||
return "/system/etc/ld.config.txt"
|
return "/system/etc/ld.config.txt"
|
||||||
}
|
}
|
||||||
@@ -36,7 +30,7 @@ object AppProcess {
|
|||||||
/**
|
/**
|
||||||
* Based on: https://android.googlesource.com/platform/bionic/+/30f2f05/linker/linker_config.cpp#182
|
* Based on: https://android.googlesource.com/platform/bionic/+/30f2f05/linker/linker_config.cpp#182
|
||||||
*/
|
*/
|
||||||
@RequiresApi(29)
|
@RequiresApi(26)
|
||||||
fun findLinkerSection(lines: Sequence<String>, binaryRealPath: String): String {
|
fun findLinkerSection(lines: Sequence<String>, binaryRealPath: String): String {
|
||||||
for (untrimmed in lines) {
|
for (untrimmed in lines) {
|
||||||
val line = untrimmed.substringBefore('#').trim()
|
val line = untrimmed.substringBefore('#').trim()
|
||||||
|
|||||||
@@ -7,10 +7,29 @@ import android.content.Context
|
|||||||
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
|
||||||
|
|
||||||
class NoShellException(cause: Throwable) : Exception("Root missing", cause)
|
class NoShellException(cause: Throwable) : Exception("Root missing", cause)
|
||||||
|
|
||||||
|
val currentInstructionSet by lazy {
|
||||||
|
val classVMRuntime = Class.forName("dalvik.system.VMRuntime")
|
||||||
|
val runtime = classVMRuntime.getDeclaredMethod("getRuntime").invoke(null)
|
||||||
|
classVMRuntime.getDeclaredMethod("getCurrentInstructionSet").invoke(runtime) as String
|
||||||
|
}
|
||||||
|
|
||||||
|
private val classSystemProperties by lazy { Class.forName("android.os.SystemProperties") }
|
||||||
|
@get:RequiresApi(26)
|
||||||
|
val isVndkLite by lazy {
|
||||||
|
classSystemProperties.getDeclaredMethod("getBoolean", String::class.java, Boolean::class.java).invoke(null,
|
||||||
|
"ro.vndk.lite", false) as Boolean
|
||||||
|
}
|
||||||
|
@get:RequiresApi(26)
|
||||||
|
val vndkVersion by lazy {
|
||||||
|
classSystemProperties.getDeclaredMethod("get", String::class.java, String::class.java).invoke(null,
|
||||||
|
"ro.vndk.version", "") as String
|
||||||
|
}
|
||||||
|
|
||||||
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