Skip to content

Commit 8725a49

Browse files
SwakshanoSumAtrIX
andauthored
feat(Instagram): Add Hide highlights tray patch (#6489)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent 8b6360e commit 8725a49

File tree

6 files changed

+59
-26
lines changed

6 files changed

+59
-26
lines changed

patches/api/patches.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ public final class app/revanced/patches/instagram/hide/explore/HideExploreFeedKt
308308
public static final fun getHideExploreFeedPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
309309
}
310310

311+
public final class app/revanced/patches/instagram/hide/highlightsTray/HideHighlightsTrayPatchKt {
312+
public static final fun getHideHighlightsTrayPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
313+
}
314+
311315
public final class app/revanced/patches/instagram/hide/navigation/HideNavigationButtonsKt {
312316
public static final fun getHideNavigationButtonsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
313317
}
Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
11
package app.revanced.patches.instagram.hide.explore
22

3-
import app.revanced.patcher.Fingerprint
4-
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
5-
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
6-
import app.revanced.patcher.patch.BytecodePatchContext
73
import app.revanced.patcher.patch.bytecodePatch
8-
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
9-
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-
}
4+
import app.revanced.patches.instagram.shared.replaceStringWithBogus
275

286
@Suppress("unused")
297
val hideExploreFeedPatch = bytecodePatch(
@@ -34,6 +12,6 @@ val hideExploreFeedPatch = bytecodePatch(
3412
compatibleWith("com.instagram.android")
3513

3614
execute {
37-
exploreResponseJsonParserFingerprint.replaceJsonFieldWithBogus(EXPLORE_KEY_TO_BE_HIDDEN)
15+
exploreResponseJsonParserFingerprint.replaceStringWithBogus(EXPLORE_KEY_TO_BE_HIDDEN)
3816
}
3917
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package app.revanced.patches.instagram.hide.highlightsTray
2+
3+
import app.revanced.patcher.fingerprint
4+
5+
internal const val TARGET_STRING = "highlights_tray"
6+
7+
internal val highlightsUrlBuilderFingerprint = fingerprint {
8+
strings(TARGET_STRING,"X-IG-Accept-Hint")
9+
}
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.highlightsTray
2+
3+
import app.revanced.patcher.patch.bytecodePatch
4+
import app.revanced.patches.instagram.shared.replaceStringWithBogus
5+
6+
@Suppress("unused")
7+
val hideHighlightsTrayPatch = bytecodePatch(
8+
name = "Hide highlights tray",
9+
description = "Hides the highlights tray in profile section.",
10+
use = false
11+
) {
12+
compatibleWith("com.instagram.android")
13+
14+
execute {
15+
highlightsUrlBuilderFingerprint.replaceStringWithBogus(TARGET_STRING)
16+
}
17+
}

patches/src/main/kotlin/app/revanced/patches/instagram/hide/suggestions/HideSuggestedContent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package app.revanced.patches.instagram.hide.suggestions
22

33
import app.revanced.patcher.patch.bytecodePatch
4-
import app.revanced.patches.instagram.hide.explore.replaceJsonFieldWithBogus
4+
import app.revanced.patches.instagram.shared.replaceStringWithBogus
55

66
@Suppress("unused")
77
val hideSuggestedContent = bytecodePatch(
@@ -13,7 +13,7 @@ val hideSuggestedContent = bytecodePatch(
1313

1414
execute {
1515
FEED_ITEM_KEYS_TO_BE_HIDDEN.forEach { key ->
16-
feedItemParseFromJsonFingerprint.replaceJsonFieldWithBogus(key)
16+
feedItemParseFromJsonFingerprint.replaceStringWithBogus(key)
1717
}
1818
}
1919
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package app.revanced.patches.instagram.shared
2+
3+
import app.revanced.patcher.Fingerprint
4+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
5+
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
6+
import app.revanced.patcher.patch.BytecodePatchContext
7+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
8+
9+
context(BytecodePatchContext)
10+
internal fun Fingerprint.replaceStringWithBogus(
11+
targetString: String,
12+
) {
13+
val targetStringIndex = stringMatches!!.first { match -> match.string == targetString }.index
14+
val targetStringRegister = method.getInstruction<OneRegisterInstruction>(targetStringIndex).registerA
15+
16+
/**
17+
* Replaces the 'target string' with 'BOGUS'.
18+
* This is usually done when we need to override a JSON key or url,
19+
* to skip with a random string that is not a valid JSON key.
20+
*/
21+
method.replaceInstruction(
22+
targetStringIndex,
23+
"const-string v$targetStringRegister, \"BOGUS\"",
24+
)
25+
}

0 commit comments

Comments
 (0)