diff --git a/patches/api/patches.api b/patches/api/patches.api index 15b955acb..dfc890bf2 100644 --- a/patches/api/patches.api +++ b/patches/api/patches.api @@ -269,7 +269,7 @@ public final class app/revanced/patches/instagram/feed/LimitFeedToFollowedProfil } public final class app/revanced/patches/instagram/hide/explore/HideExploreFeedKt { - public static final fun getHideExportFeedPatch ()Lapp/revanced/patcher/patch/BytecodePatch; + public static final fun getHideExploreFeedPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } public final class app/revanced/patches/instagram/hide/navigation/HideNavigationButtonsKt { @@ -280,6 +280,10 @@ public final class app/revanced/patches/instagram/hide/stories/HideStoriesKt { public static final fun getHideStoriesPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } +public final class app/revanced/patches/instagram/hide/suggestions/HideSuggestedContentKt { + public static final fun getHideSuggestedContent ()Lapp/revanced/patcher/patch/BytecodePatch; +} + public final class app/revanced/patches/instagram/misc/devmenu/EnableDeveloperMenuPatchKt { public static final fun getEnableDeveloperMenuPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/hide/explore/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/explore/Fingerprints.kt index 63402788b..a85e8eb30 100644 --- a/patches/src/main/kotlin/app/revanced/patches/instagram/hide/explore/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/explore/Fingerprints.kt @@ -3,7 +3,9 @@ package app.revanced.patches.instagram.hide.explore import app.revanced.patcher.fingerprint +internal const val EXPLORE_KEY_TO_BE_HIDDEN = "sectional_items" + internal val exploreResponseJsonParserFingerprint = fingerprint { - strings("sectional_items", "ExploreTopicalFeedResponse") + strings(EXPLORE_KEY_TO_BE_HIDDEN, "ExploreTopicalFeedResponse") custom { method, _ -> method.name == "parseFromJson" } } diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/hide/explore/HideExploreFeed.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/explore/HideExploreFeed.kt index 25ff17907..a2c7d5ba5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/instagram/hide/explore/HideExploreFeed.kt +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/explore/HideExploreFeed.kt @@ -1,33 +1,39 @@ package app.revanced.patches.instagram.hide.explore +import app.revanced.patcher.Fingerprint import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.patch.BytecodePatchContext import app.revanced.patcher.patch.bytecodePatch import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +context(BytecodePatchContext) +internal fun Fingerprint.replaceJsonFieldWithBogus( + key: String, +) { + val targetStringIndex = stringMatches!!.first { match -> match.string == key }.index + val targetStringRegister = method.getInstruction(targetStringIndex).registerA + + /** + * Replacing the JSON key we want to skip with a random string that is not a valid JSON key. + * This way the feeds array will never be populated. + * Received JSON keys that are not handled are simply ignored, so there are no side effects. + */ + method.replaceInstruction( + targetStringIndex, + "const-string v$targetStringRegister, \"BOGUS\"", + ) +} + @Suppress("unused") -val hideExportFeedPatch = bytecodePatch( +val hideExploreFeedPatch = bytecodePatch( name = "Hide explore feed", description = "Hides posts and reels from the explore/search page.", - use = false + use = false, ) { compatibleWith("com.instagram.android") execute { - exploreResponseJsonParserFingerprint.method.apply { - val sectionalItemStringIndex = exploreResponseJsonParserFingerprint.stringMatches!!.first().index - val sectionalItemStringRegister = getInstruction(sectionalItemStringIndex).registerA - - /** - * Replacing the JSON key we want to skip with a random string that is not a valid JSON key. - * This way the feeds array will never be populated. - * Received JSON keys that are not handled are simply ignored, so there are no side effects. - */ - replaceInstruction( - sectionalItemStringIndex, - "const-string v$sectionalItemStringRegister, \"BOGUS\"" - ) - } + exploreResponseJsonParserFingerprint.replaceJsonFieldWithBogus(EXPLORE_KEY_TO_BE_HIDDEN) } } - diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/hide/suggestions/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/suggestions/Fingerprints.kt new file mode 100644 index 000000000..0f731b4f4 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/suggestions/Fingerprints.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.instagram.hide.suggestions + +import app.revanced.patcher.fingerprint + +internal val FEED_ITEM_KEYS_TO_BE_HIDDEN = arrayOf( + "clips_netego", + "stories_netego", + "in_feed_survey", + "bloks_netego", + "suggested_igd_channels", + "suggested_top_accounts", + "suggested_users", +) + +internal val feedItemParseFromJsonFingerprint = fingerprint { + strings(*FEED_ITEM_KEYS_TO_BE_HIDDEN, "FeedItem") +} diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/hide/suggestions/HideSuggestedContent.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/suggestions/HideSuggestedContent.kt new file mode 100644 index 000000000..0c2501411 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/hide/suggestions/HideSuggestedContent.kt @@ -0,0 +1,19 @@ +package app.revanced.patches.instagram.hide.suggestions + +import app.revanced.patcher.patch.bytecodePatch +import app.revanced.patches.instagram.hide.explore.replaceJsonFieldWithBogus + +@Suppress("unused") +val hideSuggestedContent = bytecodePatch( + name = "Hide suggested content", + description = "Hides suggested stories, reels, threads and survey from feed (Suggested posts will still be shown).", + use = false, +) { + compatibleWith("com.instagram.android") + + execute { + FEED_ITEM_KEYS_TO_BE_HIDDEN.forEach { key -> + feedItemParseFromJsonFingerprint.replaceJsonFieldWithBogus(key) + } + } +}