From beb643678d5bf7783e3ae7d2fc2ea4cfa572898d Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sat, 26 Oct 2024 15:47:36 -0400 Subject: [PATCH] refactor: Simplify extensions register declaration (#3084) --- .../misc/extension/hooks/StartActivityInitHook.kt | 2 +- .../googlephotos/misc/extension/Fingerprints.kt | 2 +- .../shared/misc/extension/SharedExtensionPatch.kt | 12 ++++++------ .../patches/youtube/misc/settings/SettingsPatch.kt | 1 - 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/googlenews/misc/extension/hooks/StartActivityInitHook.kt b/patches/src/main/kotlin/app/revanced/patches/googlenews/misc/extension/hooks/StartActivityInitHook.kt index 558b24eba..4e9e5c14c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlenews/misc/extension/hooks/StartActivityInitHook.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlenews/misc/extension/hooks/StartActivityInitHook.kt @@ -20,7 +20,7 @@ internal val startActivityInitHook = extensionHook( contextRegisterResolver = { method -> val moveResultInstruction = method.implementation!!.instructions.elementAt(getApplicationContextIndex + 1) as OneRegisterInstruction - moveResultInstruction.registerA + "v${moveResultInstruction.registerA}" }, ) { opcodes( diff --git a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/extension/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/extension/Fingerprints.kt index 84e6d5876..ca1065faa 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/extension/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/extension/Fingerprints.kt @@ -20,7 +20,7 @@ internal val homeActivityInitHook = extensionHook( contextRegisterResolver = { method -> val moveResultInstruction = method.implementation!!.instructions.elementAt(getApplicationContextIndex + 1) as OneRegisterInstruction - moveResultInstruction.registerA + "v${moveResultInstruction.registerA}" }, ) { opcodes( diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/extension/SharedExtensionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/extension/SharedExtensionPatch.kt index 3d7a1e444..a53102f9e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/extension/SharedExtensionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/extension/SharedExtensionPatch.kt @@ -7,7 +7,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.fingerprint import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.bytecodePatch -import app.revanced.util.exception +import app.revanced.util.matchOrThrow import com.android.tools.smali.dexlib2.iface.Method import java.net.URLDecoder import java.util.jar.JarFile @@ -77,24 +77,24 @@ fun sharedExtensionPatch( class ExtensionHook internal constructor( val fingerprint: Fingerprint, private val insertIndexResolver: ((Method) -> Int), - private val contextRegisterResolver: (Method) -> Int, + private val contextRegisterResolver: (Method) -> String, ) { operator fun invoke(extensionClassDescriptor: String) { - fingerprint.match?.mutableMethod?.let { method -> + fingerprint.matchOrThrow.mutableMethod.let { method -> val insertIndex = insertIndexResolver(method) val contextRegister = contextRegisterResolver(method) method.addInstruction( insertIndex, - "invoke-static/range { v$contextRegister .. v$contextRegister }, " + + "invoke-static/range { $contextRegister .. $contextRegister }, " + "$extensionClassDescriptor->setContext(Landroid/content/Context;)V", ) - } ?: throw fingerprint.exception + } } } fun extensionHook( insertIndexResolver: ((Method) -> Int) = { 0 }, - contextRegisterResolver: (Method) -> Int = { it.implementation!!.registerCount - 1 }, + contextRegisterResolver: (Method) -> String = { "p0" }, fingerprintBuilderBlock: FingerprintBuilder.() -> Unit, ) = ExtensionHook(fingerprint(block = fingerprintBuilderBlock), insertIndexResolver, contextRegisterResolver) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsPatch.kt index 5a731c905..183950b03 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsPatch.kt @@ -239,7 +239,6 @@ object PreferenceScreen : BasePreferenceScreen() { val SHORTS = Screen( key = "revanced_settings_screen_06_shorts", summaryKey = null, - sorting = Sorting.UNSORTED, ) // Don't sort, because title sorting scatters the custom color preferences.