Remove class mapping in full APK

This commit is contained in:
topjohnwu 2021-01-26 07:27:21 -08:00
parent 6ae2c9387d
commit 1024e68eb6
6 changed files with 17 additions and 67 deletions

View File

@ -4,7 +4,7 @@
package="com.topjohnwu.magisk"> package="com.topjohnwu.magisk">
<application <application
android:name="a.e" android:name=".core.App"
android:extractNativeLibs="true" android:extractNativeLibs="true"
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
android:multiArch="true" android:multiArch="true"
@ -12,7 +12,7 @@
<!-- Splash --> <!-- Splash -->
<activity <activity
android:name="a.c" android:name=".core.SplashActivity"
android:theme="@style/SplashTheme"> android:theme="@style/SplashTheme">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -25,11 +25,11 @@
</activity> </activity>
<!-- Main --> <!-- Main -->
<activity android:name="a.b" /> <activity android:name=".ui.MainActivity" />
<!-- Superuser --> <!-- Superuser -->
<activity <activity
android:name="a.m" android:name=".ui.surequest.SuRequestActivity"
android:directBootAware="true" android:directBootAware="true"
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:exported="false" android:exported="false"
@ -42,7 +42,7 @@
<!-- Receiver --> <!-- Receiver -->
<receiver <receiver
android:name="a.h" android:name=".core.Receiver"
android:directBootAware="true" android:directBootAware="true"
android:exported="false"> android:exported="false">
<intent-filter> <intent-filter>
@ -57,11 +57,11 @@
</receiver> </receiver>
<!-- DownloadService --> <!-- DownloadService -->
<service android:name="a.j" /> <service android:name=".core.download.DownloadService" />
<!-- FileProvider --> <!-- FileProvider -->
<provider <provider
android:name="a.p" android:name=".core.Provider"
android:authorities="${applicationId}.provider" android:authorities="${applicationId}.provider"
android:directBootAware="true" android:directBootAware="true"
android:exported="false" android:exported="false"

View File

@ -1,32 +0,0 @@
@file:JvmName("a")
package a
import com.topjohnwu.magisk.core.App
import com.topjohnwu.magisk.core.Provider
import com.topjohnwu.magisk.core.Receiver
import com.topjohnwu.magisk.core.SplashActivity
import com.topjohnwu.magisk.core.download.DownloadService
import com.topjohnwu.magisk.ui.MainActivity
import com.topjohnwu.magisk.ui.surequest.SuRequestActivity
import com.topjohnwu.signing.SignBoot
fun main(args: Array<String>) {
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()

View File

@ -18,11 +18,8 @@ import android.util.DisplayMetrics
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import com.topjohnwu.magisk.DynAPK import com.topjohnwu.magisk.DynAPK
import com.topjohnwu.magisk.R 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.refreshLocale
import com.topjohnwu.magisk.core.utils.updateConfig 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) { fun AssetManager.addAssetPath(path: String) {
DynAPK.addAssetPath(this, path) DynAPK.addAssetPath(this, path)
@ -47,10 +44,8 @@ fun Context.wrapJob(): Context = object : InjectedContext(this) {
} }
} }
fun Class<*>.cmp(pkg: String): ComponentName { fun Class<*>.cmp(pkg: String) =
val name = ClassMap[this].name ComponentName(pkg, Info.stub?.classToComponent?.get(name) ?: name)
return ComponentName(pkg, Info.stub?.classToComponent?.get(name) ?: name)
}
inline fun <reified T> Activity.redirect() = Intent(intent) inline fun <reified T> Activity.redirect() = Intent(intent)
.setComponent(T::class.java.cmp(packageName)) .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) override fun getPendingJob(jobId: Int) = base.getPendingJob(jobId)
private fun JobInfo.patch(): JobInfo { private fun JobInfo.patch(): JobInfo {
// Swap out the service of JobInfo // Swap out the service of JobInfo
val name = service.className val component = service.run {
val component = ComponentName( ComponentName(packageName,
service.packageName, Info.stub?.classToComponent?.get(className) ?: className)
Info.stub!!.classToComponent[name] ?: name }
)
javaClass.getDeclaredField("service").apply { javaClass.getDeclaredField("service").apply {
isAccessible = true isAccessible = true
}.set(this, component) }.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 // Keep a reference to these resources to prevent it from
// being removed when running "remove unused resources" // being removed when running "remove unused resources"
val shouldKeepResources = listOf( val shouldKeepResources = listOf(

View File

@ -1,5 +1,6 @@
package com.topjohnwu.signing; package com.topjohnwu.signing;
import androidx.annotation.Keep;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -32,6 +33,7 @@ import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.Arrays; import java.util.Arrays;
@Keep
public class SignBoot { public class SignBoot {
private static final int BOOT_IMAGE_HEADER_V1_RECOVERY_DTBO_SIZE_OFFSET = 1632; private static final int BOOT_IMAGE_HEADER_V1_RECOVERY_DTBO_SIZE_OFFSET = 1632;

View File

@ -27,7 +27,7 @@ android.injected.testOnly=false
kapt.incremental.apt=true kapt.incremental.apt=true
# Magisk # Magisk
magisk.stubVersion=16 magisk.stubVersion=17
magisk.versionCode=21405 magisk.versionCode=21405
magisk.ndkVersion=21d magisk.ndkVersion=21d
magisk.fullNdkVersion=21.3.6528147 magisk.fullNdkVersion=21.3.6528147

View File

@ -779,7 +779,7 @@ NVBASE=/data/adb
TMPDIR=/dev/tmp TMPDIR=/dev/tmp
# Bootsigner related stuff # Bootsigner related stuff
BOOTSIGNERCLASS=a.a BOOTSIGNERCLASS=com.topjohnwu.signing.SignBoot
BOOTSIGNER='/system/bin/dalvikvm -Xnoimage-dex2oat -cp $APK $BOOTSIGNERCLASS' BOOTSIGNER='/system/bin/dalvikvm -Xnoimage-dex2oat -cp $APK $BOOTSIGNERCLASS'
BOOTSIGNED=false BOOTSIGNED=false