This commit is contained in:
inotia00
2023-04-10 00:52:41 +09:00
parent dc5db02a85
commit 9fa2ecc345
7 changed files with 146 additions and 0 deletions

View File

@ -0,0 +1,19 @@
package app.revanced.patches.youtube.layout.general.searchterms.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object SearchEndpointFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT,
Opcode.CONST_4,
Opcode.CONST_16,
Opcode.CONST_4
)
)

View File

@ -0,0 +1,12 @@
package app.revanced.patches.youtube.layout.general.searchterms.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
object SearchEndpointParentFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf(),
strings = listOf("voz-target-id")
)

View File

@ -0,0 +1,15 @@
package app.revanced.patches.youtube.layout.general.searchterms.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
object SearchSuggestionEntryFingerprint : MethodFingerprint(
customFingerprint = { methodDef ->
methodDef.implementation?.instructions?.any {
it.opcode.ordinal == Opcode.CONST.ordinal &&
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.searchSuggestionEntryLabelId
} == true
}
)

View File

@ -0,0 +1,91 @@
package app.revanced.patches.youtube.layout.general.searchterms.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.general.searchterms.fingerprints.*
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.GENERAL
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
@Patch
@Name("hide-search-terms")
@Description("Hide trending searches and search history in the search bar.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class SearchTermsPatch : BytecodePatch(
listOf(
SearchEndpointParentFingerprint,
SearchSuggestionEntryFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
SearchEndpointParentFingerprint.result?.let { parentResult ->
SearchEndpointFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let {
with (it.mutableMethod) {
val targetIndex = it.scanResult.patternScanResult!!.startIndex + 1
val targetRegister = (instruction(targetIndex) as OneRegisterInstruction).registerA
addInstruction(
targetIndex + 1,
"sput-boolean v$targetRegister, $GENERAL->isSearchWordEmpty:Z"
)
}
} ?: return SearchEndpointFingerprint.toErrorResult()
} ?: return SearchEndpointParentFingerprint.toErrorResult()
SearchSuggestionEntryFingerprint.result?.mutableMethod?.let { method ->
with (method.implementation!!.instructions) {
val targetIndex = this.indexOfFirst {
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.searchSuggestionEntryLabelId
} + 2
val targetRegister = (elementAt(targetIndex) as OneRegisterInstruction).registerA
method.addInstruction(
targetIndex + 4,
"invoke-static {v$targetRegister}, $GENERAL->hideSearchTerms(Landroid/view/View;)V"
)
method.addInstruction(
targetIndex + 2,
"invoke-static {v$targetRegister}, $GENERAL->hideSearchTerms(Landroid/view/View;)V"
)
}
} ?: return SearchSuggestionEntryFingerprint.toErrorResult()
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: GENERAL_SETTINGS",
"SETTINGS: HIDE_SEARCH_TERMS"
)
)
SettingsPatch.updatePatchStatus("hide-search-terms")
return PatchResultSuccess()
}
}

View File

