From 5147404c9ee8c439b5417e5a48c6fb445c8c67c2 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Fri, 7 Oct 2022 23:01:41 +0200 Subject: [PATCH] fix(video-ads): block remaining video ads --- ...dsFingerprint.kt => LoadAdsFingerprint.kt} | 11 +++--- .../ShowVideoAdsConstructorFingerprint.kt | 35 ------------------- .../youtube/ad/video/patch/VideoAdsPatch.kt | 32 +++++++++-------- 3 files changed, 23 insertions(+), 55 deletions(-) rename src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/{ShowVideoAdsFingerprint.kt => LoadAdsFingerprint.kt} (56%) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/ShowVideoAdsConstructorFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/ShowVideoAdsFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/LoadAdsFingerprint.kt similarity index 56% rename from src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/ShowVideoAdsFingerprint.kt rename to src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/LoadAdsFingerprint.kt index 2d1c09cfc..e3409c0fc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/ShowVideoAdsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/LoadAdsFingerprint.kt @@ -2,16 +2,17 @@ package app.revanced.patches.youtube.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.patches.youtube.ad.video.annotations.VideoAdsCompatibility -import org.jf.dexlib2.AccessFlags -@Name("show-video-ads-method-fingerprint") +@Name("load-ads-fingerprint") @VideoAdsCompatibility @Version("0.0.1") -object ShowVideoAdsFingerprint : MethodFingerprint( - "V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("Z") +object LoadAdsFingerprint : MethodFingerprint( + strings = listOf("Unexpected playerAd type: "), + customFingerprint = { method -> + method.parameterTypes.size > 0 && method.parameterTypes.first() == "Ljava/lang/String;" + } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/ShowVideoAdsConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/ShowVideoAdsConstructorFingerprint.kt deleted file mode 100644 index 418f5c1d2..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/video/fingerprints/ShowVideoAdsConstructorFingerprint.kt +++ /dev/null @@ -1,35 +0,0 @@ -package app.revanced.patches.youtube.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.impl.MethodFingerprint -import app.revanced.patches.youtube.ad.video.annotations.VideoAdsCompatibility -import org.jf.dexlib2.AccessFlags -import org.jf.dexlib2.Opcode - -@Name("show-video-ads-constructor-fingerprint") -@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value. -@VideoAdsCompatibility -@Version("0.0.1") -object ShowVideoAdsConstructorFingerprint : 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, - null, // either CONST_4 or CONST_16 - 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 - ) -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt index fbeb1fe9f..65e7eb8c5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/video/patch/VideoAdsPatch.kt @@ -5,15 +5,15 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstructions -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve +import app.revanced.patcher.extensions.instruction import app.revanced.patcher.patch.BytecodePatch 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.util.smali.ExternalLabel import app.revanced.patches.youtube.ad.video.annotations.VideoAdsCompatibility -import app.revanced.patches.youtube.ad.video.fingerprints.ShowVideoAdsConstructorFingerprint -import app.revanced.patches.youtube.ad.video.fingerprints.ShowVideoAdsFingerprint +import app.revanced.patches.youtube.ad.video.fingerprints.LoadAdsFingerprint 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 @@ -27,7 +27,7 @@ import app.revanced.patches.youtube.misc.settings.framework.components.impl.Swit @Version("0.0.1") class VideoAdsPatch : BytecodePatch( listOf( - ShowVideoAdsConstructorFingerprint + LoadAdsFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -41,17 +41,19 @@ class VideoAdsPatch : BytecodePatch( ) ) - ShowVideoAdsFingerprint.resolve( - context, ShowVideoAdsConstructorFingerprint.result!!.classDef - ) - - // Override the parameter by calling shouldShowAds and setting the parameter to the result - ShowVideoAdsFingerprint.result!!.mutableMethod.addInstructions( - 0, """ - invoke-static { }, Lapp/revanced/integrations/patches/VideoAdsPatch;->shouldShowAds()Z - move-result v1 - """ - ) + LoadAdsFingerprint.result!!.mutableMethod.let { method -> + method.addInstructions( + 0, + """ + invoke-static { }, Lapp/revanced/integrations/patches/VideoAdsPatch;->shouldShowAds()Z + move-result v1 + if-nez v1, :show_video_ads + const/4 v1, 0x0 + return-object v1 + """, + listOf(ExternalLabel("show_video_ads", method.instruction(0))) + ) + } return PatchResultSuccess() }