Skip to content

Commit 5cb46c4

Browse files
authored
feat(Viber): Add Hide navigation buttons patch (#5991)
1 parent 52c3695 commit 5cb46c4

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

patches/api/patches.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,10 @@ public final class app/revanced/patches/viber/ads/HideAdsPatchKt {
13061306
public static final fun getHideAdsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
13071307
}
13081308

1309+
public final class app/revanced/patches/viber/misc/navbar/HideNavigationButtonsKt {
1310+
public static final fun getHideNavigationButtonsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
1311+
}
1312+
13091313
public final class app/revanced/patches/vsco/misc/pro/UnlockProPatchKt {
13101314
public static final fun getUnlockProPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
13111315
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app.revanced.patches.viber.misc.navbar
2+
import app.revanced.patcher.fingerprint
3+
import app.revanced.patcher.patch.BytecodePatchContext
4+
5+
internal val tabIdClassFingerprint = fingerprint {
6+
strings("shouldShowTabId")
7+
}
8+
9+
context(BytecodePatchContext)
10+
internal val shouldShowTabIdMethodFingerprint get() = fingerprint {
11+
parameters("I", "I")
12+
returns("Z")
13+
custom { methodDef, classDef ->
14+
classDef == tabIdClassFingerprint.classDef
15+
}
16+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package app.revanced.patches.viber.misc.navbar
2+
3+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
4+
import app.revanced.patcher.patch.booleanOption
5+
import app.revanced.patcher.patch.bytecodePatch
6+
import java.util.logging.Logger
7+
import kotlin.collections.joinToString
8+
9+
10+
private const val instructionsFooter = """
11+
# If we reach this, it means that this tab has been disabled by user
12+
const/4 v0, 0
13+
return v0 # return false as "This tab is not enabled"
14+
15+
# Proceed with default execution
16+
:continue
17+
nop
18+
"""
19+
20+
@Suppress("unused")
21+
val hideNavigationButtonsPatch = bytecodePatch(
22+
name = "Hide navigation buttons",
23+
description = "Permanently hides navigation bar buttons, such as Explore and Marketplace.",
24+
use = false
25+
) {
26+
compatibleWith("com.viber.voip")
27+
28+
val hideOptions = AllowedNavigationItems.entries.associateWith {
29+
booleanOption(
30+
key = it.key,
31+
default = it.defaultHideOption,
32+
title = it.title,
33+
description = it.description,
34+
)
35+
}
36+
37+
execute {
38+
// Items that won't be forcefully hidden.
39+
val allowedItems = hideOptions.filter { (option, enabled) -> enabled.value != true }
40+
41+
if (allowedItems.size == AllowedNavigationItems.entries.size) {
42+
return@execute Logger.getLogger(this::class.java.name).warning(
43+
"No hide navigation buttons options are enabled. No changes made."
44+
)
45+
}
46+
47+
val injectionInstructions = allowedItems
48+
.map { it.key.buildAllowInstruction() }
49+
.joinToString("\n") + instructionsFooter
50+
51+
shouldShowTabIdMethodFingerprint
52+
.method
53+
.addInstructionsWithLabels(0, injectionInstructions)
54+
}
55+
}
56+
57+
/**
58+
* Navigation items taken from source code.
59+
* They appear in code like new NavigationItem(0, R.string.bottom_tab_chats, R.drawable.ic_tab_chats).
60+
*/
61+
private enum class AllowedNavigationItems(
62+
val defaultHideOption: Boolean,
63+
private val itemName: String,
64+
private vararg val ids: Int
65+
) {
66+
CHATS(false, "Chats", 0),
67+
CALLS(false, "Calls", 1, 7),
68+
EXPLORE(true, "Explore", 2),
69+
MORE(false, "More", 3),
70+
PAY(true, "Pay", 5),
71+
CAMERA(true, "Camera", 6),
72+
MARKETPLACE(true, "Marketplace", 8);
73+
74+
val key = "hide$itemName"
75+
val title = "Hide $itemName"
76+
val description = "Permanently hides the $itemName button."
77+
78+
fun buildAllowInstruction(): String =
79+
ids.joinToString("\n") { id ->
80+
"""
81+
const/4 v0, $id # If tabId == $id ($itemName), don't hide it
82+
if-eq p1, v0, :continue
83+
"""
84+
}
85+
}

0 commit comments

Comments
 (0)