From b6ca3b4491cc0a5c42b6a52ec48ad0ff8a54f0b2 Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Mon, 13 Mar 2023 02:18:40 +0500 Subject: [PATCH] feat(youtubevanced): `general-ads` patch (#1693) --- .../annotations/ClientSpoofCompatibility.kt | 2 +- .../UserAgentHeaderBuilderFingerprint.kt | 2 +- .../misc/fix/spoof/patch/ClientSpoofPatch.kt | 6 +- .../VerticalScrollCompatibility.kt | 3 +- .../CanScrollVerticallyFingerprint.kt | 2 +- .../patch/VerticalScrollPatch.kt | 6 +- .../general/bytecode/patch/GeneralAdsPatch.kt | 2 +- .../patch/bytecode/MicroGBytecodePatch.kt | 2 +- .../annotations/HideAdsCompatibility.kt | 8 +++ .../fingerprints/ContainsAdFingerprint.kt | 25 ++++++++ .../ad/general/patch/HideAdsPatch.kt | 63 +++++++++++++++++++ 11 files changed, 109 insertions(+), 12 deletions(-) rename src/main/kotlin/app/revanced/patches/{youtube => shared}/misc/fix/spoof/annotations/ClientSpoofCompatibility.kt (82%) rename src/main/kotlin/app/revanced/patches/{youtube => shared}/misc/fix/spoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt (83%) rename src/main/kotlin/app/revanced/patches/{youtube => shared}/misc/fix/spoof/patch/ClientSpoofPatch.kt (84%) rename src/main/kotlin/app/revanced/patches/{youtube => shared}/misc/fix/verticalscroll/annotations/VerticalScrollCompatibility.kt (69%) rename src/main/kotlin/app/revanced/patches/{youtube => shared}/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt (85%) rename src/main/kotlin/app/revanced/patches/{youtube => shared}/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt (83%) create mode 100644 src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/annotations/HideAdsCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/fingerprints/ContainsAdFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/patch/HideAdsPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/spoof/annotations/ClientSpoofCompatibility.kt b/src/main/kotlin/app/revanced/patches/shared/misc/fix/spoof/annotations/ClientSpoofCompatibility.kt similarity index 82% rename from src/main/kotlin/app/revanced/patches/youtube/misc/fix/spoof/annotations/ClientSpoofCompatibility.kt rename to src/main/kotlin/app/revanced/patches/shared/misc/fix/spoof/annotations/ClientSpoofCompatibility.kt index 428e8fcde..8ed8a4716 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/spoof/annotations/ClientSpoofCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/shared/misc/fix/spoof/annotations/ClientSpoofCompatibility.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.fix.spoof.annotations +package app.revanced.patches.shared.misc.fix.spoof.annotations import app.revanced.patcher.annotation.Compatibility import app.revanced.patcher.annotation.Package diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/spoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/misc/fix/spoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt similarity index 83% rename from src/main/kotlin/app/revanced/patches/youtube/misc/fix/spoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt rename to src/main/kotlin/app/revanced/patches/shared/misc/fix/spoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt index 0c1dcdbdd..f3cf363e3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/spoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/misc/fix/spoof/fingerprints/UserAgentHeaderBuilderFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.fix.spoof.fingerprints +package app.revanced.patches.shared.misc.fix.spoof.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/spoof/patch/ClientSpoofPatch.kt b/src/main/kotlin/app/revanced/patches/shared/misc/fix/spoof/patch/ClientSpoofPatch.kt similarity index 84% rename from src/main/kotlin/app/revanced/patches/youtube/misc/fix/spoof/patch/ClientSpoofPatch.kt rename to src/main/kotlin/app/revanced/patches/shared/misc/fix/spoof/patch/ClientSpoofPatch.kt index 0b6a1ebe9..c58e71c93 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/spoof/patch/ClientSpoofPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/misc/fix/spoof/patch/ClientSpoofPatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.fix.spoof.patch +package app.revanced.patches.shared.misc.fix.spoof.patch import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name @@ -10,8 +10,8 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.youtube.misc.fix.spoof.annotations.ClientSpoofCompatibility -import app.revanced.patches.youtube.misc.fix.spoof.fingerprints.UserAgentHeaderBuilderFingerprint +import app.revanced.patches.shared.misc.fix.spoof.annotations.ClientSpoofCompatibility +import app.revanced.patches.shared.misc.fix.spoof.fingerprints.UserAgentHeaderBuilderFingerprint import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction @Patch diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/annotations/VerticalScrollCompatibility.kt b/src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/annotations/VerticalScrollCompatibility.kt similarity index 69% rename from src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/annotations/VerticalScrollCompatibility.kt rename to src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/annotations/VerticalScrollCompatibility.kt index 9924f25c2..bd19fbc45 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/annotations/VerticalScrollCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/annotations/VerticalScrollCompatibility.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.fix.verticalscroll.annotations +package app.revanced.patches.shared.misc.fix.verticalscroll.annotations import app.revanced.patcher.annotation.Compatibility import app.revanced.patcher.annotation.Package @@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Package @Compatibility( [ Package("com.google.android.youtube"), + Package("com.vanced.android.youtube") ] ) @Target(AnnotationTarget.CLASS) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt similarity index 85% rename from src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt rename to src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt index 338e07774..e5d137ca6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/fingerprints/CanScrollVerticallyFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.fix.verticalscroll.fingerprints +package app.revanced.patches.shared.misc.fix.verticalscroll.fingerprints import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt b/src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt similarity index 83% rename from src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt rename to src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt index f78eb494a..557ccb5a3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt +++ b/src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/patch/VerticalScrollPatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.youtube.misc.fix.verticalscroll.patch +package app.revanced.patches.shared.misc.fix.verticalscroll.patch import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Description @@ -9,8 +9,8 @@ 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.patches.youtube.misc.fix.verticalscroll.annotations.VerticalScrollCompatibility -import app.revanced.patches.youtube.misc.fix.verticalscroll.fingerprints.CanScrollVerticallyFingerprint +import app.revanced.patches.shared.misc.fix.verticalscroll.annotations.VerticalScrollCompatibility +import app.revanced.patches.shared.misc.fix.verticalscroll.fingerprints.CanScrollVerticallyFingerprint import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Description("Fixes issues with scrolling on the home screen when the first component is of type EmptyComponent.") diff --git a/src/main/kotlin/app/revanced/patches/youtube/ad/general/bytecode/patch/GeneralAdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/ad/general/bytecode/patch/GeneralAdsPatch.kt index 4fc211775..9bcc728a4 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/ad/general/bytecode/patch/GeneralAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/ad/general/bytecode/patch/GeneralAdsPatch.kt @@ -18,7 +18,7 @@ import app.revanced.patches.youtube.ad.general.annotation.GeneralAdsCompatibilit import app.revanced.patches.youtube.ad.general.bytecode.fingerprints.ReelConstructorFingerprint import app.revanced.patches.youtube.ad.general.resource.patch.GeneralAdsResourcePatch import app.revanced.patches.youtube.misc.fix.backtoexitgesture.patch.FixBackToExitGesturePatch -import app.revanced.patches.youtube.misc.fix.verticalscroll.patch.VerticalScrollPatch +import app.revanced.patches.shared.misc.fix.verticalscroll.patch.VerticalScrollPatch import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction import org.jf.dexlib2.iface.instruction.formats.Instruction31i import org.jf.dexlib2.iface.instruction.formats.Instruction35c diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt index 9fc74c4ed..4063a2de6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/microg/patch/bytecode/MicroGBytecodePatch.kt @@ -11,7 +11,7 @@ import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.shared.fingerprints.WatchWhileActivityFingerprint import app.revanced.patches.youtube.layout.buttons.cast.patch.HideCastButtonPatch -import app.revanced.patches.youtube.misc.fix.spoof.patch.ClientSpoofPatch +import app.revanced.patches.shared.misc.fix.spoof.patch.ClientSpoofPatch import app.revanced.patches.youtube.misc.fix.playback.patch.SpoofSignatureVerificationPatch import app.revanced.patches.youtube.misc.microg.annotations.MicroGPatchCompatibility import app.revanced.patches.youtube.misc.microg.fingerprints.* diff --git a/src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/annotations/HideAdsCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/annotations/HideAdsCompatibility.kt new file mode 100644 index 000000000..e7c85c582 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/annotations/HideAdsCompatibility.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.youtubevanced.ad.general.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("com.vanced.android.youtube")]) +@Target(AnnotationTarget.CLASS) +internal annotation class HideAdsCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/fingerprints/ContainsAdFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/fingerprints/ContainsAdFingerprint.kt new file mode 100644 index 000000000..ed26fa039 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/fingerprints/ContainsAdFingerprint.kt @@ -0,0 +1,25 @@ +package app.revanced.patches.youtubevanced.ad.general.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object ContainsAdFingerprint:MethodFingerprint( + returnType = "Z", + parameters = listOf("L", "L"), + access = AccessFlags.STATIC or AccessFlags.PUBLIC, + opcodes = listOf( + Opcode.CONST_STRING, + Opcode.INVOKE_INTERFACE, + Opcode.CONST_STRING, + Opcode.INVOKE_INTERFACE, + Opcode.CONST_STRING, + Opcode.INVOKE_INTERFACE + ), + strings = listOf("ads_video_with_context"), + customFingerprint = { methodDef -> + methodDef.name == "containsAd" && methodDef.definingClass.endsWith("LithoAdRemoval;") + } +) { +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/patch/HideAdsPatch.kt b/src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/patch/HideAdsPatch.kt new file mode 100644 index 000000000..c820e1e46 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtubevanced/ad/general/patch/HideAdsPatch.kt @@ -0,0 +1,63 @@ +package app.revanced.patches.youtubevanced.ad.general.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +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.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.patches.shared.misc.fix.verticalscroll.patch.VerticalScrollPatch +import app.revanced.patches.youtubevanced.ad.general.annotations.HideAdsCompatibility +import app.revanced.patches.youtubevanced.ad.general.fingerprints.ContainsAdFingerprint +import org.jf.dexlib2.iface.instruction.formats.Instruction21c + +@Patch +@Name("hide-ads") +@Description("Removes general ads.") +@DependsOn([VerticalScrollPatch::class]) +@HideAdsCompatibility +@Version("0.0.1") +class HideAdsPatch : BytecodePatch( + listOf( + ContainsAdFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + ContainsAdFingerprint.result?.let { result -> + result.mutableMethod.apply { + val insertIndex = result.scanResult.patternScanResult!!.endIndex + 1 + val adsListRegister = (instruction(insertIndex - 2) as Instruction21c).registerA + + listOf( + "video_display_full_buttoned_layout", + "full_width_square_image_layout", + "_ad_with", + "landscape_image_wide_button_layout", + "banner_text_icon", + "cell_divider", + "square_image_layout", + "watch_metadata_app_promo", + "video_display_full_layout", + "hero_promo_image", + "statement_banner", + "primetime_promo" + ).forEach { component -> + addInstructions( + insertIndex, """ + const-string v$adsListRegister, "$component" + invoke-interface {v0, v$adsListRegister}, Ljava/util/List;->add(Ljava/lang/Object;)Z + """ + ) + } + } + } ?: return ContainsAdFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} \ No newline at end of file