feat(YouTube): add Hide toolbar button patch

This commit is contained in:
inotia00 2023-10-19 08:22:01 +09:00
parent e27c316bd2
commit e5ce2b707d
8 changed files with 182 additions and 0 deletions

View File

@ -0,0 +1,69 @@
package app.revanced.patches.youtube.general.toolbar
import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.utils.fingerprints.ToolBarPatchFingerprint
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.patches.youtube.utils.toolbar.ToolBarHookPatch
import app.revanced.util.integrations.Constants.GENERAL
@Patch(
name = "Hide toolbar button",
description = "Hide the button in the toolbar.",
dependencies = [
SettingsPatch::class,
ToolBarHookPatch::class
],
compatiblePackages = [
CompatiblePackage(
"com.google.android.youtube",
[
"18.24.37",
"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"
]
)
]
)
@Suppress("unused")
object ToolBarButtonPatch : BytecodePatch(
setOf(ToolBarPatchFingerprint)
) {
override fun execute(context: BytecodeContext) {
ToolBarPatchFingerprint.result?.let {
it.mutableMethod.apply {
addInstruction(
0,
"invoke-static {p0, p1}, $GENERAL->hideToolBarButton(Ljava/lang/String;Landroid/view/View;)V"
)
}
} ?: throw ToolBarPatchFingerprint.exception
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: GENERAL_SETTINGS",
"SETTINGS: HIDE_TOOLBAR_BUTTON"
)
)
SettingsPatch.updatePatchStatus("Hide toolbar button")
}
}

View File

@ -0,0 +1,23 @@
package app.revanced.patches.youtube.general.toolbar.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.MenuItemView
import app.revanced.util.bytecode.isWideLiteralExists
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object ToolBarButtonFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroid/view/MenuItem;"),
returnType = "V",
opcodes = listOf(
Opcode.IF_NEZ,
Opcode.SGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT,
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT
),
customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(MenuItemView) }
)

View File

@ -0,0 +1,13 @@
package app.revanced.patches.youtube.utils.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
object ToolBarPatchFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PRIVATE or AccessFlags.STATIC,
customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lapp/revanced/integrations/patches/utils/ToolBarPatch;"
&& methodDef.name == "hookToolBar"
}
)

View File

@ -51,6 +51,7 @@ object SharedResourceIdPatch : ResourcePatch() {
var InlineTimeBarPlayedNotHighlightedColor: Long = -1
var InsetOverlayViewLayout: Long = -1
var LiveChatButton: Long = -1
var MenuItemView: Long = -1
var MusicAppDeeplinkButtonView: Long = -1
var PosterArtWidthDefault: Long = -1
var QualityAuto: Long = -1
@ -131,6 +132,7 @@ object SharedResourceIdPatch : ResourcePatch() {
find(COLOR, "inline_time_bar_played_not_highlighted_color")
InsetOverlayViewLayout = find(ID, "inset_overlay_view_layout")
LiveChatButton = find(ID, "live_chat_overlay_button")
MenuItemView = find(ID, "menu_item_view")
MusicAppDeeplinkButtonView = find(ID, "music_app_deeplink_button_view")
PosterArtWidthDefault = find(DIMEN, "poster_art_width_default")
QualityAuto = find(STRING, "quality_auto")

View File

@ -0,0 +1,45 @@
package app.revanced.patches.youtube.utils.toolbar
import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.toolbar.fingerprints.ToolBarButtonFingerprint
import app.revanced.util.integrations.Constants.UTILS_PATH
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@Patch(dependencies = [SharedResourceIdPatch::class])
object ToolBarHookPatch : BytecodePatch(
setOf(ToolBarButtonFingerprint)
) {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$UTILS_PATH/ToolBarPatch;"
override fun execute(context: BytecodeContext) {
ToolBarButtonFingerprint.result?.let {
it.mutableMethod.apply {
val startIndex = it.scanResult.patternScanResult!!.startIndex
val endIndex = it.scanResult.patternScanResult!!.endIndex
val insertIndex = endIndex - 1
val enumRegister = getInstruction<OneRegisterInstruction>(startIndex).registerA
val freeRegister = getInstruction<TwoRegisterInstruction>(endIndex).registerA
val imageViewReference = getInstruction<ReferenceInstruction>(insertIndex).reference
addInstructions(
insertIndex, """
iget-object v$freeRegister, p0, $imageViewReference
invoke-static {v$enumRegister, v$freeRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->hookToolBar(Ljava/lang/Enum;Landroid/widget/ImageView;)V
"""
)
}
} ?: throw ToolBarButtonFingerprint.exception
}
}

View File

@ -0,0 +1,23 @@
package app.revanced.patches.youtube.utils.toolbar.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.MenuItemView
import app.revanced.util.bytecode.isWideLiteralExists
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
object ToolBarButtonFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Landroid/view/MenuItem;"),
returnType = "V",
opcodes = listOf(
Opcode.IF_NEZ,
Opcode.SGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT,
Opcode.IGET_OBJECT,
Opcode.IGET_OBJECT
),
customFingerprint = { methodDef, _ -> methodDef.isWideLiteralExists(MenuItemView) }
)

View File

@ -543,6 +543,9 @@ Known issue: Autoplay does not work"</string>
<string name="revanced_hide_transcript_section_summary_off">Transcript sections are shown</string>
<string name="revanced_hide_transcript_section_summary_on">Transcript sections are hidden</string>
<string name="revanced_hide_transcript_section_title">Hide transcript sections</string>
<string name="revanced_hide_toolbar_create_notification_button_summary_off">Create and Notification buttons are shown</string>
<string name="revanced_hide_toolbar_create_notification_button_summary_on">Create and Notification buttons are hidden</string>
<string name="revanced_hide_toolbar_create_notification_button_title">Hide buttons in toolbar</string>
<string name="revanced_hide_trending_searches_summary_off">Trending searches are shown</string>
<string name="revanced_hide_trending_searches_summary_on">Trending searches are hidden</string>
<string name="revanced_hide_trending_searches_title">Hide trending searches</string>

View File

@ -200,6 +200,9 @@
<!-- SETTINGS: HIDE_SUGGESTIONS_SHELF
<SwitchPreference android:title="@string/revanced_hide_suggestions_shelf_title" android:key="revanced_hide_suggestions_shelf" android:defaultValue="false" android:summary="@string/revanced_hide_suggestions_shelf_summary" />SETTINGS: HIDE_SUGGESTIONS_SHELF -->
<!-- SETTINGS: HIDE_TOOLBAR_BUTTON
<SwitchPreference android:title="@string/revanced_hide_toolbar_create_notification_button_title" android:key="revanced_hide_toolbar_create_notification_button" android:defaultValue="false" android:summaryOn="@string/revanced_hide_toolbar_create_notification_button_summary_on" android:summaryOff="@string/revanced_hide_toolbar_create_notification_button_summary_off" />SETTINGS: HIDE_TOOLBAR_BUTTON -->
<!-- SETTINGS: HIDE_TRENDING_SEARCHES
<SwitchPreference android:title="@string/revanced_hide_trending_searches_title" android:key="revanced_hide_trending_searches" android:defaultValue="true" android:summaryOn="@string/revanced_hide_trending_searches_summary_on" android:summaryOff="@string/revanced_hide_trending_searches_summary_off" />SETTINGS: HIDE_TRENDING_SEARCHES -->
@ -356,6 +359,7 @@
<Preference android:title="Hide mix playlists" 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"/>
<Preference android:title="Hide trending searches" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_misc" />