Support restarting app when obfuscated

This commit is contained in:
topjohnwu
2019-11-03 02:55:12 -05:00
parent 14ba002cbc
commit 0c9feedb37
14 changed files with 46 additions and 57 deletions

View File

@@ -53,18 +53,12 @@ fun Context.wrapJob(): Context = object : GlobalResContext(this) {
}
}
fun Class<*>.cmp(pkg: String = BuildConfig.APPLICATION_ID): ComponentName {
fun Class<*>.cmp(pkg: String): ComponentName {
val name = ClassMap[this].name
return ComponentName(pkg, Info.stub?.componentMap?.get(name) ?: name)
}
fun Context.intent(c: Class<*>): Intent {
val cls = ClassMap[c]
return Info.stub?.let {
val className = it.componentMap.getOrElse(cls.name) { cls.name }
Intent().setComponent(ComponentName(this, className))
} ?: Intent(this, cls)
}
inline fun <reified T> Context.intent() = Intent().setComponent(T::class.java.cmp(packageName))
private open class GlobalResContext(base: Context) : ContextWrapper(base) {
open val mRes: Resources get() = ResourceMgr.resource
@@ -192,8 +186,9 @@ object ClassMap {
UpdateCheckService::class.java to a.g::class.java,
GeneralReceiver::class.java to a.h::class.java,
DownloadService::class.java to a.j::class.java,
SuRequestActivity::class.java to a.m::class.java
SuRequestActivity::class.java to a.m::class.java,
ProcessPhoenix::class.java to a.r::class.java
)
operator fun get(c: Class<*>) = map.getOrElse(c) { throw IllegalArgumentException() }
operator fun get(c: Class<*>) = map.getOrElse(c) { c }
}

View File

@@ -140,7 +140,7 @@ open class DownloadService : RemoteFileService() {
inline operator fun invoke(context: Context, argBuilder: Builder.() -> Unit) {
val app = context.applicationContext
val builder = Builder().apply(argBuilder)
val intent = app.intent(DownloadService::class.java).putExtra(ARG_URL, builder.subject)
val intent = app.intent<DownloadService>().putExtra(ARG_URL, builder.subject)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
app.startForegroundService(intent)

View File

@@ -38,7 +38,7 @@ private fun RemoteFileService.upgrade(apk: File, id: Int) {
patch(apk, id)
} else {
// Simply relaunch the app
ProcessPhoenix.triggerRebirth(this)
ProcessPhoenix.triggerRebirth(this, intent<ProcessPhoenix>())
}
} else {
patch(apk, id)

View File

@@ -63,7 +63,7 @@ open class GeneralReceiver : BaseReceiver() {
}
when (action) {
REQUEST -> {
val i = context.intent(SuRequestActivity::class.java)
val i = context.intent<SuRequestActivity>()
.setAction(action)
.putExtra("socket", intent.getStringExtra("socket"))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

View File

@@ -60,7 +60,7 @@ open class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Na
override fun onCreate(savedInstanceState: Bundle?) {
if (!SplashActivity.DONE) {
startActivity(intent(SplashActivity::class.java))
startActivity(intent<SplashActivity>())
finish()
}

View File

@@ -40,7 +40,7 @@ open class SplashActivity : Activity() {
Config.suManager = ""
Shell.su("pm uninstall $pkg").submit()
}
if (TextUtils.equals(pkg, packageName)) {
if (pkg == packageName) {
runCatching {
// We are the manager, remove com.topjohnwu.magisk as it could be malware
packageManager.getApplicationInfo(BuildConfig.APPLICATION_ID, 0)
@@ -60,10 +60,9 @@ open class SplashActivity : Activity() {
// Setup shortcuts
Shortcuts.setup(this)
val intent = intent(MainActivity::class.java)
intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION))
DONE = true
startActivity(intent)
startActivity(intent<MainActivity>().apply { intent?.also { putExtras(it) } })
finish()
}

View File

@@ -60,7 +60,7 @@ open class FlashActivity : BaseActivity<FlashViewModel, ActivityFlashBinding>()
companion object {
private fun intent(context: Context) = context.intent(FlashActivity::class.java)
private fun intent(context: Context) = context.intent<FlashActivity>()
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
private fun intent(context: Context, file: File) = intent(context).setData(file.toUri())

View File

@@ -28,7 +28,7 @@ class ModulesFragment : BaseFragment<ModuleViewModel, FragmentModulesBinding>()
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == Const.ID.FETCH_ZIP && resultCode == Activity.RESULT_OK && data != null) {
// Get the URI of the selected file
val intent = activity.intent(FlashActivity::class.java)
val intent = activity.intent<FlashActivity>()
intent.setData(data.data).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP)
startActivity(intent)
}

View File

@@ -47,7 +47,7 @@ object Notifications {
}
fun magiskUpdate(context: Context) {
val intent = context.intent(SplashActivity::class.java)
val intent = context.intent<SplashActivity>()
.putExtra(Const.Key.OPEN_SECTION, "magisk")
val stackBuilder = TaskStackBuilder.create(context)
stackBuilder.addParentStack(SplashActivity::class.java.cmp(context.packageName))
@@ -65,7 +65,7 @@ object Notifications {
}
fun managerUpdate(context: Context) {
val intent = context.intent(GeneralReceiver::class.java)
val intent = context.intent<GeneralReceiver>()
.setAction(Const.Key.BROADCAST_MANAGER_UPDATE)
.putExtra(Const.Key.INTENT_SET_APP, Info.remote.app)
@@ -82,7 +82,7 @@ object Notifications {
}
fun dtboPatched(context: Context) {
val intent = context.intent(GeneralReceiver::class.java)
val intent = context.intent<GeneralReceiver>()
.setAction(Const.Key.BROADCAST_REBOOT)
val pendingIntent = PendingIntent.getBroadcast(context,
Const.ID.DTBO_NOTIFICATION_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT)

View File

@@ -7,6 +7,7 @@ import android.content.pm.ShortcutManager
import android.graphics.drawable.Icon
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.content.getSystemService
import androidx.core.graphics.drawable.toAdaptiveIcon
import androidx.core.graphics.drawable.toIcon
import com.topjohnwu.magisk.*
@@ -19,7 +20,7 @@ object Shortcuts {
fun setup(context: Context) {
if (Build.VERSION.SDK_INT >= 25) {
val manager = context.getSystemService(ShortcutManager::class.java)
val manager = context.getSystemService<ShortcutManager>()
manager?.dynamicShortcuts = getShortCuts(context)
}
}
@@ -28,7 +29,7 @@ object Shortcuts {
private fun getShortCuts(context: Context): List<ShortcutInfo> {
val shortCuts = mutableListOf<ShortcutInfo>()
val root = Shell.rootAccess()
val intent = context.intent(SplashActivity::class.java)
val intent = context.intent<SplashActivity>()
fun getIcon(id: Int): Icon {
return if (Build.VERSION.SDK_INT >= 26)