From c1b9eefa280b980d08a571e1ce205dc71ccde3b6 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Wed, 2 Aug 2023 01:35:40 +0200 Subject: [PATCH] feat(YouTube): Support version `18.29.38` --- .../LayoutConstructorFingerprint.kt | 12 ++++ ...essibilityPlayerProgressTimeFingerprint.kt | 12 ---- .../OnTouchEventHandlerFingerprint.kt | 32 ++++++++++ .../patch/EnableSeekbarTappingPatch.kt | 46 +++++--------- .../EnableSeekbarTappingResourcePatch.kt | 13 +--- .../SubtitleButtonControllerFingerprint.kt | 5 +- .../LayoutConstructorFingerprint.kt | 10 --- .../autoplay/patch/HideAutoplayButtonPatch.kt | 2 +- .../captions/patch/HideCaptionsButtonPatch.kt | 6 +- .../HideLoadMoreButtonFingerprint.kt | 7 +-- .../CreatePlayerOverviewFingerprint.kt | 3 +- .../fingerprints/TimeCounterFingerprint.kt | 30 ++++----- .../FullscreenPanelsCompatibility.kt | 8 --- .../FullscreenViewAdderFingerprint.kt | 11 ---- .../FullscreenViewAdderParentFingerprint.kt | 20 ------ .../patch/FullscreenPanelsRemoverPatch.kt | 63 ------------------- .../fingerprints/ShortsTextViewFingerprint.kt | 4 +- ...TextComponentAtomicReferenceFingerprint.kt | 2 +- .../ControlsOverlayFingerprint.kt | 7 +-- .../patch/SponsorBlockBytecodePatch.kt | 31 +++++---- .../MiniPlayerOverrideFingerprint.kt | 19 ++---- .../MiniPlayerOverrideParentFingerprint.kt | 7 --- .../patch/TabletMiniPlayerPatch.kt | 48 +++++++------- ...izedPlaybackPolicyControllerFingerprint.kt | 23 ++++--- .../patch/PlayerControlsBytecodePatch.kt | 13 +++- .../PlayerControlsVisibilityFingerprint.kt | 5 +- .../fingerprint/PlayerTypeFingerprint.kt | 20 +----- .../fingerprint/VideoStateFingerprint.kt | 5 +- .../playertype/patch/PlayerTypeHookPatch.kt | 16 ++--- .../videoid/fingerprint/VideoIdFingerprint.kt | 6 +- .../VideoIdFingerprintBackgroundPlay.kt | 21 +++++-- .../video/videoid/patch/VideoIdPatch.kt | 41 +++++++----- 32 files changed, 214 insertions(+), 334 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/shared/fingerprints/LayoutConstructorFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/AccessibilityPlayerProgressTimeFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/OnTouchEventHandlerFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/fingerprints/LayoutConstructorFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/annotations/FullscreenPanelsCompatibility.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/patch/FullscreenPanelsRemoverPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideParentFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/shared/fingerprints/LayoutConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/shared/fingerprints/LayoutConstructorFingerprint.kt new file mode 100644 index 00000000..ad843e9f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/shared/fingerprints/LayoutConstructorFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.shared.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +object LayoutConstructorFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = emptyList(), + strings = listOf("1.0x") +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/AccessibilityPlayerProgressTimeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/AccessibilityPlayerProgressTimeFingerprint.kt deleted file mode 100644 index e56b68e5..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/AccessibilityPlayerProgressTimeFingerprint.kt +++ /dev/null @@ -1,12 +0,0 @@ -package app.revanced.patches.youtube.interaction.seekbar.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patches.youtube.interaction.seekbar.patch.EnableSeekbarTappingResourcePatch -import app.revanced.util.patch.LiteralValueFingerprint -import com.android.tools.smali.dexlib2.AccessFlags - -object AccessibilityPlayerProgressTimeFingerprint : LiteralValueFingerprint( - returnType = "L", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - literal = EnableSeekbarTappingResourcePatch.accessibilityPlayerProgressTime -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/OnTouchEventHandlerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/OnTouchEventHandlerFingerprint.kt new file mode 100644 index 00000000..98a0d214 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/fingerprints/OnTouchEventHandlerFingerprint.kt @@ -0,0 +1,32 @@ +package app.revanced.patches.youtube.interaction.seekbar.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +@FuzzyPatternScanMethod(3) +object OnTouchEventHandlerFingerprint : MethodFingerprint( + returnType = "Z", + accessFlags = AccessFlags.PUBLIC or AccessFlags.PUBLIC, + parameters = listOf("L"), + opcodes = listOf( + Opcode.INVOKE_VIRTUAL, // oMethodReference + Opcode.RETURN, + Opcode.IGET_OBJECT, + Opcode.IGET_BOOLEAN, + Opcode.IF_EQZ, + Opcode.INVOKE_VIRTUAL, + Opcode.RETURN, + Opcode.INT_TO_FLOAT, + Opcode.INT_TO_FLOAT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_NEZ, + Opcode.RETURN, + Opcode.INVOKE_VIRTUAL, + Opcode.INVOKE_VIRTUAL, // pMethodReference + ), + customFingerprint = { methodDef, _ -> methodDef.name == "onTouchEvent" } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingPatch.kt index 424c7f32..32a5ed3b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingPatch.kt @@ -13,13 +13,15 @@ import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.youtube.interaction.seekbar.annotation.SeekbarTappingCompatibility -import app.revanced.patches.youtube.interaction.seekbar.fingerprints.AccessibilityPlayerProgressTimeFingerprint +import app.revanced.patches.youtube.interaction.seekbar.fingerprints.OnTouchEventHandlerFingerprint import app.revanced.patches.youtube.interaction.seekbar.fingerprints.SeekbarTappingFingerprint import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference @Patch @DependsOn([IntegrationsPatch::class, EnableSeekbarTappingResourcePatch::class]) @@ -27,37 +29,23 @@ import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c @Description("Enables tap-to-seek on the seekbar of the video player.") @SeekbarTappingCompatibility class EnableSeekbarTappingPatch : BytecodePatch( - listOf(AccessibilityPlayerProgressTimeFingerprint, SeekbarTappingFingerprint) + listOf(OnTouchEventHandlerFingerprint, SeekbarTappingFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { // Find the required methods to tap the seekbar. - val seekbarTappingMethods = - AccessibilityPlayerProgressTimeFingerprint.result?.classDef?.methods?.let { methods -> - buildMap { - // find the methods which tap the seekbar - methods.forEach { method -> - if (method.implementation == null) return@forEach + val seekbarTappingMethods = OnTouchEventHandlerFingerprint.result?.let { + val patternScanResult = it.scanResult.patternScanResult!! - val instructions = method.implementation!!.instructions + fun getReference(index: Int) = it.mutableMethod.getInstruction(index) + .reference as MethodReference - // The method has more than 7 instructions. - if (instructions.count() < 7) return@forEach - - // The 7th instruction has the opcode CONST_4. - val instruction = instructions.elementAt(6) - if (instruction.opcode != Opcode.CONST_4) return@forEach - - // the literal for this instruction has to be either 1 or 2. - val literal = (instruction as NarrowLiteralInstruction).narrowLiteral - - // Based on the literal, determine which method is which. - if (literal == 1) this["P"] = method - if (literal == 2) this["O"] = method - } - } + buildMap { + put("O", getReference(patternScanResult.endIndex)) + put("N", getReference(patternScanResult.startIndex)) } + } - seekbarTappingMethods ?: return AccessibilityPlayerProgressTimeFingerprint.toErrorResult() + seekbarTappingMethods ?: return OnTouchEventHandlerFingerprint.toErrorResult() SeekbarTappingFingerprint.result?.let { val insertIndex = it.scanResult.patternScanResult!!.endIndex - 1 @@ -68,11 +56,11 @@ class EnableSeekbarTappingPatch : BytecodePatch( val freeRegister = 0 val xAxisRegister = 2 - val pMethod = seekbarTappingMethods["P"]!! val oMethod = seekbarTappingMethods["O"]!! + val nMethod = seekbarTappingMethods["N"]!! - fun Method.toInvokeInstructionString() = - "invoke-virtual { v$thisInstanceRegister, v$xAxisRegister }, $definingClass->$name(I)V" + fun MethodReference.toInvokeInstructionString() = + "invoke-virtual { v$thisInstanceRegister, v$xAxisRegister }, $this" addInstructionsWithLabels( insertIndex, @@ -81,7 +69,7 @@ class EnableSeekbarTappingPatch : BytecodePatch( move-result v$freeRegister if-eqz v$freeRegister, :disabled ${oMethod.toInvokeInstructionString()} - ${pMethod.toInvokeInstructionString()} + ${nMethod.toInvokeInstructionString()} """, ExternalLabel("disabled", getInstruction(insertIndex)) ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingResourcePatch.kt index 29c62c37..a28a5327 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/patch/EnableSeekbarTappingResourcePatch.kt @@ -2,16 +2,14 @@ package app.revanced.patches.youtube.interaction.seekbar.patch import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.ResourcePatch import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch -@DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) +@DependsOn([SettingsPatch::class]) class EnableSeekbarTappingResourcePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { SettingsPatch.PreferenceScreen.INTERACTIONS.addPreferences( @@ -22,15 +20,6 @@ class EnableSeekbarTappingResourcePatch : ResourcePatch { StringResource("revanced_seekbar_tapping_summary_off", "Seekbar tapping is disabled") ) ) - - accessibilityPlayerProgressTime = ResourceMappingPatch.resourceMappings.find { - it.name == "accessibility_player_progress_time" - }?.id ?: return PatchResultError("Failed to find required resource") - return PatchResultSuccess() } - - internal companion object { - var accessibilityPlayerProgressTime = -1L - } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/fingerprints/SubtitleButtonControllerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/fingerprints/SubtitleButtonControllerFingerprint.kt index 1d9545c7..b3b0462b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/fingerprints/SubtitleButtonControllerFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/fingerprints/SubtitleButtonControllerFingerprint.kt @@ -19,8 +19,5 @@ object SubtitleButtonControllerFingerprint : MethodFingerprint( Opcode.CONST, Opcode.INVOKE_VIRTUAL, Opcode.IGET_OBJECT, - ), - customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("SubtitleButtonController;") - } + ) ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/fingerprints/LayoutConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/fingerprints/LayoutConstructorFingerprint.kt deleted file mode 100644 index 92d33ce3..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/fingerprints/LayoutConstructorFingerprint.kt +++ /dev/null @@ -1,10 +0,0 @@ -package app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint - -object LayoutConstructorFingerprint : MethodFingerprint( - strings = listOf("1.0x"), - customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("YouTubeControlsOverlay;") - } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/patch/HideAutoplayButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/patch/HideAutoplayButtonPatch.kt index 9f2c2f2d..f60021dc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/patch/HideAutoplayButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/autoplay/patch/HideAutoplayButtonPatch.kt @@ -17,7 +17,7 @@ import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.youtube.layout.buttons.autoplay.annotations.AutoplayButtonCompatibility -import app.revanced.patches.youtube.layout.buttons.autoplay.fingerprints.LayoutConstructorFingerprint +import app.revanced.patches.shared.fingerprints.LayoutConstructorFingerprint import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import com.android.tools.smali.dexlib2.iface.instruction.Instruction diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/patch/HideCaptionsButtonPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/patch/HideCaptionsButtonPatch.kt index d6817e29..34940dd2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/patch/HideCaptionsButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/captions/patch/HideCaptionsButtonPatch.kt @@ -38,12 +38,12 @@ class HideCaptionsButtonPatch : BytecodePatch(listOf( val subtitleButtonControllerMethod = SubtitleButtonControllerFingerprint.result!!.mutableMethod // Due to previously applied patches, scanResult index cannot be used in this context - val igetBooleanIndex = subtitleButtonControllerMethod.implementation!!.instructions.indexOfFirst { + val insertIndex = subtitleButtonControllerMethod.implementation!!.instructions.indexOfFirst { it.opcode == Opcode.IGET_BOOLEAN - } + } + 1 subtitleButtonControllerMethod.addInstruction( - igetBooleanIndex + 1, + insertIndex, """ invoke-static {v0}, Lapp/revanced/integrations/patches/HideCaptionsButtonPatch;->hideCaptionsButton(Landroid/widget/ImageView;)V """ diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/bytecode/fingerprints/HideLoadMoreButtonFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/bytecode/fingerprints/HideLoadMoreButtonFingerprint.kt index 6ba8b0ab..258ba7d9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/bytecode/fingerprints/HideLoadMoreButtonFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/loadmorebutton/bytecode/fingerprints/HideLoadMoreButtonFingerprint.kt @@ -1,15 +1,10 @@ package app.revanced.patches.youtube.layout.hide.loadmorebutton.bytecode.fingerprints -import app.revanced.patcher.extensions.or -import app.revanced.util.patch.LiteralValueFingerprint import app.revanced.patches.youtube.layout.hide.loadmorebutton.resource.patch.HideLoadMoreButtonResourcePatch -import com.android.tools.smali.dexlib2.AccessFlags +import app.revanced.util.patch.LiteralValueFingerprint import com.android.tools.smali.dexlib2.Opcode object HideLoadMoreButtonFingerprint : LiteralValueFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, - parameters = listOf("L", "L", "L", "L"), opcodes = listOf( Opcode.CONST, Opcode.CONST_4, diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt index 5b25eb70..785577ea 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/player/overlay/bytecode/fingerprints/CreatePlayerOverviewFingerprint.kt @@ -17,7 +17,6 @@ object CreatePlayerOverviewFingerprint : MethodFingerprint( Opcode.CHECK_CAST ), customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("YouTubeControlsOverlay;") - && methodDef.containsConstantInstructionValue(HidePlayerOverlayResourcePatch.scrimOverlayId) + methodDef.containsConstantInstructionValue(HidePlayerOverlayResourcePatch.scrimOverlayId) } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/fingerprints/TimeCounterFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/fingerprints/TimeCounterFingerprint.kt index 32712b92..cfc85b69 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/fingerprints/TimeCounterFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/fingerprints/TimeCounterFingerprint.kt @@ -1,28 +1,24 @@ package app.revanced.patches.youtube.layout.hide.time.fingerprints import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode +@FuzzyPatternScanMethod(1) object TimeCounterFingerprint : MethodFingerprint( - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf(), - returnType = "V", - opcodes = listOf( - Opcode.SUB_LONG_2ADDR, - Opcode.INVOKE_STATIC, - Opcode.MOVE_RESULT_OBJECT, + "V", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf(), listOf( Opcode.IGET_OBJECT, Opcode.IGET_WIDE, - Opcode.INVOKE_STATIC, - Opcode.MOVE_RESULT_OBJECT, - Opcode.INVOKE_INTERFACE, - Opcode.RETURN_VOID, - ), - customFingerprint = { _, classDef -> - // On older devices this fingerprint resolves very slowly. - // Speed this up by checking for the number of methods. - classDef.methods.count() == 14 - } + Opcode.CONST_WIDE_16, + Opcode.CMP_LONG, + Opcode.IF_LEZ, + Opcode.IGET_OBJECT, + Opcode.IF_EQZ, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + Opcode.GOTO, + ) ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/annotations/FullscreenPanelsCompatibility.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/annotations/FullscreenPanelsCompatibility.kt deleted file mode 100644 index 11dbf884..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/annotations/FullscreenPanelsCompatibility.kt +++ /dev/null @@ -1,8 +0,0 @@ -package app.revanced.patches.youtube.layout.panels.fullscreen.remove.annotations - -import app.revanced.patcher.annotation.Compatibility -import app.revanced.patcher.annotation.Package - -@Compatibility([Package("com.google.android.youtube", arrayOf("18.16.37", "18.19.35", "18.20.39", "18.23.35"))]) -@Target(AnnotationTarget.CLASS) -internal annotation class FullscreenPanelsCompatibility diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/fingerprints/FullscreenViewAdderFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/fingerprints/FullscreenViewAdderFingerprint.kt index 52190273..e69de29b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/fingerprints/FullscreenViewAdderFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/fingerprints/FullscreenViewAdderFingerprint.kt @@ -1,11 +0,0 @@ -package app.revanced.patches.youtube.layout.panels.fullscreen.remove.fingerprints - - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import com.android.tools.smali.dexlib2.Opcode - -object FullscreenViewAdderFingerprint : MethodFingerprint( - opcodes = listOf( - Opcode.IGET_BOOLEAN - ) -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/fingerprints/FullscreenViewAdderParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/fingerprints/FullscreenViewAdderParentFingerprint.kt index a7b2565b..e69de29b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/fingerprints/FullscreenViewAdderParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/fingerprints/FullscreenViewAdderParentFingerprint.kt @@ -1,20 +0,0 @@ -package app.revanced.patches.youtube.layout.panels.fullscreen.remove.fingerprints - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import com.android.tools.smali.dexlib2.Opcode - -object FullscreenViewAdderParentFingerprint : MethodFingerprint( - returnType = "V", - parameters = listOf("Landroid/content/Context;", "Landroid/view/View;"), - opcodes = listOf( - Opcode.GOTO, - Opcode.IGET_BOOLEAN, - Opcode.IF_EQ, - Opcode.GOTO, - Opcode.CONST_4, - Opcode.INVOKE_VIRTUAL, - ), - customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("FullscreenEngagementPanelOverlay;") - } -) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/patch/FullscreenPanelsRemoverPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/patch/FullscreenPanelsRemoverPatch.kt deleted file mode 100644 index ab36bb88..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/panels/fullscreen/remove/patch/FullscreenPanelsRemoverPatch.kt +++ /dev/null @@ -1,63 +0,0 @@ -package app.revanced.patches.youtube.layout.panels.fullscreen.remove.patch - -import app.revanced.patcher.annotation.Description -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructions -import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction -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.PatchResultError -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.settings.preference.impl.StringResource -import app.revanced.patches.shared.settings.preference.impl.SwitchPreference -import app.revanced.patches.youtube.layout.panels.fullscreen.remove.annotations.FullscreenPanelsCompatibility -import app.revanced.patches.youtube.layout.panels.fullscreen.remove.fingerprints.FullscreenViewAdderFingerprint -import app.revanced.patches.youtube.layout.panels.fullscreen.remove.fingerprints.FullscreenViewAdderParentFingerprint -import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch -import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch - -@Patch -@Name("Disable fullscreen panels") -@DependsOn([IntegrationsPatch::class, SettingsPatch::class]) -@Description("Disables video description and comments panel in fullscreen view.") -@FullscreenPanelsCompatibility -class FullscreenPanelsRemoverPatch : BytecodePatch( - listOf( - FullscreenViewAdderParentFingerprint - ) -) { - override fun execute(context: BytecodeContext): PatchResult { - SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( - SwitchPreference( - "revanced_hide_fullscreen_panels", - StringResource("revanced_hide_fullscreen_panels_title", "Hide fullscreen panels"), - StringResource("revanced_hide_fullscreen_panels_summary_on", "Fullscreen panels are hidden"), - StringResource("revanced_hide_fullscreen_panels_summary_off", "Fullscreen panels are shown") - ) - ) - - val parentResult = FullscreenViewAdderParentFingerprint.result!! - FullscreenViewAdderFingerprint.resolve(context, parentResult.method, parentResult.classDef) - val result = FullscreenViewAdderParentFingerprint.result - ?: return PatchResultError("Fingerprint not resolved!") - - val method = result.mutableMethod - - val ifIndex = result.scanResult.patternScanResult!!.startIndex + 2 - - method.removeInstruction(ifIndex) - method.addInstructions( - ifIndex, - """ - invoke-static {}, Lapp/revanced/integrations/patches/FullscreenPanelsRemoverPatch;->getFullscreenPanelsVisibility()I - move-result p1 - """ - ) - - return PatchResultSuccess() - } -} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/ShortsTextViewFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/ShortsTextViewFingerprint.kt index 283c8fb9..1009acbd 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/ShortsTextViewFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/ShortsTextViewFingerprint.kt @@ -1,12 +1,12 @@ package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints -import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode object ShortsTextViewFingerprint : MethodFingerprint( - accessFlags = AccessFlags.PROTECTED or AccessFlags.FINAL, + // 18.29.38 method is public final visibility, but in 18.23.35 and older it's protected final. + // If 18.23.35 is dropped then accessFlags should be specified here. returnType = "V", parameters = listOf("L", "L"), opcodes = listOf( diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentAtomicReferenceFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentAtomicReferenceFingerprint.kt index a1b0858d..0879f52c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentAtomicReferenceFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentAtomicReferenceFingerprint.kt @@ -15,7 +15,7 @@ object TextComponentAtomicReferenceFingerprint : MethodFingerprint( opcodes = listOf( Opcode.MOVE_OBJECT_FROM16, // available unused register Opcode.MOVE_OBJECT_FROM16, - Opcode.MOVE_OBJECT_FROM16, + null, // move-object/from16 or move/from16 Opcode.MOVE_OBJECT_FROM16, Opcode.INVOKE_VIRTUAL, // CharSequence atomic reference Opcode.MOVE_RESULT_OBJECT, diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/ControlsOverlayFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/ControlsOverlayFingerprint.kt index afd72b40..934386bc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/ControlsOverlayFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/fingerprints/ControlsOverlayFingerprint.kt @@ -19,9 +19,6 @@ object ControlsOverlayFingerprint : MethodFingerprint( Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT, Opcode.CHECK_CAST, - Opcode.NEW_INSTANCE, - ), - customFingerprint = { methodDef, _ -> - methodDef.definingClass == "Lcom/google/android/apps/youtube/app/player/overlay/YouTubeControlsOverlay;" - } + Opcode.NEW_INSTANCE + ) ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt index 963a7008..4f00ba5b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/bytecode/patch/SponsorBlockBytecodePatch.kt @@ -17,6 +17,7 @@ import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.shared.fingerprints.LayoutConstructorFingerprint import app.revanced.patches.shared.fingerprints.SeekbarFingerprint import app.revanced.patches.shared.fingerprints.SeekbarOnDrawFingerprint import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch @@ -59,23 +60,16 @@ class SponsorBlockBytecodePatch : BytecodePatch( listOf( SeekbarFingerprint, AppendTimeFingerprint, - ControlsOverlayFingerprint, + LayoutConstructorFingerprint, AutoRepeatParentFingerprint, ) ) { - - private companion object { - const val INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR = - "Lapp/revanced/integrations/sponsorblock/SegmentPlaybackController;" - const val INTEGRATIONS_CREATE_SEGMENT_BUTTON_CONTROLLER_CLASS_DESCRIPTOR = - "Lapp/revanced/integrations/sponsorblock/ui/CreateSegmentButtonController;" - const val INTEGRATIONS_VOTING_BUTTON_CONTROLLER_CLASS_DESCRIPTOR = - "Lapp/revanced/integrations/sponsorblock/ui/VotingButtonController;" - const val INTEGRATIONS_SPONSORBLOCK_VIEW_CONTROLLER_CLASS_DESCRIPTOR = - "Lapp/revanced/integrations/sponsorblock/ui/SponsorBlockViewController;" - } - override fun execute(context: BytecodeContext): PatchResult { + LayoutConstructorFingerprint.result?.let { + if (!ControlsOverlayFingerprint.resolve(context, it.classDef)) + throw ControlsOverlayFingerprint.toErrorResult() + } ?: return LayoutConstructorFingerprint.toErrorResult() + /* * Hook the video time methods */ @@ -279,4 +273,15 @@ class SponsorBlockBytecodePatch : BytecodePatch( return PatchResultSuccess() } + + private companion object { + const val INTEGRATIONS_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/sponsorblock/SegmentPlaybackController;" + const val INTEGRATIONS_CREATE_SEGMENT_BUTTON_CONTROLLER_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/sponsorblock/ui/CreateSegmentButtonController;" + const val INTEGRATIONS_VOTING_BUTTON_CONTROLLER_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/sponsorblock/ui/VotingButtonController;" + const val INTEGRATIONS_SPONSORBLOCK_VIEW_CONTROLLER_CLASS_DESCRIPTOR = + "Lapp/revanced/integrations/sponsorblock/ui/SponsorBlockViewController;" + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideFingerprint.kt index ded121ec..73f59350 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideFingerprint.kt @@ -3,21 +3,10 @@ package app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode object MiniPlayerOverrideFingerprint : MethodFingerprint( - "Z", AccessFlags.STATIC or AccessFlags.PUBLIC, - listOf("Landroid/content/Context;"), - opcodes = listOf( - Opcode.INVOKE_STATIC, - Opcode.MOVE_RESULT, - Opcode.CONST_4, - Opcode.IF_EQ, - Opcode.CONST_4, - Opcode.IF_EQ, - Opcode.CONST_4, // override this value - Opcode.RETURN, - Opcode.CONST_4, // override this value - Opcode.RETURN - ), + returnType = "L", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L"), + strings = listOf("appName") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideParentFingerprint.kt deleted file mode 100644 index df535223..00000000 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/fingerprints/MiniPlayerOverrideParentFingerprint.kt +++ /dev/null @@ -1,7 +0,0 @@ -package app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints - -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint - -object MiniPlayerOverrideParentFingerprint : MethodFingerprint( - strings = listOf("Unset or unknown Input OneOf case for dynamic input") -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/patch/TabletMiniPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/patch/TabletMiniPlayerPatch.kt index b7961a69..22d5c122 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/patch/TabletMiniPlayerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/tabletminiplayer/patch/TabletMiniPlayerPatch.kt @@ -4,6 +4,7 @@ import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.data.toMethodWalker import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve @@ -17,7 +18,10 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference import app.revanced.patches.youtube.layout.tabletminiplayer.annotations.TabletMiniPlayerCompatibility -import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.* +import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerDimensionsCalculatorParentFingerprint +import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerOverrideFingerprint +import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerOverrideNoContextFingerprint +import app.revanced.patches.youtube.layout.tabletminiplayer.fingerprints.MiniPlayerResponseModelSizeCheckFingerprint import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import com.android.tools.smali.dexlib2.Opcode @@ -32,7 +36,7 @@ class TabletMiniPlayerPatch : BytecodePatch( listOf( MiniPlayerDimensionsCalculatorParentFingerprint, MiniPlayerResponseModelSizeCheckFingerprint, - MiniPlayerOverrideParentFingerprint + MiniPlayerOverrideFingerprint ) ) { override fun execute(context: BytecodeContext): PatchResult { @@ -62,33 +66,33 @@ class TabletMiniPlayerPatch : BytecodePatch( /** same register used to return **/ ) - /* - * Method with context parameter. - */ - MiniPlayerOverrideParentFingerprint.result?.let { - if (!MiniPlayerOverrideFingerprint.resolve(context, it.classDef)) - throw MiniPlayerOverrideFingerprint.toErrorResult() - } ?: return MiniPlayerOverrideParentFingerprint.toErrorResult() - /* * Override every return instruction with the proxy call. */ - MiniPlayerOverrideFingerprint.result!!.mutableMethod.apply { - implementation!!.let { implementation -> - val returnIndices = implementation.instructions - .withIndex() - .filter { (_, instruction) -> instruction.opcode == Opcode.RETURN } - .map { (index, _) -> index } + MiniPlayerOverrideFingerprint.result?.let { result -> + result.mutableMethod.let { method -> + val appNameStringIndex = result.scanResult.stringsScanResult!!.matches.first().index + 2 + context.toMethodWalker(method).nextMethod(appNameStringIndex, true) + .getMethod() as MutableMethod + }.apply { + implementation!!.let { implementation -> + val returnIndices = implementation.instructions + .withIndex() + .filter { (_, instruction) -> instruction.opcode == Opcode.RETURN } + .map { (index, _) -> index } - if (returnIndices.isEmpty()) throw PatchResultError("No return instructions found.") + if (returnIndices.isEmpty()) throw PatchResultError("No return instructions found.") - // This method clobbers register p0 to return the value, calculate to override. - val returnedRegister = implementation.registerCount - parameters.size + // This method clobbers register p0 to return the value, calculate to override. + val returnedRegister = implementation.registerCount - parameters.size - // Hook the returned register on every return instruction. - returnIndices.forEach { index -> insertOverride(index, returnedRegister) } + // Hook the returned register on every return instruction. + returnIndices.forEach { index -> insertOverride(index, returnedRegister) } + } } - } + + return@let + } ?: return MiniPlayerOverrideFingerprint.toErrorResult() /* * Size check return value override. diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt index 0b889561..1a24e194 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/minimizedplayback/fingerprints/KidsMinimizedPlaybackPolicyControllerFingerprint.kt @@ -4,22 +4,31 @@ import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction object KidsMinimizedPlaybackPolicyControllerFingerprint : MethodFingerprint( returnType = "V", accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf("I", "L", "L"), + parameters = listOf("I", "L", "L"), opcodes = listOf( - Opcode.IF_EQZ, + Opcode.CONST_4, + Opcode.IF_NE, Opcode.SGET_OBJECT, Opcode.IF_NE, - Opcode.CONST_4, - Opcode.IPUT_BOOLEAN, - Opcode.IF_EQZ, Opcode.IGET, - Opcode.INVOKE_STATIC + Opcode.CONST_4, + Opcode.IF_NE, + Opcode.IGET_OBJECT, + Opcode.SGET_OBJECT, + Opcode.IF_EQ, + Opcode.GOTO, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.RETURN_VOID ), customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("MinimizedPlaybackPolicyController;") + methodDef.implementation!!.instructions.any { + ((it as? NarrowLiteralInstruction)?.narrowLiteral == 5) + } } ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/bytecode/patch/PlayerControlsBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/bytecode/patch/PlayerControlsBytecodePatch.kt index 2fef90c1..41627635 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/bytecode/patch/PlayerControlsBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/bytecode/patch/PlayerControlsBytecodePatch.kt @@ -1,14 +1,17 @@ package app.revanced.patches.youtube.misc.playercontrols.bytecode.patch +import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult 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.patches.shared.fingerprints.LayoutConstructorFingerprint import app.revanced.patches.youtube.misc.playercontrols.annotation.PlayerControlsCompatibility import app.revanced.patches.youtube.misc.playercontrols.fingerprints.BottomControlsInflateFingerprint import app.revanced.patches.youtube.misc.playercontrols.fingerprints.PlayerControlsVisibilityFingerprint @@ -20,9 +23,17 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Description("Manages the code for the player controls of the YouTube player.") @PlayerControlsCompatibility class PlayerControlsBytecodePatch : BytecodePatch( - listOf(PlayerControlsVisibilityFingerprint, BottomControlsInflateFingerprint) + listOf( + LayoutConstructorFingerprint, + BottomControlsInflateFingerprint + ) ) { override fun execute(context: BytecodeContext): PatchResult { + LayoutConstructorFingerprint.result?.let { + if (!PlayerControlsVisibilityFingerprint.resolve(context, it.classDef)) + throw LayoutConstructorFingerprint.toErrorResult() + } ?: return LayoutConstructorFingerprint.toErrorResult() + showPlayerControlsFingerprintResult = PlayerControlsVisibilityFingerprint.result!! inflateFingerprintResult = BottomControlsInflateFingerprint.result!! diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/PlayerControlsVisibilityFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/PlayerControlsVisibilityFingerprint.kt index 3d9a2372..1f6951a0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/PlayerControlsVisibilityFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/fingerprints/PlayerControlsVisibilityFingerprint.kt @@ -7,8 +7,5 @@ import com.android.tools.smali.dexlib2.AccessFlags object PlayerControlsVisibilityFingerprint : MethodFingerprint( accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL, returnType = "V", - parameters = listOf("Z", "Z"), - customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("YouTubeControlsOverlay;") - } + parameters = listOf("Z", "Z") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/PlayerTypeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/PlayerTypeFingerprint.kt index 477b63d9..dc252f97 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/PlayerTypeFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/PlayerTypeFingerprint.kt @@ -10,26 +10,8 @@ object PlayerTypeFingerprint : MethodFingerprint( accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("L"), opcodes = listOf( - Opcode.INVOKE_VIRTUAL, - Opcode.IGET_OBJECT, Opcode.IF_NE, - Opcode.RETURN_VOID, - Opcode.IPUT_OBJECT, - Opcode.INVOKE_DIRECT, - Opcode.INVOKE_VIRTUAL, - Opcode.INVOKE_VIRTUAL, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT, - Opcode.IF_EQZ, - Opcode.CONST_4, - Opcode.INVOKE_STATIC, - Opcode.RETURN_VOID, - Opcode.CONST_4, - Opcode.INVOKE_STATIC, - Opcode.INVOKE_VIRTUAL, Opcode.RETURN_VOID ), - customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("YouTubePlayerOverlaysLayout;") - } + customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("/YouTubePlayerOverlaysLayout;") } ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/VideoStateFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/VideoStateFingerprint.kt index 5212f68a..1fb9e7f0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/VideoStateFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/fingerprint/VideoStateFingerprint.kt @@ -17,8 +17,5 @@ object VideoStateFingerprint : MethodFingerprint( Opcode.IF_EQZ, Opcode.IF_EQZ, Opcode.IGET_OBJECT, // obfuscated parameter field name - ), - customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("YouTubeControlsOverlay;") - } + ) ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/patch/PlayerTypeHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/patch/PlayerTypeHookPatch.kt index 82f578da..831482dc 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/patch/PlayerTypeHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/patch/PlayerTypeHookPatch.kt @@ -12,33 +12,27 @@ import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch -import app.revanced.patches.youtube.misc.playertype.annotation.PlayerTypeHookCompatibility import app.revanced.patches.youtube.misc.playertype.fingerprint.PlayerTypeFingerprint import app.revanced.patches.youtube.misc.playertype.fingerprint.VideoStateFingerprint import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @Name("Player type hook") @Description("Hook to get the current player type and video playback state.") -@PlayerTypeHookCompatibility @DependsOn([IntegrationsPatch::class]) class PlayerTypeHookPatch : BytecodePatch( listOf(PlayerTypeFingerprint, VideoStateFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - - PlayerTypeFingerprint.result?.let { - it.mutableMethod.apply { - addInstruction( - 0, - "invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->setPlayerType(Ljava/lang/Enum;)V" - ) - } - } ?: return PlayerTypeFingerprint.toErrorResult() + PlayerTypeFingerprint.result?.mutableMethod?.addInstruction( + 0, + "invoke-static {p1}, $INTEGRATIONS_CLASS_DESCRIPTOR->setPlayerType(Ljava/lang/Enum;)V" + ) ?: return PlayerTypeFingerprint.toErrorResult() VideoStateFingerprint.result?.let { it.mutableMethod.apply { val endIndex = it.scanResult.patternScanResult!!.endIndex val videoStateFieldName = getInstruction(endIndex).reference + addInstructions( 0, """ diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/videoid/fingerprint/VideoIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/video/videoid/fingerprint/VideoIdFingerprint.kt index ae8dfadc..dcb8df5c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/videoid/fingerprint/VideoIdFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/videoid/fingerprint/VideoIdFingerprint.kt @@ -10,6 +10,7 @@ object VideoIdFingerprint : MethodFingerprint( accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("L"), opcodes = listOf( + Opcode.MOVE_RESULT_OBJECT, Opcode.IF_EQZ, Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT_OBJECT, @@ -23,8 +24,5 @@ object VideoIdFingerprint : MethodFingerprint( Opcode.MOVE_RESULT_OBJECT, Opcode.INVOKE_INTERFACE, Opcode.MOVE_RESULT_OBJECT - ), - customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("SubtitlesOverlayPresenter;") - } + ) ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/videoid/fingerprint/VideoIdFingerprintBackgroundPlay.kt b/src/main/kotlin/app/revanced/patches/youtube/video/videoid/fingerprint/VideoIdFingerprintBackgroundPlay.kt index 1556a600..23de434c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/videoid/fingerprint/VideoIdFingerprintBackgroundPlay.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/videoid/fingerprint/VideoIdFingerprintBackgroundPlay.kt @@ -9,8 +9,21 @@ object VideoIdFingerprintBackgroundPlay : MethodFingerprint( returnType = "V", accessFlags = AccessFlags.DECLARED_SYNCHRONIZED or AccessFlags.FINAL or AccessFlags.PUBLIC, parameters = listOf("L"), - opcodes = listOf(Opcode.INVOKE_INTERFACE), - customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("PlaybackLifecycleMonitor;") - } + opcodes = listOf( + Opcode.MONITOR_EXIT, + Opcode.RETURN_VOID, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.NEW_ARRAY, + Opcode.SGET_OBJECT, + Opcode.APUT_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.IF_EQZ, + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT, + ), ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/videoid/patch/VideoIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/videoid/patch/VideoIdPatch.kt index 92ed1f39..6a178cb9 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/videoid/patch/VideoIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/videoid/patch/VideoIdPatch.kt @@ -6,6 +6,7 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess @@ -25,27 +26,33 @@ class VideoIdPatch : BytecodePatch( listOf(VideoIdFingerprint, VideoIdFingerprintBackgroundPlay) ) { override fun execute(context: BytecodeContext): PatchResult { - VideoIdFingerprint.result?.let { result -> - val videoIdRegisterInstructionIndex = result.scanResult.patternScanResult!!.endIndex + /** + * Supplies the method and register index of the video id register. + * + * @param consumer Consumer that receives the method, insert index and video id register index. + */ + fun MethodFingerprint.setFields(consumer: (MutableMethod, Int, Int) -> Unit) = result?.let { result -> + val videoIdRegisterIndex = result.scanResult.patternScanResult!!.endIndex + + result.mutableMethod.let { + val videoIdRegister = it.getInstruction(videoIdRegisterIndex).registerA + val insertIndex = videoIdRegisterIndex + 1 + consumer(it, insertIndex, videoIdRegister) - result.mutableMethod.also { - insertMethod = it - }.apply { - videoIdRegister = getInstruction(videoIdRegisterInstructionIndex).registerA - insertIndex = videoIdRegisterInstructionIndex + 1 } - } ?: return VideoIdFingerprint.toErrorResult() + } ?: throw VideoIdFingerprint.toErrorResult() - VideoIdFingerprintBackgroundPlay.result?.let { result -> - val endIndex = result.scanResult.patternScanResult!!.endIndex + VideoIdFingerprint.setFields { method, insertIndex, videoIdRegister -> + insertMethod = method + VideoIdPatch.insertIndex = insertIndex + VideoIdPatch.videoIdRegister = videoIdRegister + } - result.mutableMethod.also { - backgroundPlaybackMethod = it - }.apply { - backgroundPlaybackVideoIdRegister = getInstruction(endIndex + 1).registerA - backgroundPlaybackInsertIndex = endIndex + 2 - } - } ?: return VideoIdFingerprintBackgroundPlay.toErrorResult() + VideoIdFingerprintBackgroundPlay.setFields { method, insertIndex, videoIdRegister -> + backgroundPlaybackMethod = method + backgroundPlaybackInsertIndex = insertIndex + backgroundPlaybackVideoIdRegister = videoIdRegister + } return PatchResultSuccess() }