From c6b2f8c0172b4fd142927d9448ed855831c86ae4 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 27 Jun 2024 22:25:43 +0200 Subject: [PATCH] feat(Instagram): Add `Hide ads` patch (#3380) Co-authored-by: oSumAtrIX --- api/revanced-patches.api | 6 ++++ .../instagram/patches/ad/HideAdsPatch.kt | 29 +++++++++++++++++++ .../ad/fingerprints/AdInjectorFingerprint.kt | 17 +++++++++++ 3 files changed, 52 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/instagram/patches/ad/HideAdsPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/instagram/patches/ad/fingerprints/AdInjectorFingerprint.kt diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 2eb9a62f..057f8cf9 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -241,6 +241,12 @@ public final class app/revanced/patches/inshorts/ad/HideAdsPatch : app/revanced/ public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } +public final class app/revanced/patches/instagram/patches/ad/HideAdsPatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/instagram/patches/ad/HideAdsPatch; + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V +} + public final class app/revanced/patches/instagram/patches/ads/timeline/HideTimelineAdsPatch : app/revanced/patcher/patch/BytecodePatch { public static final field INSTANCE Lapp/revanced/patches/instagram/patches/ads/timeline/HideTimelineAdsPatch; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V diff --git a/src/main/kotlin/app/revanced/patches/instagram/patches/ad/HideAdsPatch.kt b/src/main/kotlin/app/revanced/patches/instagram/patches/ad/HideAdsPatch.kt new file mode 100644 index 00000000..15b0668e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/instagram/patches/ad/HideAdsPatch.kt @@ -0,0 +1,29 @@ +package app.revanced.patches.instagram.patches.ad + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.instagram.patches.ad.fingerprints.AdInjectorFingerprint +import app.revanced.util.exception + +@Patch( + name = "Hide ads", + description = "Hides ads in stories, discover, profile, etc." + + "An ad can still appear once when refreshing the home feed.", + compatiblePackages = [CompatiblePackage("com.instagram.android")], +) +@Suppress("unused") +object HideAdsPatch : BytecodePatch( + setOf(AdInjectorFingerprint), +) { + override fun execute(context: BytecodeContext) = + AdInjectorFingerprint.result?.mutableMethod?.addInstructions( + 0, + """ + const/4 v0, 0x0 + return v0 + """, + ) ?: throw AdInjectorFingerprint.exception +} diff --git a/src/main/kotlin/app/revanced/patches/instagram/patches/ad/fingerprints/AdInjectorFingerprint.kt b/src/main/kotlin/app/revanced/patches/instagram/patches/ad/fingerprints/AdInjectorFingerprint.kt new file mode 100644 index 00000000..1e250d7d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/instagram/patches/ad/fingerprints/AdInjectorFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.instagram.patches.ad.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +internal object AdInjectorFingerprint : MethodFingerprint( + returnType = "Z", + accessFlags = AccessFlags.PRIVATE.value, + parameters = listOf("L", "L"), + opcodes = listOf( + Opcode.IGET, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT, + ), + strings = listOf("SponsoredContentController::Delivery"), +)