mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-29 13:20:19 +02:00
feat(YouTube): add Hide search term thumbnail
patch
This commit is contained in:
parent
c0532673b4
commit
8929cb9edb
@ -0,0 +1,140 @@
|
||||
package app.revanced.patches.youtube.general.searchterm
|
||||
|
||||
import app.revanced.extensions.exception
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
||||
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
|
||||
import app.revanced.patcher.patch.BytecodePatch
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||
import app.revanced.patcher.util.smali.ExternalLabel
|
||||
import app.revanced.patches.youtube.general.searchterm.fingerprints.SearchTermThumbnailFingerprint
|
||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||
import app.revanced.util.integrations.Constants.GENERAL
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||
|
||||
@Patch(
|
||||
name = "Hide search term thumbnail",
|
||||
description = "Hide thumbnails in the search term history.",
|
||||
dependencies = [SettingsPatch::class],
|
||||
compatiblePackages = [
|
||||
CompatiblePackage(
|
||||
"com.google.android.youtube",
|
||||
[
|
||||
"18.25.40",
|
||||
"18.27.36",
|
||||
"18.29.38",
|
||||
"18.30.37",
|
||||
"18.31.40",
|
||||
"18.32.39",
|
||||
"18.33.40",
|
||||
"18.34.38",
|
||||
"18.35.36",
|
||||
"18.36.39",
|
||||
"18.37.36",
|
||||
"18.38.44",
|
||||
"18.39.41",
|
||||
"18.40.34"
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
@Suppress("unused")
|
||||
object SearchTermThumbnailPatch : BytecodePatch(
|
||||
setOf(SearchTermThumbnailFingerprint)
|
||||
) {
|
||||
override fun execute(context: BytecodeContext) {
|
||||
SearchTermThumbnailFingerprint.result?.let { result ->
|
||||
result.mutableMethod.apply {
|
||||
val instructions = implementation!!.instructions
|
||||
|
||||
val relativeIndex = instructions.indexOfFirst { instruction ->
|
||||
instruction.opcode == Opcode.CONST_16
|
||||
&& (instruction as NarrowLiteralInstruction).narrowLiteral == 40
|
||||
}
|
||||
|
||||
val replaceIndex =
|
||||
getTargetIndexDownTo(
|
||||
relativeIndex,
|
||||
Opcode.INVOKE_VIRTUAL,
|
||||
"Landroid/widget/ImageView;->setVisibility(I)V"
|
||||
) - 1
|
||||
|
||||
val jumpIndex =
|
||||
getTargetIndexUpTo(
|
||||
relativeIndex,
|
||||
Opcode.INVOKE_STATIC,
|
||||
"Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;"
|
||||
) + 4
|
||||
|
||||
val replaceIndexInstruction = getInstruction<TwoRegisterInstruction>(replaceIndex)
|
||||
val replaceIndexReference = getInstruction<ReferenceInstruction>(replaceIndex).reference
|
||||
|
||||
addInstructionsWithLabels(
|
||||
replaceIndex + 1, """
|
||||
invoke-static { }, $GENERAL->hideSearchTermThumbnail()Z
|
||||
move-result v${replaceIndexInstruction.registerA}
|
||||
if-nez v${replaceIndexInstruction.registerA}, :hidden
|
||||
iget-object v${replaceIndexInstruction.registerA}, v${replaceIndexInstruction.registerB}, $replaceIndexReference
|
||||
""", ExternalLabel("hidden", getInstruction(jumpIndex))
|
||||
)
|
||||
removeInstruction(replaceIndex)
|
||||
}
|
||||
} ?: throw SearchTermThumbnailFingerprint.exception
|
||||
|
||||
/**
|
||||
* Add settings
|
||||
*/
|
||||
SettingsPatch.addPreference(
|
||||
arrayOf(
|
||||
"PREFERENCE: GENERAL_SETTINGS",
|
||||
"SETTINGS: HIDE_SEARCH_TERM_THUMBNAIL"
|
||||
)
|
||||
)
|
||||
|
||||
SettingsPatch.updatePatchStatus("Hide search term thumbnail")
|
||||
|
||||
}
|
||||
|
||||
private fun MutableMethod.getTargetIndexDownTo(
|
||||
startIndex: Int,
|
||||
opcode: Opcode,
|
||||
reference: String
|
||||
): Int {
|
||||
for (index in startIndex downTo 0) {
|
||||
if (getInstruction(index).opcode != opcode)
|
||||
continue
|
||||
|
||||
val targetReference = getInstruction<ReferenceInstruction>(index).reference.toString()
|
||||
if (targetReference != reference)
|
||||
continue
|
||||
|
||||
return index
|
||||
}
|
||||
throw PatchException("Failed to find hook method")
|
||||
}
|
||||
|
||||
private fun MutableMethod.getTargetIndexUpTo(
|
||||
startIndex: Int,
|
||||
opcode: Opcode,
|
||||
reference: String
|
||||
): Int {
|
||||
for (index in startIndex until implementation!!.instructions.size) {
|
||||
if (getInstruction(index).opcode != opcode)
|
||||
continue
|
||||
|
||||
val targetReference = getInstruction<ReferenceInstruction>(index).reference.toString()
|
||||
if (targetReference != reference)
|
||||
continue
|
||||
|
||||
return index
|
||||
}
|
||||
throw PatchException("Failed to find hook method")
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package app.revanced.patches.youtube.general.searchterm.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
object SearchTermThumbnailFingerprint : MethodFingerprint(
|
||||
returnType = "Landroid/view/View;",
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
parameters = listOf("I", "Landroid/view/View;", "Landroid/view/ViewGroup;"),
|
||||
strings = listOf("ss_rds")
|
||||
)
|
@ -488,6 +488,9 @@ Some components may not be hidden."</string>
|
||||
<string name="revanced_hide_search_bar_summary_off">Search bar is shown.</string>
|
||||
<string name="revanced_hide_search_bar_summary_on">Search bar is hidden.</string>
|
||||
<string name="revanced_hide_search_bar_title">Hide search bar in home feed</string>
|
||||
<string name="revanced_hide_search_term_thumbnail_summary_off">Thumbnails in the search term history are shown.</string>
|
||||
<string name="revanced_hide_search_term_thumbnail_summary_on">Thumbnails in the search term history are hidden.</string>
|
||||
<string name="revanced_hide_search_term_thumbnail_title">Hide search term thumbnail</string>
|
||||
<string name="revanced_hide_seekbar_summary_off">Video player seekbar is shown.</string>
|
||||
<string name="revanced_hide_seekbar_summary_on">Video player seekbar is hidden.</string>
|
||||
<string name="revanced_hide_seekbar_thumbnail_summary_off">Thumbnail seekbar is shown.</string>
|
||||
|
@ -205,6 +205,9 @@
|
||||
<!-- SETTINGS: HIDE_MIX_PLAYLISTS
|
||||
<SwitchPreference android:title="@string/revanced_hide_mix_playlists_title" android:key="revanced_hide_mix_playlists" android:defaultValue="false" android:summaryOn="@string/revanced_hide_mix_playlists_summary_on" android:summaryOff="@string/revanced_hide_mix_playlists_summary_off" />SETTINGS: HIDE_MIX_PLAYLISTS -->
|
||||
|
||||
<!-- SETTINGS: HIDE_SEARCH_TERM_THUMBNAIL
|
||||
<SwitchPreference android:title="@string/revanced_hide_search_term_thumbnail_title" android:key="revanced_hide_search_term_thumbnail" android:defaultValue="false" android:summaryOn="@string/revanced_hide_search_term_thumbnail_summary_on" android:summaryOff="@string/revanced_hide_search_term_thumbnail_summary_off" />SETTINGS: HIDE_SEARCH_TERM_THUMBNAIL -->
|
||||
|
||||
<!-- SETTINGS: HIDE_SNACK_BAR
|
||||
<SwitchPreference android:title="@string/revanced_hide_snack_bar_title" android:key="revanced_hide_snack_bar" android:defaultValue="false" android:summaryOn="@string/revanced_hide_snack_bar_summary_on" android:summaryOff="@string/revanced_hide_snack_bar_summary_off" />SETTINGS: HIDE_SNACK_BAR -->
|
||||
|
||||
@ -370,6 +373,7 @@
|
||||
<Preference android:title="Hide layout components" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
<Preference android:title="Hide load more button" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
<Preference android:title="Hide mix playlists" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
<Preference android:title="Hide search term thumbnail" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
<Preference android:title="Hide snack bar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
<Preference android:title="Hide suggestions shelf" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
<Preference android:title="Hide toolbar button" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user