From acde5f066053ca3d58ca09fc2a6a1381ba27d84b Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Thu, 27 Oct 2022 01:51:49 +0500 Subject: [PATCH] feat(youtube/hide-mix-playlists): hide in video suggestions (#854) Co-authored-by: oSumAtrIX --- ...int.kt => CreateMixPlaylistFingerprint.kt} | 5 ++- .../SecondCreateMixPlaylistFingerprint.kt | 30 +++++++++++++++++ .../patch/MixPlaylistsPatch.kt | 33 ++++++++++++------- 3 files changed, 53 insertions(+), 15 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/{MixPlaylistsPatchFingerprint.kt => CreateMixPlaylistFingerprint.kt} (89%) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/SecondCreateMixPlaylistFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/MixPlaylistsPatchFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/CreateMixPlaylistFingerprint.kt similarity index 89% rename from src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/MixPlaylistsPatchFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/CreateMixPlaylistFingerprint.kt index f0b51e864..27390c34b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/MixPlaylistsPatchFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/CreateMixPlaylistFingerprint.kt @@ -8,10 +8,10 @@ import app.revanced.patches.youtube.layout.hidemixplaylists.annotations.MixPlayl import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode -@Name("mix-playlists-fingerprint") +@Name("create-mix-playlist-fingerprint") @MixPlaylistsPatchCompatibility @Version("0.0.1") -object MixPlaylistsPatchFingerprint : MethodFingerprint( +object CreateMixPlaylistFingerprint : MethodFingerprint( "V", AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, listOf("L", "L", "L", "L", "L", "L", "L"), listOf( Opcode.INVOKE_DIRECT, Opcode.IPUT_OBJECT, @@ -26,6 +26,5 @@ object MixPlaylistsPatchFingerprint : MethodFingerprint( Opcode.IPUT_OBJECT, Opcode.IPUT_OBJECT, Opcode.INVOKE_VIRTUAL, - Opcode.RETURN_VOID ) ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/SecondCreateMixPlaylistFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/SecondCreateMixPlaylistFingerprint.kt new file mode 100644 index 000000000..f2e995c25 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/fingerprints/SecondCreateMixPlaylistFingerprint.kt @@ -0,0 +1,30 @@ +package app.revanced.patches.youtube.layout.hidemixplaylists.fingerprints + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.youtube.layout.hidemixplaylists.annotations.MixPlaylistsPatchCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("second-create-mix-playlist-fingerprint") +@MixPlaylistsPatchCompatibility +@Version("0.0.1") +object SecondCreateMixPlaylistFingerprint : MethodFingerprint( + "V", AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, listOf("L", "L", "L", "L", "L", "L"), listOf( + Opcode.INVOKE_DIRECT, + Opcode.IPUT_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.IPUT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.IPUT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.RETURN_VOID + ) +) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/patch/MixPlaylistsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/patch/MixPlaylistsPatch.kt index 15d5d441c..c6f692ba6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/patch/MixPlaylistsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hidemixplaylists/patch/MixPlaylistsPatch.kt @@ -5,13 +5,16 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.extensions.instruction +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint 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.patcher.patch.BytecodePatch import app.revanced.patches.youtube.layout.hidemixplaylists.annotations.MixPlaylistsPatchCompatibility -import app.revanced.patches.youtube.layout.hidemixplaylists.fingerprints.MixPlaylistsPatchFingerprint +import app.revanced.patches.youtube.layout.hidemixplaylists.fingerprints.CreateMixPlaylistFingerprint +import app.revanced.patches.youtube.layout.hidemixplaylists.fingerprints.SecondCreateMixPlaylistFingerprint import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource @@ -21,12 +24,12 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Patch @DependsOn([IntegrationsPatch::class]) @Name("hide-my-mix") -@Description("Removes mix playlists from the feed.") +@Description("Hides mix playlists.") @MixPlaylistsPatchCompatibility @Version("0.0.1") class MixPlaylistsPatch : BytecodePatch( listOf( - MixPlaylistsPatchFingerprint + CreateMixPlaylistFingerprint, SecondCreateMixPlaylistFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -40,16 +43,22 @@ class MixPlaylistsPatch : BytecodePatch( ) ) - val result = MixPlaylistsPatchFingerprint.result!! - val method = result.mutableMethod - val index = result.scanResult.patternScanResult!!.endIndex - 6 - val register = (method.implementation!!.instructions[index] as OneRegisterInstruction).registerA - - method.addInstruction( - index + 2, - "invoke-static {v$register}, Lapp/revanced/integrations/patches/HideMixPlaylistsPatch;->hideMixPlaylists(Landroid/view/View;)V" - ) + arrayOf(CreateMixPlaylistFingerprint, SecondCreateMixPlaylistFingerprint).forEach(::addHook) return PatchResultSuccess() } + + private fun addHook(fingerprint: MethodFingerprint) { + with (fingerprint.result!!) { + val insertIndex = scanResult.patternScanResult!!.endIndex - 3 + + val register = (mutableMethod.instruction(insertIndex - 2) as OneRegisterInstruction).registerA + + mutableMethod.addInstruction( + insertIndex, + "invoke-static {v$register}, Lapp/revanced/integrations/patches/HideMixPlaylistsPatch;->hideMixPlaylists(Landroid/view/View;)V" + ) + } + + } }