From 9fa2ecc345fc3e445424b2fe8fd74a90720094cb Mon Sep 17 00:00:00 2001 From: inotia00 Date: Mon, 10 Apr 2023 00:52:41 +0900 Subject: [PATCH] add `hide-search-terms` patch https://github.com/inotia00/ReVanced_Extended/issues/657 --- .../fingerprints/SearchEndpointFingerprint.kt | 19 ++++ .../SearchEndpointParentFingerprint.kt | 12 +++ .../SearchSuggestionEntryFingerprint.kt | 15 +++ .../searchterms/patch/SearchTermsPatch.kt | 91 +++++++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 2 + .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 4 + 7 files changed, 146 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchEndpointFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchEndpointParentFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchSuggestionEntryFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/patch/SearchTermsPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchEndpointFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchEndpointFingerprint.kt new file mode 100644 index 000000000..b4ea8b077 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchEndpointFingerprint.kt @@ -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 + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchEndpointParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchEndpointParentFingerprint.kt new file mode 100644 index 000000000..7df9614a5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchEndpointParentFingerprint.kt @@ -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") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchSuggestionEntryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchSuggestionEntryFingerprint.kt new file mode 100644 index 000000000..03804ed99 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/fingerprints/SearchSuggestionEntryFingerprint.kt @@ -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 + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/patch/SearchTermsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/patch/SearchTermsPatch.kt new file mode 100644 index 000000000..2d39b7cfe --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/general/searchterms/patch/SearchTermsPatch.kt @@ -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() + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt index 38cbc84a4..82234ef34 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -47,6 +47,7 @@ class SharedResourceIdPatch : ResourcePatch { var reelRemixLabelId: Long = -1 var relatedChipCloudMarginLabelId: Long = -1 var rightCommentLabelId: Long = -1 + var searchSuggestionEntryLabelId: Long = -1 var scrubbingLabelId: Long = -1 var timeBarPlayedDarkLabelId: Long = -1 var timeStampsContainerLabelId: Long = -1 @@ -89,6 +90,7 @@ class SharedResourceIdPatch : ResourcePatch { reelRemixLabelId = find(ID, "reel_dyn_remix") relatedChipCloudMarginLabelId = find(LAYOUT, "related_chip_cloud_reduced_margins") rightCommentLabelId = find(DRAWABLE, "ic_right_comment_32c") + searchSuggestionEntryLabelId = find(LAYOUT, "search_suggestion_entry") scrubbingLabelId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing") timeBarPlayedDarkLabelId = find(COLOR, "inline_time_bar_colorized_bar_played_color_dark") timeStampsContainerLabelId = find(ID, "timestamps_container") diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index 64ff058e4..f173c753f 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -471,6 +471,9 @@ Please do not report any issues you encounter while using this feature."Time stamp is shown Time stamp is hidden Hide time stamp + Trending searches & search history are shown + Trending searches & search history are hidden + Hide trending searches & search history View products banner is shown View products banner is hidden Hide view products banner (in player) diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index a1bb254c8..16bd2e3d1 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -101,6 +101,9 @@ + + @@ -459,6 +462,7 @@ +