From 6b826bd0f705a269f70eedce08d92b94ed1e9628 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 23 Jul 2023 15:20:02 +0900 Subject: [PATCH] feat(reddit/hide-navigation-buttons): supports the latest version --- .../NavigationButtonsCompatibility.kt | 8 ------ .../BottomNavScreenFingerprint.kt | 10 +++---- .../navigation/patch/CreateButtonPatch.kt | 4 +-- .../navigation/patch/DiscoverButtonPatch.kt | 4 +-- .../patch/NavigationButtonsPatch.kt | 26 +++++-------------- 5 files changed, 16 insertions(+), 36 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/navigation/annotations/NavigationButtonsCompatibility.kt diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/annotations/NavigationButtonsCompatibility.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/annotations/NavigationButtonsCompatibility.kt deleted file mode 100644 index 187cb5e986..0000000000 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/annotations/NavigationButtonsCompatibility.kt +++ /dev/null @@ -1,8 +0,0 @@ -package app.revanced.patches.reddit.layout.navigation.annotations - -import app.revanced.patcher.annotation.Compatibility -import app.revanced.patcher.annotation.Package - -@Compatibility([Package("com.reddit.frontpage", arrayOf("2023.16.1"))]) -@Target(AnnotationTarget.CLASS) -internal annotation class NavigationButtonsCompatibility diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/fingerprints/BottomNavScreenFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/fingerprints/BottomNavScreenFingerprint.kt index 7beefb11fa..c583ea9229 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/fingerprints/BottomNavScreenFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/fingerprints/BottomNavScreenFingerprint.kt @@ -8,12 +8,12 @@ import org.jf.dexlib2.Opcode object BottomNavScreenFingerprint : MethodFingerprint( returnType = "V", accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf("L", "L", "Z", "L", "L"), + parameters = emptyList(), opcodes = listOf( Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.INVOKE_INTERFACE, - Opcode.MOVE_RESULT_OBJECT + Opcode.RETURN_VOID ), - customFingerprint = { _, classDef -> classDef.type.startsWith("Lcom/reddit/launch/bottomnav/BottomNavScreen\$") } + customFingerprint = { methodDef, classDef -> + methodDef.name == "onGlobalLayout" + && classDef.type.startsWith("Lcom/reddit/launch/bottomnav/BottomNavScreen\$") } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/CreateButtonPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/CreateButtonPatch.kt index 79de40b5f2..caf9a5082d 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/CreateButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/CreateButtonPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.reddit.layout.navigation.annotations.NavigationButtonsCompatibility import app.revanced.patches.reddit.layout.navigation.patch.NavigationButtonsPatch.Companion.setValue +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsBytecodePatch.Companion.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch @@ -23,7 +23,7 @@ import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch SettingsPatch::class ] ) -@NavigationButtonsCompatibility +@RedditCompatibility @Version("0.0.1") class CreateButtonPatch : BytecodePatch() { override fun execute(context: BytecodeContext): PatchResult { diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/DiscoverButtonPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/DiscoverButtonPatch.kt index bbae488b6e..2c0ef4ed2f 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/DiscoverButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/DiscoverButtonPatch.kt @@ -9,8 +9,8 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.reddit.layout.navigation.annotations.NavigationButtonsCompatibility import app.revanced.patches.reddit.layout.navigation.patch.NavigationButtonsPatch.Companion.setValue +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsBytecodePatch.Companion.updateSettingsStatus import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch @@ -23,7 +23,7 @@ import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch SettingsPatch::class ] ) -@NavigationButtonsCompatibility +@RedditCompatibility @Version("0.0.1") class DiscoverButtonPatch : BytecodePatch() { override fun execute(context: BytecodeContext): PatchResult { diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt index b63cb9c4f4..08c7240c8b 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt @@ -3,15 +3,12 @@ package app.revanced.patches.reddit.layout.navigation.patch import app.revanced.extensions.toErrorResult import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction -import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patches.reddit.layout.navigation.fingerprints.BottomNavScreenFingerprint -import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction class NavigationButtonsPatch : BytecodePatch( listOf(BottomNavScreenFingerprint) @@ -21,21 +18,12 @@ class NavigationButtonsPatch : BytecodePatch( BottomNavScreenFingerprint.result?.let { it.mutableMethod.apply { val startIndex = it.scanResult.patternScanResult!!.startIndex - val reference = - getInstruction(startIndex).reference.toString() + val targetRegister = + getInstruction(startIndex).registerC - if (!reference.endsWith("Ljava/util/List;")) - return PatchResultError("Invalid reference: $reference") - - val insertIndex = startIndex + 2 - val insertRegister = - getInstruction(startIndex + 1).registerA - - addInstructions( - insertIndex, """ - invoke-static {v$insertRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR - move-result-object v$insertRegister - """ + addInstruction( + startIndex + 1, + "invoke-static {v$targetRegister}, $INTEGRATIONS_METHOD_DESCRIPTOR" ) } } ?: return BottomNavScreenFingerprint.toErrorResult() @@ -46,7 +34,7 @@ class NavigationButtonsPatch : BytecodePatch( companion object { const val INTEGRATIONS_METHOD_DESCRIPTOR = "Lapp/revanced/reddit/patches/NavigationButtonsPatch;" + - "->hideNavigationButtons(Ljava/util/List;)Ljava/util/List;" + "->hideNavigationButtons(Landroid/view/ViewGroup;)V" internal fun BytecodeContext.setValue(patch: String) { this.classes.forEach { classDef ->