mirror of
https://github.com/revanced/revanced-patches
synced 2024-12-05 03:13:00 +01:00
fix(youtube/return-youtube-dislike): render dislikes when scrolling into the screen (#1873)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
7d30541781
commit
85675b8000
@ -10,11 +10,12 @@ object ShortsTextComponentParentFingerprint : MethodFingerprint(
|
|||||||
access = AccessFlags.PROTECTED or AccessFlags.FINAL,
|
access = AccessFlags.PROTECTED or AccessFlags.FINAL,
|
||||||
parameters = listOf("L", "L"),
|
parameters = listOf("L", "L"),
|
||||||
opcodes = listOf(
|
opcodes = listOf(
|
||||||
Opcode.IF_EQZ,
|
Opcode.INVOKE_STATIC,
|
||||||
Opcode.CONST_4,
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
Opcode.IF_EQ,
|
Opcode.GOTO,
|
||||||
Opcode.CONST_4,
|
Opcode.INVOKE_STATIC,
|
||||||
Opcode.IF_EQ,
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
Opcode.INVOKE_VIRTUAL,
|
||||||
Opcode.RETURN_VOID,
|
Opcode.RETURN_VOID,
|
||||||
Opcode.IGET_OBJECT,
|
Opcode.IGET_OBJECT,
|
||||||
Opcode.CHECK_CAST,
|
Opcode.CHECK_CAST,
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves against the same method that [TextComponentContextFingerprint] resolves to.
|
||||||
|
*/
|
||||||
|
object TextComponentAtomicReferenceFingerprint : MethodFingerprint(
|
||||||
|
returnType = "L",
|
||||||
|
access = AccessFlags.PROTECTED or AccessFlags.FINAL,
|
||||||
|
parameters = listOf("L"),
|
||||||
|
opcodes = listOf(
|
||||||
|
Opcode.MOVE_OBJECT, // available unused register
|
||||||
|
Opcode.MOVE_OBJECT_FROM16,
|
||||||
|
Opcode.MOVE_OBJECT_FROM16,
|
||||||
|
Opcode.MOVE_FROM16,
|
||||||
|
Opcode.INVOKE_VIRTUAL, // CharSequence atomic reference
|
||||||
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
Opcode.CHECK_CAST,
|
||||||
|
Opcode.MOVE_OBJECT, // CharSequence reference, and control flow label. Insert code here.
|
||||||
|
Opcode.INVOKE_VIRTUAL_RANGE,
|
||||||
|
Opcode.MOVE_RESULT,
|
||||||
|
Opcode.IF_EQZ,
|
||||||
|
Opcode.INVOKE_VIRTUAL_RANGE,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
Opcode.GOTO,
|
||||||
|
Opcode.CONST_4,
|
||||||
|
Opcode.INVOKE_VIRTUAL_RANGE,
|
||||||
|
Opcode.MOVE_RESULT_OBJECT,
|
||||||
|
)
|
||||||
|
)
|
@ -0,0 +1,24 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves against the same method that [TextComponentContextFingerprint] resolves to.
|
||||||
|
*/
|
||||||
|
object TextComponentContextFingerprint : MethodFingerprint(
|
||||||
|
returnType = "L",
|
||||||
|
access = AccessFlags.PROTECTED or AccessFlags.FINAL,
|
||||||
|
parameters = listOf("L"),
|
||||||
|
opcodes = listOf(
|
||||||
|
Opcode.IGET_OBJECT, // conversion context field name
|
||||||
|
Opcode.IGET_OBJECT,
|
||||||
|
Opcode.IGET_OBJECT,
|
||||||
|
Opcode.IGET_BOOLEAN,
|
||||||
|
Opcode.IGET,
|
||||||
|
Opcode.IGET,
|
||||||
|
Opcode.IGET,
|
||||||
|
)
|
||||||
|
)
|
@ -1,14 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
|
||||||
|
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import org.jf.dexlib2.Opcode
|
|
||||||
|
|
||||||
object TextReferenceFingerprint : MethodFingerprint(
|
|
||||||
opcodes = listOf(
|
|
||||||
Opcode.INVOKE_STATIC_RANGE,
|
|
||||||
Opcode.MOVE_RESULT_OBJECT,
|
|
||||||
Opcode.INVOKE_DIRECT,
|
|
||||||
Opcode.INVOKE_VIRTUAL
|
|
||||||
)
|
|
||||||
)
|
|
@ -1,11 +0,0 @@
|
|||||||
package app.revanced.patches.youtube.layout.returnyoutubedislike.fingerprints
|
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import org.jf.dexlib2.Opcode
|
|
||||||
|
|
||||||
object TextReferenceParamFingerprint : MethodFingerprint(
|
|
||||||
opcodes = listOf(
|
|
||||||
Opcode.MOVE_OBJECT,
|
|
||||||
Opcode.MOVE_OBJECT_FROM16 // the first occurrence of this instruction uses the register for the text object
|
|
||||||
)
|
|
||||||
)
|
|
@ -9,6 +9,7 @@ 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.extensions.instruction
|
||||||
|
import app.revanced.patcher.extensions.replaceInstruction
|
||||||
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
|
||||||
@ -25,8 +26,8 @@ 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.builder.instruction.BuilderInstruction35c
|
||||||
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
|
|
||||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
|
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@ -52,13 +53,13 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
|
|||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
// region Inject newVideoLoaded event handler
|
// region Inject newVideoLoaded event handler to update dislikes when a new video is loaded.
|
||||||
|
|
||||||
VideoIdPatch.injectCall("$INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V")
|
VideoIdPatch.injectCall("$INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V")
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Hook interaction
|
// region Hook like/dislike/remove like button clicks to send votes to the API.
|
||||||
|
|
||||||
listOf(
|
listOf(
|
||||||
LikeFingerprint.toPatch(Vote.LIKE),
|
LikeFingerprint.toPatch(Vote.LIKE),
|
||||||
@ -78,39 +79,56 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
|
|||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Hook components
|
// region Hook creation of Spans and the cached lookup of them.
|
||||||
|
|
||||||
TextReferenceFingerprint.also {
|
// Alternatively the hook can be made at the creation of Spans in TextComponentSpec,
|
||||||
|
// And it works in all situations except it fails to update the Span when the user dislikes,
|
||||||
|
// since the underlying (likes only) text did not change.
|
||||||
|
// This hook handles all situations, as it's where the created Spans are stored and later reused.
|
||||||
|
TextComponentContextFingerprint.also {
|
||||||
it.resolve(
|
it.resolve(
|
||||||
context,
|
context,
|
||||||
TextComponentConstructorFingerprint.result!!.classDef
|
TextComponentConstructorFingerprint.result!!.classDef
|
||||||
)
|
)
|
||||||
}.result?.let { result ->
|
}.result?.also { result ->
|
||||||
val moveTextRefParamInstructionIndex = TextReferenceParamFingerprint.also {
|
if (!TextComponentAtomicReferenceFingerprint.resolve(context, result.method, result.classDef))
|
||||||
if (!TextReferenceParamFingerprint.resolve(context, result.method, result.classDef))
|
throw TextComponentAtomicReferenceFingerprint.toErrorResult()
|
||||||
return TextReferenceParamFingerprint.toErrorResult()
|
}?.let { textComponentContextFingerprintResult ->
|
||||||
}.result!!.scanResult.patternScanResult!!.endIndex
|
val conversionContextIndex = textComponentContextFingerprintResult
|
||||||
|
.scanResult.patternScanResult!!.startIndex
|
||||||
|
val atomicReferenceStartIndex = TextComponentAtomicReferenceFingerprint.result!!
|
||||||
|
.scanResult.patternScanResult!!.startIndex
|
||||||
|
|
||||||
result.mutableMethod.apply {
|
textComponentContextFingerprintResult.mutableMethod.apply {
|
||||||
val insertIndex = result.scanResult.patternScanResult!!.endIndex
|
// Get the conversion context obfuscated field name, and the registers for the AtomicReference and CharSequence
|
||||||
|
val conversionContextFieldName =
|
||||||
|
(instruction(conversionContextIndex) as ReferenceInstruction).reference.toString()
|
||||||
|
val contextRegister = // any free register
|
||||||
|
(instruction(atomicReferenceStartIndex) as TwoRegisterInstruction).registerB
|
||||||
|
val atomicReferenceRegister =
|
||||||
|
(instruction(atomicReferenceStartIndex + 4) as BuilderInstruction35c).registerC
|
||||||
|
|
||||||
val atomicReferenceInstruction = (instruction(insertIndex - 1) as FiveRegisterInstruction)
|
val insertIndex = atomicReferenceStartIndex + 7
|
||||||
val conversionContextParam = atomicReferenceInstruction.registerC
|
val moveCharSequenceInstruction = instruction(insertIndex) as TwoRegisterInstruction
|
||||||
val textRefParam = (instruction(moveTextRefParamInstructionIndex) as TwoRegisterInstruction).registerA
|
val charSequenceRegister = moveCharSequenceInstruction.registerB
|
||||||
|
|
||||||
// Overwritten after injected code, which is why it can be used.
|
|
||||||
val clobberRegister = atomicReferenceInstruction.registerD
|
|
||||||
|
|
||||||
|
// Insert as first instructions at the control flow label.
|
||||||
|
// Must replace the existing instruction to preserve the label, and then insert the remaining instructions.
|
||||||
|
replaceInstruction(insertIndex, "move-object/from16 v$contextRegister, p0")
|
||||||
addInstructions(
|
addInstructions(
|
||||||
insertIndex,
|
insertIndex + 1, """
|
||||||
"""
|
iget-object v$contextRegister, v$contextRegister, $conversionContextFieldName # copy obfuscated context field into free register
|
||||||
# required instruction, otherwise register might be out of range
|
invoke-static {v$contextRegister, v$atomicReferenceRegister, v$charSequenceRegister}, $INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->onLithoTextLoaded(Ljava/lang/Object;Ljava/util/concurrent/atomic/AtomicReference;Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
|
||||||
move-object/from16 v$clobberRegister, v$textRefParam
|
move-result-object v$charSequenceRegister
|
||||||
invoke-static {v$clobberRegister, v$conversionContextParam}, $ON_COMPONENT_CREATED_DESCRIPTOR
|
move-object v${moveCharSequenceInstruction.registerA}, v${moveCharSequenceInstruction.registerB} # original instruction at the insertion point
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} ?: return TextReferenceFingerprint.toErrorResult()
|
} ?: return TextComponentContextFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Hook for Short videos.
|
||||||
|
|
||||||
ShortsTextComponentParentFingerprint.result?.let {
|
ShortsTextComponentParentFingerprint.result?.let {
|
||||||
context
|
context
|
||||||
@ -123,22 +141,23 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
|
|||||||
return PatchResultError("Method signature did not match: $this $parameterTypes")
|
return PatchResultError("Method signature did not match: $this $parameterTypes")
|
||||||
|
|
||||||
val insertIndex = implementation!!.instructions.size - 1
|
val insertIndex = implementation!!.instructions.size - 1
|
||||||
|
|
||||||
val spannedParameterRegister = (instruction(insertIndex) as OneRegisterInstruction).registerA
|
val spannedParameterRegister = (instruction(insertIndex) as OneRegisterInstruction).registerA
|
||||||
val parameter = (instruction(insertIndex - 2) as BuilderInstruction35c).reference
|
val parameter = (instruction(insertIndex - 2) as BuilderInstruction35c).reference
|
||||||
|
|
||||||
if (!parameter.toString().endsWith("Landroid/text/Spanned;"))
|
if (!parameter.toString().endsWith("Landroid/text/Spanned;"))
|
||||||
return PatchResultError("Method signature parameter did not match: $parameter")
|
return PatchResultError("Method signature parameter did not match: $parameter")
|
||||||
|
|
||||||
addInstructions(
|
insertShorts(insertIndex, spannedParameterRegister)
|
||||||
insertIndex,
|
|
||||||
"""
|
|
||||||
invoke-static {v$spannedParameterRegister}, $INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->onShortsComponentCreated(Landroid/text/Spanned;)Landroid/text/Spanned;
|
|
||||||
move-result-object v$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)
|
||||||
|
}
|
||||||
} ?: return ShortsTextComponentParentFingerprint.toErrorResult()
|
} ?: return ShortsTextComponentParentFingerprint.toErrorResult()
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
@ -150,17 +169,21 @@ class ReturnYouTubeDislikePatch : BytecodePatch(
|
|||||||
const val INTEGRATIONS_PATCH_CLASS_DESCRIPTOR =
|
const val INTEGRATIONS_PATCH_CLASS_DESCRIPTOR =
|
||||||
"Lapp/revanced/integrations/patches/ReturnYouTubeDislikePatch;"
|
"Lapp/revanced/integrations/patches/ReturnYouTubeDislikePatch;"
|
||||||
|
|
||||||
const val ON_COMPONENT_CREATED_DESCRIPTOR =
|
|
||||||
"$INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->onComponentCreated(Ljava/lang/Object;Ljava/util/concurrent/atomic/AtomicReference;)V"
|
|
||||||
|
|
||||||
private fun MethodFingerprint.toPatch(voteKind: Vote) = VotePatch(this, voteKind)
|
private fun MethodFingerprint.toPatch(voteKind: Vote) = VotePatch(this, voteKind)
|
||||||
}
|
private data class VotePatch(val fingerprint: MethodFingerprint, val voteKind: Vote)
|
||||||
|
private enum class Vote(val value: Int) {
|
||||||
|
LIKE(1),
|
||||||
|
DISLIKE(-1),
|
||||||
|
REMOVE_LIKE(0)
|
||||||
|
}
|
||||||
|
|
||||||
private data class VotePatch(val fingerprint: MethodFingerprint, val voteKind: Vote)
|
private fun MutableMethod.insertShorts(index: Int, register: Int) {
|
||||||
|
addInstructions(
|
||||||
private enum class Vote(val value: Int) {
|
index, """
|
||||||
LIKE(1),
|
invoke-static {v$register}, $INTEGRATIONS_PATCH_CLASS_DESCRIPTOR->onShortsComponentCreated(Landroid/text/Spanned;)Landroid/text/Spanned;
|
||||||
DISLIKE(-1),
|
move-result-object v$register
|
||||||
REMOVE_LIKE(0)
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user