@ -47,6 +47,7 @@ class SharedResourceIdPatch : ResourcePatch {
var reelRemixLabelId: Long = -1 var reelRemixLabelId: Long = -1
var relatedChipCloudMarginLabelId: Long = -1 var relatedChipCloudMarginLabelId: Long = -1
var rightCommentLabelId: Long = -1 var rightCommentLabelId: Long = -1
var searchSuggestionEntryLabelId: Long = -1
var scrubbingLabelId: Long = -1 var scrubbingLabelId: Long = -1
var timeBarPlayedDarkLabelId: Long = -1 var timeBarPlayedDarkLabelId: Long = -1
var timeStampsContainerLabelId: Long = -1 var timeStampsContainerLabelId: Long = -1
@ -89,6 +90,7 @@ class SharedResourceIdPatch : ResourcePatch {
reelRemixLabelId = find(ID, "reel_dyn_remix") reelRemixLabelId = find(ID, "reel_dyn_remix")
relatedChipCloudMarginLabelId = find(LAYOUT, "related_chip_cloud_reduced_margins") relatedChipCloudMarginLabelId = find(LAYOUT, "related_chip_cloud_reduced_margins")
rightCommentLabelId = find(DRAWABLE, "ic_right_comment_32c") rightCommentLabelId = find(DRAWABLE, "ic_right_comment_32c")
searchSuggestionEntryLabelId = find(LAYOUT, "search_suggestion_entry")
scrubbingLabelId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing") scrubbingLabelId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing")
timeBarPlayedDarkLabelId = find(COLOR, "inline_time_bar_colorized_bar_played_color_dark") timeBarPlayedDarkLabelId = find(COLOR, "inline_time_bar_colorized_bar_played_color_dark")
timeStampsContainerLabelId = find(ID, "timestamps_container") timeStampsContainerLabelId = find(ID, "timestamps_container")

View File

@ -471,6 +471,9 @@ Please do not report any issues you encounter while using this feature."</string
<string name="revanced_hide_time_stamp_summary_off">Time stamp is shown</string> <string name="revanced_hide_time_stamp_summary_off">Time stamp is shown</string>
<string name="revanced_hide_time_stamp_summary_on">Time stamp is hidden</string> <string name="revanced_hide_time_stamp_summary_on">Time stamp is hidden</string>
<string name="revanced_hide_time_stamp_title">Hide time stamp</string> <string name="revanced_hide_time_stamp_title">Hide time stamp</string>
<string name="revanced_hide_search_terms_summary_off">Trending searches &amp; search history are shown</string>
<string name="revanced_hide_search_terms_summary_on">Trending searches &amp; search history are hidden</string>
<string name="revanced_hide_search_terms_title">Hide trending searches &amp; search history</string>
<string name="revanced_hide_view_products_summary_off">View products banner is shown</string> <string name="revanced_hide_view_products_summary_off">View products banner is shown</string>
<string name="revanced_hide_view_products_summary_on">View products banner is hidden</string> <string name="revanced_hide_view_products_summary_on">View products banner is hidden</string>
<string name="revanced_hide_view_products_title">Hide view products banner (in player)</string> <string name="revanced_hide_view_products_title">Hide view products banner (in player)</string>

View File

@ -101,6 +101,9 @@
<!-- SETTINGS: HIDE_SNACKBAR <!-- SETTINGS: HIDE_SNACKBAR
<SwitchPreference android:title="@string/revanced_hide_snackbar_title" android:key="revanced_hide_snackbar" android:defaultValue="false" android:summaryOn="@string/revanced_hide_snackbar_summary_on" android:summaryOff="@string/revanced_hide_snackbar_summary_off" />SETTINGS: HIDE_SNACKBAR --> <SwitchPreference android:title="@string/revanced_hide_snackbar_title" android:key="revanced_hide_snackbar" android:defaultValue="false" android:summaryOn="@string/revanced_hide_snackbar_summary_on" android:summaryOff="@string/revanced_hide_snackbar_summary_off" />SETTINGS: HIDE_SNACKBAR -->
<!-- SETTINGS: HIDE_SEARCH_TERMS
<SwitchPreference android:title="@string/revanced_hide_search_terms_title" android:key="revanced_hide_search_terms" android:defaultValue="false" android:summaryOn="@string/revanced_hide_search_terms_summary_on" android:summaryOff="@string/revanced_hide_search_terms_summary_off" />SETTINGS: HIDE_SEARCH_TERMS -->
<!-- SETTINGS: HIDE_FLOATING_MICROPHONE <!-- SETTINGS: HIDE_FLOATING_MICROPHONE
<SwitchPreference android:title="@string/revanced_hide_floating_microphone_title" android:key="revanced_hide_floating_microphone" android:defaultValue="true" android:summaryOn="@string/revanced_hide_floating_microphone_summary_on" android:summaryOff="@string/revanced_hide_floating_microphone_summary_off" />SETTINGS: HIDE_FLOATING_MICROPHONE --> <SwitchPreference android:title="@string/revanced_hide_floating_microphone_title" android:key="revanced_hide_floating_microphone" android:defaultValue="true" android:summaryOn="@string/revanced_hide_floating_microphone_summary_on" android:summaryOff="@string/revanced_hide_floating_microphone_summary_off" />SETTINGS: HIDE_FLOATING_MICROPHONE -->
@ -459,6 +462,7 @@
<Preference android:title="hide-crowdfunding-box" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="hide-crowdfunding-box" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-email-address" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="hide-email-address" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-snackbar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="hide-snackbar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-search-terms" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-floating-microphone" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="hide-floating-microphone" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-category-bar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="hide-category-bar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-channel-avatar-section" android:summary="@string/revanced_patches_excluded" android:selectable="false"/> <Preference android:title="hide-channel-avatar-section" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>