From 1024e68eb61db7a420965a7bb3da4357c726dfc8 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 26 Jan 2021 07:27:21 -0800 Subject: [PATCH] Remove class mapping in full APK --- app/src/main/AndroidManifest.xml | 14 ++++---- app/src/main/java/a/stubs.kt | 32 ------------------- .../java/com/topjohnwu/magisk/core/Hacks.kt | 32 ++++--------------- .../java/com/topjohnwu/signing/SignBoot.java | 2 ++ gradle.properties | 2 +- scripts/util_functions.sh | 2 +- 6 files changed, 17 insertions(+), 67 deletions(-) delete mode 100644 app/src/main/java/a/stubs.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 205590c53..45e880079 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,7 +4,7 @@ package="com.topjohnwu.magisk"> @@ -25,11 +25,11 @@ - + @@ -57,11 +57,11 @@ - + ) { - SignBoot.main(args) -} - -class b : MainActivity() - -class c : SplashActivity() - -class e : App { - constructor() : super() - constructor(o: Any) : super(o) -} - -class h : Receiver() - -class j : DownloadService() - -class m : SuRequestActivity() - -class p : Provider() diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt index 4df6924ca..a089074f9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt @@ -18,11 +18,8 @@ import android.util.DisplayMetrics import androidx.annotation.RequiresApi import com.topjohnwu.magisk.DynAPK import com.topjohnwu.magisk.R -import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.core.utils.refreshLocale import com.topjohnwu.magisk.core.utils.updateConfig -import com.topjohnwu.magisk.ui.MainActivity -import com.topjohnwu.magisk.ui.surequest.SuRequestActivity fun AssetManager.addAssetPath(path: String) { DynAPK.addAssetPath(this, path) @@ -47,10 +44,8 @@ fun Context.wrapJob(): Context = object : InjectedContext(this) { } } -fun Class<*>.cmp(pkg: String): ComponentName { - val name = ClassMap[this].name - return ComponentName(pkg, Info.stub?.classToComponent?.get(name) ?: name) -} +fun Class<*>.cmp(pkg: String) = + ComponentName(pkg, Info.stub?.classToComponent?.get(name) ?: name) inline fun Activity.redirect() = Intent(intent) .setComponent(T::class.java.cmp(packageName)) @@ -114,11 +109,10 @@ private class JobSchedulerWrapper(private val base: JobScheduler) : JobScheduler override fun getPendingJob(jobId: Int) = base.getPendingJob(jobId) private fun JobInfo.patch(): JobInfo { // Swap out the service of JobInfo - val name = service.className - val component = ComponentName( - service.packageName, - Info.stub!!.classToComponent[name] ?: name - ) + val component = service.run { + ComponentName(packageName, + Info.stub?.classToComponent?.get(className) ?: className) + } javaClass.getDeclaredField("service").apply { isAccessible = true }.set(this, component) @@ -127,20 +121,6 @@ private class JobSchedulerWrapper(private val base: JobScheduler) : JobScheduler } } -private object ClassMap { - - private val map = mapOf( - App::class.java to a.e::class.java, - MainActivity::class.java to a.b::class.java, - SplashActivity::class.java to a.c::class.java, - Receiver::class.java to a.h::class.java, - DownloadService::class.java to a.j::class.java, - SuRequestActivity::class.java to a.m::class.java - ) - - operator fun get(c: Class<*>) = map.getOrElse(c) { c } -} - // Keep a reference to these resources to prevent it from // being removed when running "remove unused resources" val shouldKeepResources = listOf( diff --git a/app/src/main/java/com/topjohnwu/signing/SignBoot.java b/app/src/main/java/com/topjohnwu/signing/SignBoot.java index 6f80a1fb5..6f934a492 100644 --- a/app/src/main/java/com/topjohnwu/signing/SignBoot.java +++ b/app/src/main/java/com/topjohnwu/signing/SignBoot.java @@ -1,5 +1,6 @@ package com.topjohnwu.signing; +import androidx.annotation.Keep; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -32,6 +33,7 @@ import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.Arrays; +@Keep public class SignBoot { private static final int BOOT_IMAGE_HEADER_V1_RECOVERY_DTBO_SIZE_OFFSET = 1632; diff --git a/gradle.properties b/gradle.properties index df57a2e79..ba351d39d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ android.injected.testOnly=false kapt.incremental.apt=true # Magisk -magisk.stubVersion=16 +magisk.stubVersion=17 magisk.versionCode=21405 magisk.ndkVersion=21d magisk.fullNdkVersion=21.3.6528147 diff --git a/scripts/util_functions.sh b/scripts/util_functions.sh index 8b2e24ced..748bb998a 100644 --- a/scripts/util_functions.sh +++ b/scripts/util_functions.sh @@ -779,7 +779,7 @@ NVBASE=/data/adb TMPDIR=/dev/tmp # Bootsigner related stuff -BOOTSIGNERCLASS=a.a +BOOTSIGNERCLASS=com.topjohnwu.signing.SignBoot BOOTSIGNER='/system/bin/dalvikvm -Xnoimage-dex2oat -cp $APK $BOOTSIGNERCLASS' BOOTSIGNED=false