Skip to content

Commit 50f0b9c

Browse files
authored
feat(Instagram): Add Hide suggested content patch (#6075)
1 parent a8c4bdb commit 50f0b9c

File tree

5 files changed

+67
-19
lines changed

5 files changed

+67
-19
lines changed

patches/api/patches.api

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public final class app/revanced/patches/instagram/feed/LimitFeedToFollowedProfil
269269
}
270270

271271
public final class app/revanced/patches/instagram/hide/explore/HideExploreFeedKt {
272-
public static final fun getHideExportFeedPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
272+
public static final fun getHideExploreFeedPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
273273
}
274274

275275
public final class app/revanced/patches/instagram/hide/navigation/HideNavigationButtonsKt {
@@ -280,6 +280,10 @@ public final class app/revanced/patches/instagram/hide/stories/HideStoriesKt {
280280
public static final fun getHideStoriesPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
281281
}
282282

283+
public final class app/revanced/patches/instagram/hide/suggestions/HideSuggestedContentKt {
284+
public static final fun getHideSuggestedContent ()Lapp/revanced/patcher/patch/BytecodePatch;
285+
}
286+
283287
public final class app/revanced/patches/instagram/misc/devmenu/EnableDeveloperMenuPatchKt {
284288
public static final fun getEnableDeveloperMenuPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
285289
}

patches/src/main/kotlin/app/revanced/patches/instagram/hide/explore/Fingerprints.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package app.revanced.patches.instagram.hide.explore
33

44
import app.revanced.patcher.fingerprint
55

6+
internal const val EXPLORE_KEY_TO_BE_HIDDEN = "sectional_items"
7+
68
internal val exploreResponseJsonParserFingerprint = fingerprint {
7-
strings("sectional_items", "ExploreTopicalFeedResponse")
9+
strings(EXPLORE_KEY_TO_BE_HIDDEN, "ExploreTopicalFeedResponse")
810
custom { method, _ -> method.name == "parseFromJson" }
911
}

patches/src/main/kotlin/app/revanced/patches/instagram/hide/explore/HideExploreFeed.kt

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
package app.revanced.patches.instagram.hide.explore
22

3+
import app.revanced.patcher.Fingerprint
34
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
45
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
6+
import app.revanced.patcher.patch.BytecodePatchContext
57
import app.revanced.patcher.patch.bytecodePatch
68
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
79

10+
context(BytecodePatchContext)
11+
internal fun Fingerprint.replaceJsonFieldWithBogus(
12+
key: String,
13+
) {
14+
val targetStringIndex = stringMatches!!.first { match -> match.string == key }.index
15+
val targetStringRegister = method.getInstruction<OneRegisterInstruction>(targetStringIndex).registerA
16+
17+
/**
18+
* Replacing the JSON key we want to skip with a random string that is not a valid JSON key.
19+
* This way the feeds array will never be populated.
20+
* Received JSON keys that are not handled are simply ignored, so there are no side effects.
21+
*/
22+
method.replaceInstruction(
23+
targetStringIndex,
24+
"const-string v$targetStringRegister, \"BOGUS\"",
25+
)
26+
}
27+
828
@Suppress("unused")
9-
val hideExportFeedPatch = bytecodePatch(
29+
val hideExploreFeedPatch = bytecodePatch(
1030
name = "Hide explore feed",
1131
description = "Hides posts and reels from the explore/search page.",
12-
use = false
32+
use = false,
1333
) {
1434
compatibleWith("com.instagram.android")
1535

1636
execute {
17-
exploreResponseJsonParserFingerprint.method.apply {
18-
val sectionalItemStringIndex = exploreResponseJsonParserFingerprint.stringMatches!!.first().index
19-
val sectionalItemStringRegister = getInstruction<OneRegisterInstruction>(sectionalItemStringIndex).registerA
20-
21-
/**
22-
* Replacing the JSON key we want to skip with a random string that is not a valid JSON key.
23-
* This way the feeds array will never be populated.
24-
* Received JSON keys that are not handled are simply ignored, so there are no side effects.
25-
*/
26-
replaceInstruction(
27-
sectionalItemStringIndex,
28-
"const-string v$sectionalItemStringRegister, \"BOGUS\""
29-
)
30-
}
37+
exploreResponseJsonParserFingerprint.replaceJsonFieldWithBogus(EXPLORE_KEY_TO_BE_HIDDEN)
3138
}
3239
}
33-
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package app.revanced.patches.instagram.hide.suggestions
2+
3+
import app.revanced.patcher.fingerprint
4+
5+
internal val FEED_ITEM_KEYS_TO_BE_HIDDEN = arrayOf(
6+
"clips_netego",
7+
"stories_netego",
8+
"in_feed_survey",
9+
"bloks_netego",
10+
"suggested_igd_channels",
11+
"suggested_top_accounts",
12+
"suggested_users",
13+
)
14+
15+
internal val feedItemParseFromJsonFingerprint = fingerprint {
16+
strings(*FEED_ITEM_KEYS_TO_BE_HIDDEN, "FeedItem")
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package app.revanced.patches.instagram.hide.suggestions
2+
3+
import app.revanced.patcher.patch.bytecodePatch
4+
import app.revanced.patches.instagram.hide.explore.replaceJsonFieldWithBogus
5+
6+
@Suppress("unused")
7+
val hideSuggestedContent = bytecodePatch(
8+
name = "Hide suggested content",
9+
description = "Hides suggested stories, reels, threads and survey from feed (Suggested posts will still be shown).",
10+
use = false,
11+
) {
12+
compatibleWith("com.instagram.android")
13+
14+
execute {
15+
FEED_ITEM_KEYS_TO_BE_HIDDEN.forEach { key ->
16+
feedItemParseFromJsonFingerprint.replaceJsonFieldWithBogus(key)
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)