feat(youtube/return-youtube-dislike): support for shorts (#1596)
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de> Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
3278f5bc33
commit
967c1cbd4b
|
@ -0,0 +1,25 @@
|
||||||
|
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.or
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
|
import org.jf.dexlib2.AccessFlags
|
||||||
|
import org.jf.dexlib2.Opcode
|
||||||
|
|
||||||
|
object ShortsTextComponentParentFingerprint : MethodFingerprint(
|
||||||
|
returnType = "V",
|
||||||
|
access = AccessFlags.PROTECTED or AccessFlags.FINAL,
|
||||||
|
parameters = listOf("L", "L"),
|
||||||
|
opcodes = listOf(
|
||||||
|
Opcode.IF_EQZ,
|
||||||
|
Opcode.CONST_4,
|
||||||
|
Opcode.IF_EQ,
|
||||||
|
Opcode.CONST_4,
|
||||||
|
Opcode.IF_EQ,
|
||||||
|
Opcode.RETURN_VOID,
|
||||||
|
Opcode.IGET_OBJECT,
|
||||||
|
Opcode.CHECK_CAST,
|
||||||
|
Opcode.IGET_BOOLEAN,
|
||||||
|
Opcode.IF_EQZ,
|
||||||
|
Opcode.INVOKE_STATIC
|
||||||
|
)
|
||||||
|
)
|
|
@ -5,8 +5,10 @@ import app.revanced.patcher.annotation.Description
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
|
import app.revanced.patcher.data.toMethodWalker
|
||||||
import app.revanced.patcher.extensions.MethodFingerprintExtensions.name
|
import app.revanced.patcher.extensions.MethodFingerprintExtensions.name
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
|
import app.revanced.patcher.extensions.instruction
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
|
@ -15,12 +17,15 @@ import app.revanced.patcher.patch.PatchResultError
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patcher.patch.annotations.Patch
|
import app.revanced.patcher.patch.annotations.Patch
|
||||||
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
import app.revanced.patches.youtube.layout.returnyoutubedislike.annotations.ReturnYouTubeDislikeCompatibility
|
import app.revanced.patches.youtube.layout.returnyoutubedislike.annotations.ReturnYouTubeDislikeCompatibility
|
||||||
import app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints.*
|
import app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints.*
|
||||||
import app.revanced.patches.youtube.layout.returnyoutubedislike.resource.patch.ReturnYouTubeDislikeResourcePatch
|
import app.revanced.patches.youtube.layout.returnyoutubedislike.resource.patch.ReturnYouTubeDislikeResourcePatch
|
||||||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
|
||||||
import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch
|
import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch
|
||||||
import app.revanced.patches.youtube.misc.video.videoid.patch.VideoIdPatch
|
import app.revanced.patches.youtube.misc.video.videoid.patch.VideoIdPatch
|
||||||
|
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
|
||||||
|
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@DependsOn(
|
@DependsOn(
|
||||||
|
@ -38,55 +43,103 @@ import app.revanced.patches.youtube.misc.video.videoid.patch.VideoIdPatch
|
||||||
class ReturnYouTubeDislikePatch : BytecodePatch(
|
class ReturnYouTubeDislikePatch : BytecodePatch(
|
||||||
listOf(
|
listOf(
|
||||||
TextComponentSpecParentFingerprint,
|
TextComponentSpecParentFingerprint,
|
||||||
|
ShortsTextComponentParentFingerprint,
|
||||||
LikeFingerprint,
|
LikeFingerprint,
|
||||||
DislikeFingerprint,
|
DislikeFingerprint,
|
||||||
RemoveLikeFingerprint,
|
RemoveLikeFingerprint,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
|
// region Inject newVideoLoaded event handler
|
||||||
|
|
||||||
|
VideoIdPatch.injectCall("$INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V")
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Hook interaction
|
||||||
|
|
||||||
listOf(
|
listOf(
|
||||||
LikeFingerprint.toPatch(Vote.LIKE),
|
LikeFingerprint.toPatch(Vote.LIKE),
|
||||||
DislikeFingerprint.toPatch(Vote.DISLIKE),
|
DislikeFingerprint.toPatch(Vote.DISLIKE),
|
||||||
RemoveLikeFingerprint.toPatch(Vote.REMOVE_LIKE)
|
RemoveLikeFingerprint.toPatch(Vote.REMOVE_LIKE)
|
||||||
).forEach { (fingerprint, vote) ->
|
).forEach { (fingerprint, vote) ->
|
||||||
with(fingerprint.result ?: return PatchResultError("Failed to find ${fingerprint.name} method.")) {
|
fingerprint.result?.mutableMethod?.apply {
|
||||||
mutableMethod.addInstructions(
|
addInstructions(
|
||||||
0,
|
0,
|
||||||
"""
|
"""
|
||||||
const/4 v0, ${vote.value}
|
const/4 v0, ${vote.value}
|
||||||
invoke-static {v0}, Lapp/revanced/integrations/patches/ReturnYouTubeDislikePatch;->sendVote(I)V
|
invoke-static {v0}, $INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->sendVote(I)V
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
}
|
} ?: return PatchResultError("Failed to find ${fingerprint.name} method.")
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoIdPatch.injectCall("Lapp/revanced/integrations/patches/ReturnYouTubeDislikePatch;->newVideoLoaded(Ljava/lang/String;)V")
|
// endregion
|
||||||
|
|
||||||
with(TextComponentFingerprint
|
// region Hook components
|
||||||
.apply { resolve(context, TextComponentSpecParentFingerprint.result!!.classDef) }
|
|
||||||
.result ?: return TextComponentFingerprint.toErrorResult()
|
|
||||||
) {
|
|
||||||
val createComponentMethod = mutableMethod
|
|
||||||
|
|
||||||
val conversionContextParam = 5
|
TextComponentFingerprint.also { it.resolve(context, TextComponentSpecParentFingerprint.result!!.classDef) }
|
||||||
val textRefParam = createComponentMethod.parameters.size - 2
|
.result?.let {
|
||||||
// insert index must be 0, otherwise UI does not updated correctly in some situations
|
with(it.mutableMethod) {
|
||||||
// such as switching from full screen or when using previous/next overlay buttons.
|
val createComponentMethod = this
|
||||||
val insertIndex = 0
|
|
||||||
|
val conversionContextParam = 5
|
||||||
|
val textRefParam = createComponentMethod.parameters.size - 2
|
||||||
|
// Insert index must be 0, otherwise UI does not updated correctly in some situations
|
||||||
|
// such as switching from full screen or when using previous/next overlay buttons.
|
||||||
|
val insertIndex = 0
|
||||||
|
|
||||||
|
createComponentMethod.addInstructions(
|
||||||
|
insertIndex,
|
||||||
|
"""
|
||||||
|
move-object/from16 v7, p$conversionContextParam
|
||||||
|
move-object/from16 v8, p$textRefParam
|
||||||
|
invoke-static {v7, v8}, $INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->onComponentCreated(Ljava/lang/Object;Ljava/util/concurrent/atomic/AtomicReference;)V
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} ?: return TextComponentFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
ShortsTextComponentParentFingerprint.result?.let {
|
||||||
|
context
|
||||||
|
.toMethodWalker(it.method)
|
||||||
|
.nextMethod(it.scanResult.patternScanResult!!.endIndex, true)
|
||||||
|
.getMethod().let { method ->
|
||||||
|
with(method as MutableMethod) {
|
||||||
|
// After walking, verify the found method is what's expected.
|
||||||
|
if (returnType != ("Ljava/lang/CharSequence;") || parameterTypes.size != 1)
|
||||||
|
return PatchResultError("Method signature did not match: $this $parameterTypes")
|
||||||
|
|
||||||
|
val insertIndex = implementation!!.instructions.size - 1
|
||||||
|
|
||||||
|
val spannedParameterRegister = (instruction(insertIndex) as OneRegisterInstruction).registerA
|
||||||
|
val parameter = (instruction(insertIndex - 2) as BuilderInstruction35c).reference
|
||||||
|
|
||||||
|
if (!parameter.toString().endsWith("Landroid/text/Spanned;"))
|
||||||
|
return PatchResultError("Method signature parameter did not match: $parameter")
|
||||||
|
|
||||||
|
addInstructions(
|
||||||
|
insertIndex,
|
||||||
|
"""
|
||||||
|
invoke-static {v$spannedParameterRegister}, $INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->onShortsComponentCreated(Landroid/text/Spanned;)Landroid/text/Spanned;
|
||||||
|
move-result-object v$spannedParameterRegister
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ?: return ShortsTextComponentParentFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
createComponentMethod.addInstructions(
|
|
||||||
insertIndex,
|
|
||||||
"""
|
|
||||||
move-object/from16 v7, p$conversionContextParam
|
|
||||||
move-object/from16 v8, p$textRefParam
|
|
||||||
invoke-static {v7, v8}, Lapp/revanced/integrations/patches/ReturnYouTubeDislikePatch;->onComponentCreated(Ljava/lang/Object;Ljava/util/concurrent/atomic/AtomicReference;)V
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MethodFingerprint.toPatch(voteKind: Vote) = VotePatch(this, voteKind)
|
private companion object {
|
||||||
|
const val INTEGRATIONS_PATCH_CLASS_DESCRIPTOR =
|
||||||
|
"Lapp/revanced/integrations/patches/ReturnYouTubeDislikePatch;"
|
||||||
|
|
||||||
|
private fun MethodFingerprint.toPatch(voteKind: Vote) = VotePatch(this, voteKind)
|
||||||
|
}
|
||||||
|
|
||||||
private data class VotePatch(val fingerprint: MethodFingerprint, val voteKind: Vote)
|
private data class VotePatch(val fingerprint: MethodFingerprint, val voteKind: Vote)
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,31 @@
|
||||||
package app.revanced.patches.youtube.misc.video.videoid.fingerprint
|
package app.revanced.patches.youtube.misc.video.videoid.fingerprint
|
||||||
|
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
|
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import org.jf.dexlib2.AccessFlags
|
import org.jf.dexlib2.AccessFlags
|
||||||
import org.jf.dexlib2.Opcode
|
import org.jf.dexlib2.Opcode
|
||||||
|
|
||||||
|
@FuzzyPatternScanMethod(2)
|
||||||
object VideoIdFingerprint : MethodFingerprint(
|
object VideoIdFingerprint : MethodFingerprint(
|
||||||
"V",
|
returnType = "V",
|
||||||
AccessFlags.DECLARED_SYNCHRONIZED or AccessFlags.FINAL or AccessFlags.PUBLIC,
|
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||||
listOf("L"),
|
parameters = listOf("L"),
|
||||||
listOf(Opcode.INVOKE_INTERFACE),
|
opcodes = listOf(
|
||||||
customFingerprint = {
|
Opcode.IF_EQZ,
|
||||||
it.definingClass.endsWith("PlaybackLifecycleMonitor;")
|
Opcode.INVOKE_VIRTUAL,
|
||||||
}
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
Opcode.INVOKE_INTERFACE,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
Opcode.IF_EQZ,
|
||||||
|
Opcode.IGET_OBJECT,
|
||||||
|
Opcode.INVOKE_VIRTUAL,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
Opcode.INVOKE_INTERFACE,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
Opcode.INVOKE_INTERFACE,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT
|
||||||
|
),
|
||||||
|
null,
|
||||||
|
{ it.definingClass.endsWith("SubtitlesOverlayPresenter;") }
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package app.revanced.patches.youtube.misc.video.videoid.patch
|
package app.revanced.patches.youtube.misc.video.videoid.patch
|
||||||
|
|
||||||
|
import app.revanced.extensions.toErrorResult
|
||||||
import app.revanced.patcher.annotation.Description
|
import app.revanced.patcher.annotation.Description
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
|
@ -22,17 +23,18 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
@DependsOn([IntegrationsPatch::class])
|
@DependsOn([IntegrationsPatch::class])
|
||||||
class VideoIdPatch : BytecodePatch(
|
class VideoIdPatch : BytecodePatch(
|
||||||
listOf(
|
listOf(VideoIdFingerprint)
|
||||||
VideoIdFingerprint
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
with(VideoIdFingerprint.result!!) {
|
VideoIdFingerprint.result?.let {
|
||||||
insertMethod = mutableMethod
|
val videoIdRegisterInstructionIndex = it.scanResult.patternScanResult!!.endIndex
|
||||||
insertIndex = scanResult.patternScanResult!!.endIndex + 2
|
|
||||||
|
|
||||||
videoIdRegister = (insertMethod.instruction(insertIndex - 1) as OneRegisterInstruction).registerA
|
with(it.mutableMethod) {
|
||||||
}
|
insertMethod = this
|
||||||
|
videoIdRegister = (instruction(videoIdRegisterInstructionIndex) as OneRegisterInstruction).registerA
|
||||||
|
insertIndex = videoIdRegisterInstructionIndex + 1
|
||||||
|
}
|
||||||
|
} ?: return VideoIdFingerprint.toErrorResult()
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
@ -49,10 +51,15 @@ class VideoIdPatch : BytecodePatch(
|
||||||
*/
|
*/
|
||||||
fun injectCall(
|
fun injectCall(
|
||||||
methodDescriptor: String
|
methodDescriptor: String
|
||||||
) = insertMethod.addInstructions(
|
) {
|
||||||
insertIndex, // move-result-object offset
|
insertMethod.addInstructions(
|
||||||
"invoke-static {v$videoIdRegister}, $methodDescriptor"
|
// TODO: The order has been proven to not be required, so remove the logic for keeping order.
|
||||||
)
|
// Keep injection calls in the order they're added:
|
||||||
|
// Increment index. So if additional injection calls are added, those calls run after this injection call.
|
||||||
|
insertIndex++,
|
||||||
|
"invoke-static {v$videoIdRegister}, $methodDescriptor"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue