From 04a2accfe9f9254af9074ad0a309d485cedb01cb Mon Sep 17 00:00:00 2001 From: Aunali321 <48486084+Aunali321@users.noreply.github.com> Date: Sun, 2 Apr 2023 06:03:57 +0530 Subject: [PATCH] feat(inshorts): `hide-ads` patch (#1828) --- .../ad/annotations/HideAdsCompatibility.kt | 9 +++++ .../ad/fingerprints/InshortsAdsFingerprint.kt | 9 +++++ .../inshorts/ad/patch/InshortsAdsPatch.kt | 38 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/inshorts/ad/annotations/HideAdsCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/inshorts/ad/fingerprints/InshortsAdsFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/inshorts/ad/patch/InshortsAdsPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/inshorts/ad/annotations/HideAdsCompatibility.kt b/src/main/kotlin/app/revanced/patches/inshorts/ad/annotations/HideAdsCompatibility.kt new file mode 100644 index 000000000..372929a12 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/inshorts/ad/annotations/HideAdsCompatibility.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.inshorts.ad.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("com.nis.app")]) + +@Target(AnnotationTarget.CLASS) +internal annotation class HideAdsCompatibility diff --git a/src/main/kotlin/app/revanced/patches/inshorts/ad/fingerprints/InshortsAdsFingerprint.kt b/src/main/kotlin/app/revanced/patches/inshorts/ad/fingerprints/InshortsAdsFingerprint.kt new file mode 100644 index 000000000..1cbb57933 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/inshorts/ad/fingerprints/InshortsAdsFingerprint.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.inshorts.ad.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.Opcode + +object InshortsAdsFingerprint : MethodFingerprint( + "V", + strings = listOf("GoogleAdLoader","exception in requestAd") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/inshorts/ad/patch/InshortsAdsPatch.kt b/src/main/kotlin/app/revanced/patches/inshorts/ad/patch/InshortsAdsPatch.kt new file mode 100644 index 000000000..7c809f6f8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/inshorts/ad/patch/InshortsAdsPatch.kt @@ -0,0 +1,38 @@ +package app.revanced.patches.inshorts.ad.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.addInstruction +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.inshorts.ad.annotations.HideAdsCompatibility +import app.revanced.patches.inshorts.ad.fingerprints.InshortsAdsFingerprint + +@Patch +@Name("hide-ads") +@Description("Removes ads from Inshorts.") +@HideAdsCompatibility +@Version("0.0.1") +class HideAdsPatch : BytecodePatch( + listOf(InshortsAdsFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + InshortsAdsFingerprint.result?.let { result -> + result.apply { + mutableMethod.addInstruction( + 0, + """ + return-void + """ + ) + } + } ?: return InshortsAdsFingerprint.toErrorResult() + + return PatchResultSuccess() + } +}