Refine relocate heuristics
This commit is contained in:
2
mobile/proguard-rules.pro
vendored
2
mobile/proguard-rules.pro
vendored
@@ -22,7 +22,7 @@
|
|||||||
#-renamesourcefileattribute SourceFile
|
#-renamesourcefileattribute SourceFile
|
||||||
|
|
||||||
-if public class be.mygod.librootkotlinx.RootServer {
|
-if public class be.mygod.librootkotlinx.RootServer {
|
||||||
private void doInit(android.content.Context, java.lang.String, boolean);
|
private void doInit(android.content.Context, boolean, java.lang.String);
|
||||||
}
|
}
|
||||||
-keep class be.mygod.librootkotlinx.RootServer {
|
-keep class be.mygod.librootkotlinx.RootServer {
|
||||||
public static void main(java.lang.String[]);
|
public static void main(java.lang.String[]);
|
||||||
|
|||||||
@@ -71,6 +71,13 @@ object AppProcess {
|
|||||||
"/system/bin/app_process"
|
"/system/bin/app_process"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to guess whether enabling relocation would work best.
|
||||||
|
* It seems some Android 5-7 devices give random permission denials without relocation.
|
||||||
|
* See also VPNHotspot#173.
|
||||||
|
*/
|
||||||
|
val shouldRelocateHeuristics get() = Build.VERSION.SDK_INT < 26 || myExeCanonical.startsWith("/data/")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To workaround Samsung's stupid kernel patch that prevents exec, we need to relocate exe outside of /data.
|
* To workaround Samsung's stupid kernel patch that prevents exec, we need to relocate exe outside of /data.
|
||||||
* See also: https://github.com/Chainfire/librootjava/issues/19
|
* See also: https://github.com/Chainfire/librootjava/issues/19
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class RootServer {
|
|||||||
Logger.me.w(line)
|
Logger.me.w(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private fun doInit(context: Context, niceName: String, shouldRelocate: Boolean = false) {
|
private fun doInit(context: Context, shouldRelocate: Boolean, niceName: String) {
|
||||||
try {
|
try {
|
||||||
val (reader, writer) = try {
|
val (reader, writer) = try {
|
||||||
process = ProcessBuilder("su").start()
|
process = ProcessBuilder("su").start()
|
||||||
@@ -207,22 +207,12 @@ class RootServer {
|
|||||||
* Initialize a RootServer synchronously, can throw a lot of exceptions.
|
* Initialize a RootServer synchronously, can throw a lot of exceptions.
|
||||||
*
|
*
|
||||||
* @param context Any [Context] from the app.
|
* @param context Any [Context] from the app.
|
||||||
|
* @param shouldRelocate Whether app process should be copied first. See also [AppProcess.shouldRelocateHeuristics].
|
||||||
* @param niceName Name to call the rooted Java process.
|
* @param niceName Name to call the rooted Java process.
|
||||||
*/
|
*/
|
||||||
suspend fun init(context: Context, niceName: String = "${context.packageName}:root") {
|
suspend fun init(context: Context, shouldRelocate: Boolean = false,
|
||||||
withContext(Dispatchers.IO) {
|
niceName: String = "${context.packageName}:root") {
|
||||||
if (AppProcess.myExeCanonical.startsWith("/data/")) doInit(context, niceName, true) else try { // #173
|
withContext(Dispatchers.IO) { doInit(context, shouldRelocate, niceName) }
|
||||||
doInit(context, niceName)
|
|
||||||
} catch (e: LaunchException) {
|
|
||||||
try {
|
|
||||||
doInit(context, niceName, true)
|
|
||||||
} catch (e2: LaunchException) {
|
|
||||||
e2.addSuppressed(e)
|
|
||||||
throw e2
|
|
||||||
}
|
|
||||||
Logger.me.w("Root without relocation has failed", RuntimeException(e))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
callbackListenerExit = GlobalScope.async(Dispatchers.IO) {
|
callbackListenerExit = GlobalScope.async(Dispatchers.IO) {
|
||||||
val errorReader = async(Dispatchers.IO) {
|
val errorReader = async(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import be.mygod.librootkotlinx.*
|
|||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.util.Services
|
import be.mygod.vpnhotspot.util.Services
|
||||||
import be.mygod.vpnhotspot.util.UnblockCentral
|
import be.mygod.vpnhotspot.util.UnblockCentral
|
||||||
|
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
@@ -45,7 +46,10 @@ object RootManager : RootSession(), Logger {
|
|||||||
|
|
||||||
override suspend fun initServer(server: RootServer) {
|
override suspend fun initServer(server: RootServer) {
|
||||||
Logger.me = this
|
Logger.me = this
|
||||||
server.init(app.deviceStorage)
|
AppProcess.shouldRelocateHeuristics.let {
|
||||||
|
FirebaseCrashlytics.getInstance().setCustomKey("RootManager.relocateEnabled", it)
|
||||||
|
server.init(app.deviceStorage, it)
|
||||||
|
}
|
||||||
server.execute(RootInit())
|
server.execute(RootInit())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user