From 37610732da87549c22a430bb62d10793dfa2e696 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 28 Sep 2023 17:39:29 +0400 Subject: [PATCH] fix(YouTube - ReturnYouTubeDislike): Revert support for 18.37.36 (#3041) --- .../ReturnYouTubeDislikePatch.kt | 37 ++++++++++++------- .../fingerprints/ShortsTextViewFingerprint.kt | 1 + ...TextComponentAtomicReferenceFingerprint.kt | 12 ++---- .../TextComponentContextFingerprint.kt | 14 +++---- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt index dc0fd4955..3ab8e1efa 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt @@ -31,7 +31,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction PlayerTypeHookPatch::class, ], compatiblePackages = [ - CompatiblePackage("com.google.android.youtube", ["18.37.36"]) + CompatiblePackage("com.google.android.youtube", ["18.32.39"]) ] ) @Suppress("unused") @@ -89,40 +89,49 @@ object ReturnYouTubeDislikePatch : BytecodePatch( throw TextComponentAtomicReferenceFingerprint.exception }?.let { textComponentContextFingerprintResult -> val conversionContextIndex = textComponentContextFingerprintResult - .scanResult.patternScanResult!!.endIndex + .scanResult.patternScanResult!!.startIndex val atomicReferenceStartIndex = TextComponentAtomicReferenceFingerprint.result!! .scanResult.patternScanResult!!.startIndex - val insertIndex = atomicReferenceStartIndex + 9 + val insertIndex = atomicReferenceStartIndex + 6 textComponentContextFingerprintResult.mutableMethod.apply { - // Get the conversion context obfuscated field name + // Get the conversion context obfuscated field name, and the registers for the AtomicReference and CharSequence val conversionContextFieldReference = getInstruction(conversionContextIndex).reference - // Free register to hold the conversion context + // Reuse the free register to make room for the atomic reference register. val freeRegister = getInstruction(atomicReferenceStartIndex).registerB val atomicReferenceRegister = - getInstruction(atomicReferenceStartIndex + 6).registerC + getInstruction(atomicReferenceStartIndex + 1).registerC - // Instruction that is replaced, and also has the CharacterSequence register. - val moveCharSequenceInstruction = getInstruction(insertIndex) + val moveCharSequenceInstruction = getInstruction(insertIndex - 1) val charSequenceSourceRegister = moveCharSequenceInstruction.registerB val charSequenceTargetRegister = moveCharSequenceInstruction.registerA + // In order to preserve the atomic reference register, because it is overwritten, + // use another free register to store it. + replaceInstruction( + atomicReferenceStartIndex + 2, + "move-result-object v$freeRegister" + ) + replaceInstruction( + atomicReferenceStartIndex + 3, + "move-object v$charSequenceSourceRegister, v$freeRegister" + ) + // Move the current instance to the free register, and get the conversion context from it. - // Must replace the instruction to preserve the control flow label. - replaceInstruction(insertIndex, "move-object/from16 v$freeRegister, p0") + replaceInstruction(insertIndex - 1, "move-object/from16 v$freeRegister, p0") addInstructions( - insertIndex + 1, + insertIndex, """ # Move context to free register - iget-object v$freeRegister, v$freeRegister, $conversionContextFieldReference + iget-object v$freeRegister, v$freeRegister, $conversionContextFieldReference invoke-static {v$freeRegister, v$atomicReferenceRegister, v$charSequenceSourceRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->onLithoTextLoaded(Ljava/lang/Object;Ljava/util/concurrent/atomic/AtomicReference;Ljava/lang/CharSequence;)Ljava/lang/CharSequence; move-result-object v$freeRegister - # Replace the original instruction + # Replace the original char sequence with the modified one. move-object v${charSequenceTargetRegister}, v${freeRegister} """ ) @@ -141,7 +150,7 @@ object ReturnYouTubeDislikePatch : BytecodePatch( val isDisLikesBooleanReference = getInstruction(patternResult.endIndex).reference val textViewFieldReference = // Like/Dislike button TextView field - getInstruction(patternResult.endIndex - 1).reference + getInstruction(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. diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/ShortsTextViewFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/ShortsTextViewFingerprint.kt index c5efc64e4..a012ad54b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/ShortsTextViewFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/ShortsTextViewFingerprint.kt @@ -27,6 +27,7 @@ object ShortsTextViewFingerprint : MethodFingerprint( Opcode.IF_EQ, Opcode.RETURN_VOID, Opcode.IGET_OBJECT, // TextView field + Opcode.CHECK_CAST, Opcode.IGET_BOOLEAN, // boolean field ) ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentAtomicReferenceFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentAtomicReferenceFingerprint.kt index b929e2c11..069ec8bb6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentAtomicReferenceFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentAtomicReferenceFingerprint.kt @@ -13,17 +13,13 @@ object TextComponentAtomicReferenceFingerprint : MethodFingerprint( accessFlags = AccessFlags.PROTECTED or AccessFlags.FINAL, parameters = listOf("L"), opcodes = listOf( - Opcode.MOVE_OBJECT, // Register B is free register - Opcode.MOVE_OBJECT_FROM16, - Opcode.MOVE_OBJECT_FROM16, - Opcode.MOVE_OBJECT_FROM16, - Opcode.MOVE_OBJECT_FROM16, - Opcode.MOVE_OBJECT_FROM16, + Opcode.MOVE_OBJECT, // Register A and B is context, use B as context, reuse A as free register Opcode.INVOKE_VIRTUAL, // Register C is atomic reference Opcode.MOVE_RESULT_OBJECT, // Register A is char sequence + Opcode.MOVE_OBJECT, Opcode.CHECK_CAST, - Opcode.MOVE_OBJECT, // Replace this instruction with patch code - Opcode.INVOKE_INTERFACE, + Opcode.MOVE_OBJECT, + Opcode.INVOKE_INTERFACE, // Insert hook here Opcode.MOVE_RESULT, Opcode.IF_EQZ, Opcode.INVOKE_INTERFACE, diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentContextFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentContextFingerprint.kt index c23573bc2..9c2e7d7e7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentContextFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/fingerprints/TextComponentContextFingerprint.kt @@ -13,14 +13,12 @@ object TextComponentContextFingerprint : MethodFingerprint( accessFlags = AccessFlags.PROTECTED or AccessFlags.FINAL, parameters = listOf("L"), opcodes = listOf( - Opcode.MOVE_OBJECT_FROM16, - Opcode.MOVE_OBJECT_FROM16, - Opcode.INVOKE_STATIC_RANGE, - Opcode.MOVE_RESULT_OBJECT, - Opcode.IGET_OBJECT, - Opcode.IGET_OBJECT, - Opcode.IGET_OBJECT, - Opcode.IGET_OBJECT, Opcode.IGET_OBJECT, // conversion context field name + Opcode.IGET_OBJECT, + Opcode.IGET_OBJECT, + Opcode.IGET_BOOLEAN, + Opcode.IGET, + Opcode.IGET, + Opcode.IGET, ) ) \ No newline at end of file