From 9ec17d43287d95c8908bc61c2317329b93a4908e Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sat, 18 Jan 2025 20:08:27 +0900 Subject: [PATCH] fix(YouTube Music - Disable dislike redirection): Patch not working in `8.02.53` https://github.com/inotia00/ReVanced_Extended/issues/2695 --- .../redirection/DislikeRedirectionPatch.kt | 37 +++++++++++++------ .../music/general/redirection/Fingerprints.kt | 30 +++++++++++++++ .../utils/playservice/VersionCheckPatch.kt | 6 +++ 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt index bd019dfa4..34ca7563a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt @@ -9,6 +9,8 @@ import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKA import app.revanced.patches.music.utils.extension.Constants.GENERAL_CLASS_DESCRIPTOR import app.revanced.patches.music.utils.patch.PatchList.DISABLE_DISLIKE_REDIRECTION import app.revanced.patches.music.utils.pendingIntentReceiverFingerprint +import app.revanced.patches.music.utils.playservice.is_7_29_or_greater +import app.revanced.patches.music.utils.playservice.versionCheckPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.ResourceUtils.updatePatchStatus import app.revanced.patches.music.utils.settings.addSwitchPreference @@ -23,7 +25,8 @@ 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 + +var onClickReference = "" @Suppress("unused") val dislikeRedirectionPatch = bytecodePatch( @@ -32,11 +35,12 @@ val dislikeRedirectionPatch = bytecodePatch( ) { compatibleWith(COMPATIBLE_PACKAGE) - dependsOn(settingsPatch) + dependsOn( + settingsPatch, + versionCheckPatch, + ) execute { - lateinit var onClickReference: Reference - pendingIntentReceiverFingerprint.methodOrThrow().apply { val startIndex = indexOfFirstStringInstructionOrThrow("YTM Dislike") val onClickRelayIndex = @@ -63,18 +67,21 @@ val dislikeRedirectionPatch = bytecodePatch( reference.parameterTypes.size == 1 } onClickReference = - getInstruction(onClickIndex).reference + getInstruction(onClickIndex).reference.toString() disableDislikeRedirection(onClickIndex) } } } - dislikeButtonOnClickListenerFingerprint.methodOrThrow().apply { - val onClickIndex = indexOfFirstInstructionOrThrow { - getReference()?.toString() == onClickReference.toString() - } - disableDislikeRedirection(onClickIndex) + if (is_7_29_or_greater) { + dislikeButtonOnClickListenerAlternativeFingerprint + .methodOrThrow() + .disableDislikeRedirection() + } else { + dislikeButtonOnClickListenerFingerprint + .methodOrThrow() + .disableDislikeRedirection() } addSwitchPreference( @@ -88,7 +95,15 @@ val dislikeRedirectionPatch = bytecodePatch( } } -private fun MutableMethod.disableDislikeRedirection(onClickIndex: Int) { +private fun MutableMethod.disableDislikeRedirection(startIndex: Int = 0) { + val onClickIndex = + if (startIndex == 0) { + indexOfFirstInstructionOrThrow { + getReference()?.toString() == onClickReference + } + } else { + startIndex + } val targetIndex = indexOfFirstInstructionReversedOrThrow(onClickIndex, Opcode.IF_EQZ) val insertRegister = getInstruction(targetIndex).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/Fingerprints.kt index 527af433a..38f3d17e8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/general/redirection/Fingerprints.kt @@ -4,6 +4,8 @@ import app.revanced.util.containsLiteralInstruction import app.revanced.util.fingerprint.legacyFingerprint import app.revanced.util.or import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference internal val dislikeButtonOnClickListenerFingerprint = legacyFingerprint( name = "dislikeButtonOnClickListenerFingerprint", @@ -18,3 +20,31 @@ internal val dislikeButtonOnClickListenerFingerprint = legacyFingerprint( } ) +/** + * YouTube Music 7.27.52 ~ + * TODO: Make this fingerprint more concise + */ +internal val dislikeButtonOnClickListenerAlternativeFingerprint = legacyFingerprint( + name = "dislikeButtonOnClickListenerAlternativeFingerprint", + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L", "Ljava/util/Map;"), + customFingerprint = custom@{ method, classDef -> + if (classDef.fields.count() != 7) { + return@custom false + } + if (classDef.methods.count() != 5) { + return@custom false + } + val implementation = method.implementation + ?: return@custom false + val instructions = implementation.instructions + val instructionCount = instructions.count() + if (instructionCount < 50) { + return@custom false + } + + ((instructions.elementAt(0) as? ReferenceInstruction)?.reference as? FieldReference)?.name == "likeEndpoint" + } +) + diff --git a/patches/src/main/kotlin/app/revanced/patches/music/utils/playservice/VersionCheckPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/utils/playservice/VersionCheckPatch.kt index 6344ff17a..9e4c07482 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/utils/playservice/VersionCheckPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/utils/playservice/VersionCheckPatch.kt @@ -27,6 +27,10 @@ var is_7_23_or_greater = false private set var is_7_25_or_greater = false private set +var is_7_27_or_greater = false + private set +var is_7_29_or_greater = false + private set val versionCheckPatch = resourcePatch( description = "versionCheckPatch", @@ -53,5 +57,7 @@ val versionCheckPatch = resourcePatch( is_7_20_or_greater = 243899000 <= playStoreServicesVersion is_7_23_or_greater = 244199000 <= playStoreServicesVersion is_7_25_or_greater = 244399000 <= playStoreServicesVersion + is_7_27_or_greater = 244515000 <= playStoreServicesVersion + is_7_29_or_greater = 244799000 <= playStoreServicesVersion } }