feat(YouTube): replace with a fingerprint that supports a wider range of versions

This commit is contained in:
inotia00
2024-10-06 18:41:52 +09:00
parent 12127d6f25
commit 41e00d6a4f
13 changed files with 173 additions and 43 deletions

View File

@ -50,6 +50,7 @@ import app.revanced.patches.youtube.video.information.VideoInformationPatch
import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.findMethodOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow
@ -147,13 +148,15 @@ object PlayerComponentsPatch : BaseBytecodePatch(
hookInitVideoPanel(1)
} else {
val syntheticIndex =
indexOfFirstInstructionOrThrow(Opcode.NEW_INSTANCE)
val syntheticReference =
getInstruction<ReferenceInstruction>(syntheticIndex).reference.toString()
indexOfFirstInstruction(0, Opcode.NEW_INSTANCE)
if (syntheticIndex >= 0) {
val syntheticReference =
getInstruction<ReferenceInstruction>(syntheticIndex).reference.toString()
context.findMethodOrThrow(syntheticReference) {
name == "onClick"
}.hookInitVideoPanel(0)
context.findMethodOrThrow(syntheticReference) {
name == "onClick"
}.hookInitVideoPanel(0)
}
}
}
}

View File

@ -25,7 +25,7 @@ internal object BuildBrowseRequestFingerprint : MethodFingerprint(
fun indexOfRequestFinishedListenerInstruction(methodDef: Method) =
methodDef.indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>().toString() == "Lorg/chromium/net/ExperimentalUrlRequest${'$'}Builder;->setRequestFinishedListener(Lorg/chromium/net/RequestFinishedInfo${'$'}Listener;)Lorg/chromium/net/ExperimentalUrlRequest${'$'}Builder;"
getReference<MethodReference>()?.name == "setRequestFinishedListener"
}
fun indexOfNewUrlRequestBuilderInstruction(methodDef: Method) =

View File

