From 1408c2e6283f4c48020d4305008a45f53b96b5cc Mon Sep 17 00:00:00 2001 From: Loukios <24696530+Loukious@users.noreply.github.com> Date: Sun, 12 Nov 2023 22:21:06 +0100 Subject: [PATCH] feat(Facebook): Add `Hide story ads` patch (#3257) Co-authored-by: Loukious Co-authored-by: oSumAtrIX --- .../facebook/ads/story/HideStoryAdsPatch.kt | 26 +++++++++++++++++++ .../fingerprints/AdsInsertionFingerprint.kt | 3 +++ .../fingerprints/FetchMoreAdsFingerprint.kt | 3 +++ .../fingerprints/FieldMethodFingerprint.kt | 15 +++++++++++ 4 files changed, 47 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/facebook/ads/story/HideStoryAdsPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/AdsInsertionFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/FetchMoreAdsFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/FieldMethodFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/facebook/ads/story/HideStoryAdsPatch.kt b/src/main/kotlin/app/revanced/patches/facebook/ads/story/HideStoryAdsPatch.kt new file mode 100644 index 00000000..68aa8457 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/facebook/ads/story/HideStoryAdsPatch.kt @@ -0,0 +1,26 @@ +package app.revanced.patches.facebook.ads.story + +import app.revanced.extensions.exception +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.facebook.ads.story.fingerprints.AdsInsertionFingerprint +import app.revanced.patches.facebook.ads.story.fingerprints.FetchMoreAdsFingerprint + +@Patch( + name = "Hide story ads", + description = "Hides the ads in the Facebook app stories.", + compatiblePackages = [CompatiblePackage("com.facebook.katana")] +) +@Suppress("unused") +object HideStoryAdsPatch : BytecodePatch( + setOf(FetchMoreAdsFingerprint, AdsInsertionFingerprint) +) { + override fun execute(context: BytecodeContext) = + setOf(FetchMoreAdsFingerprint, AdsInsertionFingerprint).forEach { fingerprint -> + fingerprint.result?.mutableMethod?.replaceInstruction(0, "return-void") + ?: throw fingerprint.exception + } +} diff --git a/src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/AdsInsertionFingerprint.kt b/src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/AdsInsertionFingerprint.kt new file mode 100644 index 00000000..04ffce23 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/AdsInsertionFingerprint.kt @@ -0,0 +1,3 @@ +package app.revanced.patches.facebook.ads.story.fingerprints + +object AdsInsertionFingerprint : FieldMethodFingerprint(fieldValue = "AdBucketDataSourceUtil\$attemptAdsInsertion\$1") \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/FetchMoreAdsFingerprint.kt b/src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/FetchMoreAdsFingerprint.kt new file mode 100644 index 00000000..d02c8cc9 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/FetchMoreAdsFingerprint.kt @@ -0,0 +1,3 @@ +package app.revanced.patches.facebook.ads.story.fingerprints + +object FetchMoreAdsFingerprint : FieldMethodFingerprint(fieldValue = "AdBucketDataSourceUtil\$attemptFetchMoreAds\$1") diff --git a/src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/FieldMethodFingerprint.kt b/src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/FieldMethodFingerprint.kt new file mode 100644 index 00000000..52d6419b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/facebook/ads/story/fingerprints/FieldMethodFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.facebook.ads.story.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.iface.value.StringEncodedValue + +abstract class FieldMethodFingerprint(fieldValue: String) : MethodFingerprint( + returnType = "V", + parameters = listOf(), + customFingerprint = { methodDef, classDef -> + methodDef.name == "run" && classDef.fields.any any@{ field -> + if (field.name != "__redex_internal_original_name") return@any false + (field.initialValue as? StringEncodedValue)?.value == fieldValue + } + } +)