From e5ce2b707d8f509b8c0a91cfc45ba899e77ab4ec Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 19 Oct 2023 08:22:01 +0900 Subject: [PATCH] feat(YouTube): add `Hide toolbar button` patch --- .../general/toolbar/ToolBarButtonPatch.kt | 69 +++++++++++++++++++ .../fingerprints/ToolBarButtonFingerprint.kt | 23 +++++++ .../fingerprints/ToolBarPatchFingerprint.kt | 13 ++++ .../utils/resourceid/SharedResourceIdPatch.kt | 2 + .../youtube/utils/toolbar/ToolBarHookPatch.kt | 45 ++++++++++++ .../fingerprints/ToolBarButtonFingerprint.kt | 23 +++++++ .../youtube/settings/host/values/strings.xml | 3 + .../youtube/settings/xml/revanced_prefs.xml | 4 ++ 8 files changed, 182 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/general/toolbar/ToolBarButtonPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/general/toolbar/fingerprints/ToolBarButtonFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/ToolBarPatchFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/ToolBarHookPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/fingerprints/ToolBarButtonFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/toolbar/ToolBarButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/general/toolbar/ToolBarButtonPatch.kt new file mode 100644 index 000000000..6cce0f5f8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/toolbar/ToolBarButtonPatch.kt @@ -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") + + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/general/toolbar/fingerprints/ToolBarButtonFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/general/toolbar/fingerprints/ToolBarButtonFingerprint.kt new file mode 100644 index 000000000..31e1549e2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/general/toolbar/fingerprints/ToolBarButtonFingerprint.kt @@ -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) } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/ToolBarPatchFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/ToolBarPatchFingerprint.kt new file mode 100644 index 000000000..2de08d8f2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/fingerprints/ToolBarPatchFingerprint.kt @@ -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" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt index 8b712b41b..e3bcf3386 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt @@ -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") diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/ToolBarHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/ToolBarHookPatch.kt new file mode 100644 index 000000000..e387c2c97 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/ToolBarHookPatch.kt @@ -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(startIndex).registerA + val freeRegister = getInstruction(endIndex).registerA + + val imageViewReference = getInstruction(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 + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/fingerprints/ToolBarButtonFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/fingerprints/ToolBarButtonFingerprint.kt new file mode 100644 index 000000000..b0588b7f3 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/toolbar/fingerprints/ToolBarButtonFingerprint.kt @@ -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) } +) \ No newline at end of file diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml index a80cebeb9..0bdc18c5f 100644 --- a/src/main/resources/youtube/settings/host/values/strings.xml +++ b/src/main/resources/youtube/settings/host/values/strings.xml @@ -543,6 +543,9 @@ Known issue: Autoplay does not work" Transcript sections are shown Transcript sections are hidden Hide transcript sections + Create and Notification buttons are shown + Create and Notification buttons are hidden + Hide buttons in toolbar Trending searches are shown Trending searches are hidden Hide trending searches diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml index ad8f39c65..569e358ab 100644 --- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -200,6 +200,9 @@ + + @@ -356,6 +359,7 @@ +