@ -6,20 +6,28 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.youtube.utils.fix.suggestedvideoendscreen.fingerprints.AutoNavConstructorFingerprint
import app.revanced.patches.youtube.utils.fix.suggestedvideoendscreen.fingerprints.AutoNavStatusFingerprint
import app.revanced.patches.youtube.utils.fix.suggestedvideoendscreen.fingerprints.RemoveOnLayoutChangeListenerFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.PLAYER_CLASS_DESCRIPTOR
import app.revanced.util.alsoResolve
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
@Patch(
description = "Fixes an issue where the suggested video end screen is always visible regardless of whether autoplay is set or not."
)
object SuggestedVideoEndScreenPatch : BytecodePatch(
setOf(RemoveOnLayoutChangeListenerFingerprint)
setOf(
AutoNavConstructorFingerprint,
RemoveOnLayoutChangeListenerFingerprint
)
) {
override fun execute(context: BytecodeContext) {
@ -36,15 +44,23 @@ object SuggestedVideoEndScreenPatch : BytecodePatch(
it.getWalkerMethod(context, it.scanResult.patternScanResult!!.endIndex)
walkerIndex.apply {
val invokeInterfaceIndex =
indexOfFirstInstructionOrThrow(opcode = Opcode.INVOKE_INTERFACE)
val autoNavStatusMethodName = AutoNavStatusFingerprint.alsoResolve(
context, AutoNavConstructorFingerprint
).mutableMethod.name
val invokeIndex =
indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
reference?.returnType == "Z" &&
reference.parameterTypes.size == 0 &&
reference.name == autoNavStatusMethodName
}
val iGetObjectIndex =
indexOfFirstInstructionReversedOrThrow(invokeInterfaceIndex, Opcode.IGET_OBJECT)
indexOfFirstInstructionReversedOrThrow(invokeIndex, Opcode.IGET_OBJECT)
val invokeInterfaceReference =
getInstruction<ReferenceInstruction>(invokeInterfaceIndex).reference
val invokeReference = getInstruction<ReferenceInstruction>(invokeIndex).reference
val iGetObjectReference =
getInstruction<ReferenceInstruction>(iGetObjectIndex).reference
val opcodeName = getInstruction(invokeIndex).opcode.name
addInstructionsWithLabels(
0,
@ -56,7 +72,7 @@ object SuggestedVideoEndScreenPatch : BytecodePatch(
iget-object v0, p0, $iGetObjectReference
# This reference checks whether autoplay is turned on.
invoke-interface {v0}, $invokeInterfaceReference
$opcodeName {v0}, $invokeReference
move-result v0
# Hide suggested video end screen only when autoplay is turned off.

View File

@ -0,0 +1,11 @@
package app.revanced.patches.youtube.utils.fix.suggestedvideoendscreen.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
internal object AutoNavConstructorFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
strings = listOf("main_app_autonav"),
)

View File

@ -0,0 +1,11 @@
package app.revanced.patches.youtube.utils.fix.suggestedvideoendscreen.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
internal object AutoNavStatusFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
returnType = "Z",
parameters = emptyList()
)

View File

@ -7,7 +7,6 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.youtube.utils.fingerprints.YouTubeControlsOverlayFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.SHARED_PATH
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH
import app.revanced.patches.youtube.utils.playertype.fingerprint.ActionBarSearchResultsFingerprint
@ -18,7 +17,6 @@ import app.revanced.patches.youtube.utils.playertype.fingerprint.VideoStateFinge
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelWatchPlayer
import app.revanced.util.addStaticFieldToIntegration
import app.revanced.util.alsoResolve
import app.revanced.util.findMethodOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
@ -38,7 +36,7 @@ object PlayerTypeHookPatch : BytecodePatch(
BrowseIdClassFingerprint,
PlayerTypeFingerprint,
ReelWatchPagerFingerprint,
YouTubeControlsOverlayFingerprint
VideoStateFingerprint,
)
) {
private const val INTEGRATIONS_PLAYER_TYPE_HOOK_CLASS_DESCRIPTOR =
@ -79,11 +77,9 @@ object PlayerTypeHookPatch : BytecodePatch(
// region patch for set video state
VideoStateFingerprint.alsoResolve(
context, YouTubeControlsOverlayFingerprint
).let {
VideoStateFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val endIndex = it.scanResult.patternScanResult!!.endIndex
val endIndex = it.scanResult.patternScanResult!!.startIndex + 1
val videoStateFieldName =
getInstruction<ReferenceInstruction>(endIndex).reference

View File

@ -6,22 +6,22 @@ import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal object VideoStateFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("Lcom/google/android/libraries/youtube/player/features/overlay/controls/ControlsState;"),
opcodes = listOf(
Opcode.CONST_4,
Opcode.IF_EQZ,
Opcode.IF_EQZ,
Opcode.IGET_OBJECT, // obfuscated parameter field name
Opcode.IGET_OBJECT,
Opcode.IF_NE,
),
customFingerprint = { methodDef, _ ->
methodDef.indexOfFirstInstruction {
opcode == Opcode.IGET_OBJECT &&
getReference<FieldReference>()?.definingClass == methodDef.parameterTypes.firstOrNull()
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "equals"
} >= 0
}
},
)

View File

@ -2,7 +2,9 @@ package app.revanced.patches.youtube.video.information
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
@ -38,6 +40,7 @@ import app.revanced.patches.youtube.video.playerresponse.PlayerResponseMethodHoo
import app.revanced.patches.youtube.video.videoid.VideoIdPatch
import app.revanced.util.addStaticFieldToIntegration
import app.revanced.util.alsoResolve
import app.revanced.util.cloneMutable
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
@ -119,6 +122,7 @@ object VideoInformationPatch : BytecodePatch(
private var seekSourceEnumType = ""
private var seekSourceMethodName = ""
private var seekRelativeSourceMethodName = ""
private var cloneSeekRelativeSourceMethod = false
private lateinit var context: BytecodeContext
@ -135,6 +139,32 @@ object VideoInformationPatch : BytecodePatch(
internal lateinit var speedSelectionInsertMethod: MutableMethod
internal lateinit var videoEndMethod: MutableMethod
private fun cloneSeekRelativeSourceMethod(fingerprintResult: MethodFingerprintResult) {
if (!cloneSeekRelativeSourceMethod) return
val methods = fingerprintResult.mutableClass.methods
methods.find { method ->
method.name == seekRelativeSourceMethodName
}?.apply {
methods.add(
cloneMutable(
returnType = "Z"
).apply {
val lastIndex = implementation!!.instructions.lastIndex
removeInstruction(lastIndex)
addInstructions(
lastIndex, """
move-result p1
return p1
"""
)
}
)
}
}
private fun addSeekInterfaceMethods(
result: MethodFingerprintResult,
seekMethodName: String,
@ -203,12 +233,16 @@ object VideoInformationPatch : BytecodePatch(
// hook the player controller for use through integrations
onCreateHook(INTEGRATIONS_CLASS_DESCRIPTOR, "initialize")
seekSourceEnumType = parameterTypes[1].toString()
seekSourceMethodName = name
seekRelativeSourceMethodName = SeekRelativeFingerprint.alsoResolve(
val seekRelativeMethod = SeekRelativeFingerprint.alsoResolve(
context,
VideoEndFingerprint
).mutableMethod.name
).mutableMethod
seekSourceEnumType = parameterTypes[1].toString()
seekSourceMethodName = name
seekRelativeSourceMethodName = seekRelativeMethod.name
cloneSeekRelativeSourceMethod = seekRelativeMethod.returnType == "V"
cloneSeekRelativeSourceMethod(it)
// Create integrations interface methods.
addSeekInterfaceMethods(
@ -250,6 +284,8 @@ object VideoInformationPatch : BytecodePatch(
// hook the MDX director for use through integrations
onCreateHookMdx(INTEGRATIONS_CLASS_DESCRIPTOR, "initializeMdx")
cloneSeekRelativeSourceMethod(it)
// Create integrations interface methods.
addSeekInterfaceMethods(
it,

View File

@ -11,12 +11,11 @@ import com.android.tools.smali.dexlib2.Opcode
*/
internal object SeekRelativeFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
returnType = "Z",
// returnType = "Z", ~ YouTube 19.39.39
// returnType = "V", YouTube 19.40.xx ~
parameters = listOf("J", "L"),
opcodes = listOf(
Opcode.ADD_LONG_2ADDR,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.RETURN
)
)