From df01c0bf8cfe0561d1b3adc89393802c7bcd0ca7 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:37:20 +0900 Subject: [PATCH] fix(YouTube Music/Disable dislike redirection): not working at notification controls or widgets --- .../redirection/DislikeRedirectionPatch.kt | 70 +++++++++++++++---- ...DislikeButtonOnClickListenerFingerprint.kt | 12 +--- .../PendingIntentReceiverFingerprint.kt | 11 +++ .../kotlin/app/revanced/util/BytecodeUtils.kt | 5 ++ 4 files changed, 75 insertions(+), 23 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/music/utils/fingerprints/PendingIntentReceiverFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt index 4e2d3cd2c..50372a72a 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt @@ -6,13 +6,24 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.music.general.redirection.fingerprints.DislikeButtonOnClickListenerFingerprint +import app.revanced.patches.music.utils.fingerprints.PendingIntentReceiverFingerprint import app.revanced.patches.music.utils.integrations.Constants.GENERAL import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.util.exception +import app.revanced.util.getStringInstructionIndex +import app.revanced.util.getTargetIndexReversed +import app.revanced.util.getTargetIndexWithReference +import app.revanced.util.getWalkerMethod +import app.revanced.util.indexOfFirstInstruction +import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference +import com.android.tools.smali.dexlib2.iface.reference.Reference @Patch( name = "Disable dislike redirection", @@ -38,23 +49,45 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction ) @Suppress("unused") object DislikeRedirectionPatch : BytecodePatch( - setOf(DislikeButtonOnClickListenerFingerprint) + setOf( + DislikeButtonOnClickListenerFingerprint, + PendingIntentReceiverFingerprint + ) ) { + private lateinit var onClickReference: Reference + override fun execute(context: BytecodeContext) { + PendingIntentReceiverFingerprint.result?.let { + it.mutableMethod.apply { + val startIndex = getStringInstructionIndex("YTM Dislike") + val onClickRelayIndex = getTargetIndexReversed(startIndex, Opcode.INVOKE_VIRTUAL) + val onClickRelayMethod = getWalkerMethod(context, onClickRelayIndex) + + onClickRelayMethod.apply { + val onClickMethodIndex = getTargetIndexReversed(Opcode.INVOKE_DIRECT) + val onClickMethod = getWalkerMethod(context, onClickMethodIndex) + + onClickMethod.apply { + val onClickIndex = indexOfFirstInstruction { + val reference = ((this as? ReferenceInstruction)?.reference as? MethodReference) + + opcode == Opcode.INVOKE_INTERFACE + && reference?.returnType == "V" + && reference.parameterTypes.size == 1 + } + onClickReference = getInstruction(onClickIndex).reference + + injectCall(onClickIndex) + } + } + } + } ?: throw PendingIntentReceiverFingerprint.exception + DislikeButtonOnClickListenerFingerprint.result?.let { it.mutableMethod.apply { - val startIndex = it.scanResult.patternScanResult!!.startIndex - val jumpIndex = it.scanResult.patternScanResult!!.endIndex + 1 - val freeRegister = getInstruction(startIndex).registerA - - addInstructionsWithLabels( - startIndex + 1, """ - invoke-static {}, $GENERAL->disableDislikeRedirection()Z - move-result v$freeRegister - if-nez v$freeRegister, :disable - """, ExternalLabel("disable", getInstruction(jumpIndex)) - ) + val onClickIndex = getTargetIndexWithReference(onClickReference.toString()) + injectCall(onClickIndex) } } ?: throw DislikeButtonOnClickListenerFingerprint.exception @@ -65,4 +98,17 @@ object DislikeRedirectionPatch : BytecodePatch( ) } + + private fun MutableMethod.injectCall(onClickIndex: Int) { + val targetIndex = getTargetIndexReversed(onClickIndex, Opcode.IF_EQZ) + val insertRegister = getInstruction(targetIndex).registerA + + addInstructionsWithLabels( + targetIndex + 1, """ + invoke-static {}, $GENERAL->disableDislikeRedirection()Z + move-result v$insertRegister + if-nez v$insertRegister, :disable + """, ExternalLabel("disable", getInstruction(onClickIndex + 1)) + ) + } } diff --git a/src/main/kotlin/app/revanced/patches/music/general/redirection/fingerprints/DislikeButtonOnClickListenerFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/general/redirection/fingerprints/DislikeButtonOnClickListenerFingerprint.kt index b238c7b3e..a405b7204 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/redirection/fingerprints/DislikeButtonOnClickListenerFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/redirection/fingerprints/DislikeButtonOnClickListenerFingerprint.kt @@ -1,24 +1,14 @@ package app.revanced.patches.music.general.redirection.fingerprints -import app.revanced.util.containsWideLiteralInstructionIndex import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.MethodFingerprint +import app.revanced.util.containsWideLiteralInstructionIndex import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode internal object DislikeButtonOnClickListenerFingerprint : MethodFingerprint( returnType = "V", accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("Landroid/view/View;"), - opcodes = listOf( - Opcode.IF_EQZ, - Opcode.IGET_OBJECT, - Opcode.IGET_OBJECT, - Opcode.SGET_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.INVOKE_INTERFACE - ), customFingerprint = handler@{ methodDef, _ -> if (!methodDef.containsWideLiteralInstructionIndex(53465)) return@handler false diff --git a/src/main/kotlin/app/revanced/patches/music/utils/fingerprints/PendingIntentReceiverFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/utils/fingerprints/PendingIntentReceiverFingerprint.kt new file mode 100644 index 000000000..96129f1a8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/utils/fingerprints/PendingIntentReceiverFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.music.utils.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +object PendingIntentReceiverFingerprint : MethodFingerprint( + returnType = "V", + strings = listOf("YTM Dislike", "YTM Next", "YTM Previous"), + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/PendingIntentReceiver;") + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/util/BytecodeUtils.kt b/src/main/kotlin/app/revanced/util/BytecodeUtils.kt index 73410e80b..fee2428e2 100644 --- a/src/main/kotlin/app/revanced/util/BytecodeUtils.kt +++ b/src/main/kotlin/app/revanced/util/BytecodeUtils.kt @@ -257,6 +257,11 @@ fun MutableMethod.getTargetIndexWithReferenceReversed(startIndex: Int, reference return -1 } +fun MutableMethod.getWalkerMethod(context: BytecodeContext, index: Int) = + context.toMethodWalker(this) + .nextMethod(index, true) + .getMethod() as MutableMethod + fun BytecodeContext.updatePatchStatus( className: String, methodName: String