Skip to content

Commit

Permalink
feat(YouTube): Support version 18.29.38
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Aug 23, 2023
1 parent 134e66a commit c1b9eef
Show file tree
Hide file tree
Showing 32 changed files with 217 additions and 337 deletions.
Original file line number Diff line number Diff line change
@@ -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")
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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" }
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,39 @@ 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])
@Name("Seekbar tapping")
@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<ReferenceInstruction>(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
Expand All @@ -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,
Expand All @@ -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))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@ object SubtitleButtonControllerFingerprint : MethodFingerprint(
Opcode.CONST,
Opcode.INVOKE_VIRTUAL,
Opcode.IGET_OBJECT,
),
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("SubtitleButtonController;")
}
)
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ object CreatePlayerOverviewFingerprint : MethodFingerprint(
Opcode.CHECK_CAST
),
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("YouTubeControlsOverlay;")
&& methodDef.containsConstantInstructionValue(HidePlayerOverlayResourcePatch.scrimOverlayId)
methodDef.containsConstantInstructionValue(HidePlayerOverlayResourcePatch.scrimOverlayId)
}
)
Original file line number Diff line number Diff line change
@@ -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,
)
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
)
)
Original file line number Diff line number Diff line change
@@ -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;")
}
)
Loading

0 comments on commit c1b9eef

Please sign in to comment.