1
1
package app.revanced.patches.youtube.layout.searchbar
2
2
3
- import app.revanced.patcher.Fingerprint
4
- import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
5
3
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
6
- import app.revanced.patcher.patch.BytecodePatchContext
7
4
import app.revanced.patcher.patch.bytecodePatch
8
- import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
5
+ import app.revanced.patcher.patch.resourcePatch
9
6
import app.revanced.patches.all.misc.resources.addResources
10
7
import app.revanced.patches.all.misc.resources.addResourcesPatch
8
+ import app.revanced.patches.shared.misc.mapping.get
9
+ import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
10
+ import app.revanced.patches.shared.misc.mapping.resourceMappings
11
11
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
12
12
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
13
13
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
14
14
import app.revanced.patches.youtube.misc.settings.settingsPatch
15
+ import app.revanced.util.addInstructionsAtControlFlowLabel
16
+ import app.revanced.util.findInstructionIndicesReversedOrThrow
17
+ import app.revanced.util.getReference
18
+ import app.revanced.util.indexOfFirstInstructionOrThrow
19
+ import com.android.tools.smali.dexlib2.Opcode
15
20
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
21
+ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
16
22
17
23
private const val EXTENSION_CLASS_DESCRIPTOR =
18
24
" Lapp/revanced/extension/youtube/patches/WideSearchbarPatch;"
19
25
26
+ internal var ytWordmarkHeaderId = - 1L
27
+ private set
28
+ internal var ytPremiumWordmarkHeaderId = - 1L
29
+ private set
30
+
31
+ private val wideSearchbarResourcePatch = resourcePatch {
32
+ dependsOn(resourceMappingPatch)
33
+
34
+ execute {
35
+ ytWordmarkHeaderId = resourceMappings[
36
+ " attr" ,
37
+ " ytWordmarkHeader" ,
38
+ ]
39
+
40
+ ytPremiumWordmarkHeaderId = resourceMappings[
41
+ " attr" ,
42
+ " ytPremiumWordmarkHeader" ,
43
+ ]
44
+ }
45
+ }
46
+
20
47
val wideSearchbarPatch = bytecodePatch(
21
48
name = " Wide search bar" ,
22
- description = " Adds an option to replace the search icon with a wide search bar. This will hide the YouTube logo when active." ,
49
+ description = " Adds an option to replace the search icon with a wide search bar. " +
50
+ " This will hide the YouTube logo when active." ,
23
51
) {
24
52
dependsOn(
25
53
sharedExtensionPatch,
26
54
settingsPatch,
27
55
addResourcesPatch,
56
+ wideSearchbarResourcePatch,
28
57
)
29
58
30
59
compatibleWith(
@@ -46,37 +75,29 @@ val wideSearchbarPatch = bytecodePatch(
46
75
SwitchPreference (" revanced_wide_searchbar" ),
47
76
)
48
77
49
- /* *
50
- * Navigate a fingerprints method at a given index mutably .
51
- *
52
- * @param index The index to navigate to.
53
- * @param from The fingerprint to navigate the method on.
54
- * @return The [MutableMethod] which was navigated on.
55
- */
56
- fun BytecodePatchContext. walkMutable ( index : Int , from : Fingerprint ) =
57
- navigate(from.originalMethod).to(index).stop()
78
+ setWordmarkHeaderFingerprint. let {
79
+ // Navigate to the method that checks if the YT logo is shown beside the search bar .
80
+ val showLogoMethod = with (it.originalMethod) {
81
+ val invokeStaticIndex = indexOfFirstInstructionOrThrow {
82
+ opcode == Opcode . INVOKE_STATIC &&
83
+ getReference< MethodReference >()?.returnType == " Z "
84
+ }
85
+ navigate(it.originalMethod).to(invokeStaticIndex).stop()
86
+ }
58
87
59
- /* *
60
- * Injects instructions required for certain methods.
61
- */
62
- fun MutableMethod.injectSearchBarHook () {
63
- val insertIndex = implementation!! .instructions.size - 1
64
- val insertRegister = getInstruction<OneRegisterInstruction >(insertIndex).registerA
65
-
66
- addInstructions(
67
- insertIndex,
68
- """
69
- invoke-static {v$insertRegister }, $EXTENSION_CLASS_DESCRIPTOR ->enableWideSearchbar(Z)Z
70
- move-result v$insertRegister
71
- """ ,
72
- )
73
- }
88
+ showLogoMethod.apply {
89
+ findInstructionIndicesReversedOrThrow(Opcode .RETURN ).forEach { index ->
90
+ val register = getInstruction<OneRegisterInstruction >(index).registerA
74
91
75
- mapOf (
76
- setWordmarkHeaderFingerprint to 1 ,
77
- createSearchSuggestionsFingerprint to createSearchSuggestionsFingerprint.patternMatch!! .startIndex,
78
- ).forEach { (fingerprint, callIndex) ->
79
- walkMutable(callIndex, fingerprint).injectSearchBarHook()
92
+ addInstructionsAtControlFlowLabel(
93
+ index,
94
+ """
95
+ invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR ->enableWideSearchbar(Z)Z
96
+ move-result v$register
97
+ """
98
+ )
99
+ }
100
+ }
80
101
}
81
102
}
82
103
}
0 commit comments