From cbb71b5faf1386ed31dd9e0387f6cf0509d92d31 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Fri, 15 Jul 2022 12:18:25 +0100 Subject: [PATCH] feat: `music-video-ads` patch (#172) --- .../annotations/MusicVideoAdsCompatibility.kt | 13 ++++++ ...ShowMusicVideoAdsConstructorFingerprint.kt | 39 ++++++++++++++++++ .../ShowMusicVideoAdsFingerprint.kt | 26 ++++++++++++ .../ad/video/patch/MusicVideoAdsPatch.kt | 40 +++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/ad/video/annotations/MusicVideoAdsCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/ad/video/fingerprints/ShowMusicVideoAdsConstructorFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/ad/video/fingerprints/ShowMusicVideoAdsFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/ad/video/patch/MusicVideoAdsPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/music/ad/video/annotations/MusicVideoAdsCompatibility.kt b/src/main/kotlin/app/revanced/patches/music/ad/video/annotations/MusicVideoAdsCompatibility.kt new file mode 100644 index 000000000..0a347bf56 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/ad/video/annotations/MusicVideoAdsCompatibility.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.music.ad.video.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.google.android.apps.youtube.music", arrayOf("5.03.50") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class MusicVideoAdsCompatibility diff --git a/src/main/kotlin/app/revanced/patches/music/ad/video/fingerprints/ShowMusicVideoAdsConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/ad/video/fingerprints/ShowMusicVideoAdsConstructorFingerprint.kt new file mode 100644 index 000000000..7cd26d2ac --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/ad/video/fingerprints/ShowMusicVideoAdsConstructorFingerprint.kt @@ -0,0 +1,39 @@ +package app.revanced.patches.music.ad.video.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.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patches.music.ad.video.annotations.MusicVideoAdsCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("show-video-ads-constructor-fingerprint") +@MatchingMethod( + "Laghd;", + "", +) +@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value. +@MusicVideoAdsCompatibility +@Version("0.0.1") +object ShowMusicVideoAdsConstructorFingerprint : MethodFingerprint( + "V", AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, listOf("L", "L", "L"), listOf( + Opcode.INVOKE_DIRECT, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.IPUT_OBJECT, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.IPUT_OBJECT, + Opcode.NEW_INSTANCE, + Opcode.INVOKE_DIRECT, + Opcode.IPUT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.IPUT_OBJECT, + Opcode.CONST_4, + Opcode.IPUT_BOOLEAN, + Opcode.RETURN_VOID + ) +) diff --git a/src/main/kotlin/app/revanced/patches/music/ad/video/fingerprints/ShowMusicVideoAdsFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/ad/video/fingerprints/ShowMusicVideoAdsFingerprint.kt new file mode 100644 index 000000000..4fd432ea0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/ad/video/fingerprints/ShowMusicVideoAdsFingerprint.kt @@ -0,0 +1,26 @@ +package app.revanced.patches.music.ad.video.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.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.music.ad.video.annotations.MusicVideoAdsCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("show-video-ads-method-fingerprint") +@MatchingMethod( + "Laghd;", "d" +) +@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value. +@MusicVideoAdsCompatibility +@Version("0.0.1") +object ShowMusicVideoAdsFingerprint : MethodFingerprint( + "V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("Z"), listOf( + Opcode.IPUT_BOOLEAN, + Opcode.INVOKE_VIRTUAL, + Opcode.RETURN_VOID + ) +) diff --git a/src/main/kotlin/app/revanced/patches/music/ad/video/patch/MusicVideoAdsPatch.kt b/src/main/kotlin/app/revanced/patches/music/ad/video/patch/MusicVideoAdsPatch.kt new file mode 100644 index 000000000..7c3cb61b3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/ad/video/patch/MusicVideoAdsPatch.kt @@ -0,0 +1,40 @@ +package app.revanced.patches.music.ad.video.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.impl.BytecodeData +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.fingerprint.method.utils.MethodFingerprintUtils.resolve +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.impl.BytecodePatch +import app.revanced.patches.music.ad.video.annotations.MusicVideoAdsCompatibility +import app.revanced.patches.music.ad.video.fingerprints.ShowMusicVideoAdsConstructorFingerprint +import app.revanced.patches.music.ad.video.fingerprints.ShowMusicVideoAdsFingerprint + +@Patch +@Name("music-video-ads") +@Description("Removes ads in the YouTube Music player.") +@MusicVideoAdsCompatibility +@Version("0.0.1") +class MusicVideoAdsPatch : BytecodePatch( + listOf( + ShowMusicVideoAdsConstructorFingerprint + ) +) { + override fun execute(data: BytecodeData): PatchResult { + ShowMusicVideoAdsFingerprint.resolve(data, ShowMusicVideoAdsConstructorFingerprint.result!!.classDef) + + val result = ShowMusicVideoAdsFingerprint.result!! + + result.mutableMethod.addInstructions( + result.patternScanResult!!.startIndex, """ + const/4 p1, 0x0 + """ + ) + + return PatchResultSuccess() + } +}