Skip to content

Commit

Permalink
fix(youtube/return-youtube-dislikes): fix temporarily frozen video af…
Browse files Browse the repository at this point in the history
…ter opening a shorts (ReVanced#2126)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
LisoUseInAIKyrios and oSumAtrIX committed May 14, 2023
1 parent c3f6bbe commit e0877e3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 64 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints

import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode

object ShortsTextViewFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("L", "L"),
opcodes = listOf(
Opcode.INVOKE_SUPER, // first instruction of method
Opcode.IF_NEZ,
Opcode.RETURN_VOID,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.CHECK_CAST,
Opcode.SGET_OBJECT, // insertion point, must be after constructor call to parent class
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.CONST_4,
Opcode.IF_EQZ,
Opcode.CONST_4,
Opcode.IF_EQ,
Opcode.CONST_4,
Opcode.IF_EQ,
Opcode.RETURN_VOID,
Opcode.IGET_OBJECT, // TextView field
Opcode.CHECK_CAST,
Opcode.IGET_BOOLEAN, // boolean field
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.MethodFingerprintExtensions.name
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.addInstructions
Expand All @@ -19,14 +18,12 @@ 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.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.layout.returnyoutubedislike.annotations.ReturnYouTubeDislikeCompatibility
import app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints.*
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.playertype.patch.PlayerTypeHookPatch
import app.revanced.patches.youtube.video.videoid.patch.VideoIdPatch
import org.jf.dexlib2.builder.instruction.BuilderInstruction35c
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
Expand All @@ -48,7 +45,7 @@ import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
class ReturnYouTubeDislikePatch : BytecodePatch(
listOf(
TextComponentConstructorFingerprint,
ShortsTextComponentParentFingerprint,
ShortsTextViewFingerprint,
DislikesOldLayoutTextViewFingerprint,
LikeFingerprint,
DislikeFingerprint,
Expand Down Expand Up @@ -137,35 +134,40 @@ class ReturnYouTubeDislikePatch : BytecodePatch(

// region Hook for Short videos.

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<OneRegisterInstruction>(insertIndex).registerA
val parameter = instruction<BuilderInstruction35c>(insertIndex - 2).reference

if (!parameter.toString().endsWith("Landroid/text/Spanned;"))
return PatchResultError("Method signature parameter did not match: $parameter")

insertShorts(insertIndex, spannedParameterRegister)
}
}

// Additional hook, called after user dislikes.
with(it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.startIndex + 2
val overwriteRegister = (implementation!!.instructions.elementAt(insertIndex - 1)
as OneRegisterInstruction).registerA
insertShorts(insertIndex, overwriteRegister)
ShortsTextViewFingerprint.result?.let {
it.mutableMethod.apply {
val patternResult = it.scanResult.patternScanResult!!

// If the field is true, the TextView is for a dislike button.
val isDisLikesBooleanReference = instruction<ReferenceInstruction>(patternResult.endIndex).reference

val textViewFieldReference = // Like/Dislike button TextView field
instruction<ReferenceInstruction>(patternResult.endIndex - 2).reference

// Check if the hooked TextView object is that of the dislike button.
// If RYD is disabled, or the TextView object is not that of the dislike button, the execution flow is not interrupted.
// Otherwise, the TextView object is modified, and the execution flow is interrupted to prevent it from being changed afterward.
val insertIndex = patternResult.startIndex + 6
addInstructions(
insertIndex, """
# Check, if the TextView is for a dislike button
iget-boolean v0, p0, $isDisLikesBooleanReference
if-eqz v0, :is_like
# Hook the TextView, if it is for the dislike button
iget-object v0, p0, $textViewFieldReference
invoke-static {v0}, $INTEGRATIONS_CLASS_DESCRIPTOR->setShortsDislikes(Landroid/view/View;)Z
move-result v0
if-eqz v0, :ryd_disabled
return-void
:is_like
:ryd_disabled
nop
"""
)
}
} ?: return ShortsTextComponentParentFingerprint.toErrorResult()
} ?: return ShortsTextViewFingerprint.toErrorResult()

// endregion

Expand Down Expand Up @@ -201,14 +203,5 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
DISLIKE(-1),
REMOVE_LIKE(0)
}

private fun MutableMethod.insertShorts(index: Int, register: Int) {
addInstructions(
index, """
invoke-static {v$register}, $INTEGRATIONS_CLASS_DESCRIPTOR->onShortsComponentCreated(Landroid/text/Spanned;)Landroid/text/Spanned;
move-result-object v$register
"""
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<string name="revanced_ryd_enable_summary_on">Dislikes are shown</string>
<string name="revanced_ryd_enable_summary_off">Dislikes are not shown</string>

<string name="revanced_ryd_shorts_title">Show dislikes on Shorts</string>
<string name="revanced_ryd_shorts_summary_on">Dislikes shown on Shorts</string>
<string name="revanced_ryd_shorts_summary_off">Dislikes hidden on Shorts</string>

<string name="revanced_ryd_dislike_percentage_title">Dislikes as percentage</string>
<string name="revanced_ryd_dislike_percentage_summary_on">Dislikes shown as percentage</string>
<string name="revanced_ryd_dislike_percentage_summary_off">Dislikes shown as number</string>
Expand Down

0 comments on commit e0877e3

Please sign in to comment.