From e563b19e385e09053c9dfe3feff2c41161cd856c Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 7 Feb 2023 06:31:15 +0900 Subject: [PATCH] refactor: Return YouTube Dislike now support Shorts video --- .../ShortsTextComponentParentFingerprint.kt | 19 ++++++++++ .../ReturnYouTubeDislikeBytecodePatch.kt | 38 +++++++++++++++---- 2 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/bytecode/fingerprints/ShortsTextComponentParentFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/bytecode/fingerprints/ShortsTextComponentParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/bytecode/fingerprints/ShortsTextComponentParentFingerprint.kt new file mode 100644 index 000000000..a8b121218 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/bytecode/fingerprints/ShortsTextComponentParentFingerprint.kt @@ -0,0 +1,19 @@ +package app.revanced.patches.youtube.misc.returnyoutubedislike.bytecode.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.IGET_OBJECT, + Opcode.CHECK_CAST, + Opcode.IGET_BOOLEAN, + Opcode.IF_EQZ, + Opcode.INVOKE_STATIC + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/bytecode/patch/ReturnYouTubeDislikeBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/bytecode/patch/ReturnYouTubeDislikeBytecodePatch.kt index 9a550b2e0..a4f42066e 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/bytecode/patch/ReturnYouTubeDislikeBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/returnyoutubedislike/bytecode/patch/ReturnYouTubeDislikeBytecodePatch.kt @@ -3,25 +3,26 @@ package app.revanced.patches.youtube.misc.returnyoutubedislike.bytecode.patch import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.MethodFingerprintExtensions.name +import app.revanced.patcher.data.toMethodWalker import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.youtube.misc.returnyoutubedislike.bytecode.fingerprints.* -import app.revanced.patches.youtube.misc.playertype.patch.PlayerTypeHookPatch -import app.revanced.patches.youtube.misc.videoid.legacy.patch.LegacyVideoIdPatch +import app.revanced.patches.youtube.misc.videoid.mainstream.patch.MainstreamVideoIdPatch import app.revanced.shared.annotation.YouTubeCompatibility +import app.revanced.shared.extensions.toErrorResult import app.revanced.shared.util.integrations.Constants.UTILS_PATH +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Name("return-youtube-dislike-bytecode-patch") @DependsOn( [ - LegacyVideoIdPatch::class, - PlayerTypeHookPatch::class + MainstreamVideoIdPatch::class ] ) @YouTubeCompatibility @@ -31,6 +32,7 @@ class ReturnYouTubeDislikeBytecodePatch : BytecodePatch( DislikeFingerprint, LikeFingerprint, RemoveLikeFingerprint, + ShortsTextComponentParentFingerprint, TextComponentSpecFingerprint ) ) { @@ -40,7 +42,7 @@ class ReturnYouTubeDislikeBytecodePatch : BytecodePatch( DislikeFingerprint.toPatch(Vote.DISLIKE), RemoveLikeFingerprint.toPatch(Vote.REMOVE_LIKE) ).forEach { (fingerprint, vote) -> - with(fingerprint.result ?: return PatchResultError("Failed to find ${fingerprint.name} method.")) { + with(fingerprint.result ?: return fingerprint.toErrorResult()) { mutableMethod.addInstructions( 0, """ @@ -51,7 +53,27 @@ class ReturnYouTubeDislikeBytecodePatch : BytecodePatch( } } - LegacyVideoIdPatch.injectCall("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V") + ShortsTextComponentParentFingerprint.result?.let { + with(context + .toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) + .getMethod() as MutableMethod + ) { + val insertInstructions = this.implementation!!.instructions + val insertIndex = insertInstructions.size - 1 + val insertRegister = (insertInstructions.elementAt(insertIndex) as OneRegisterInstruction).registerA + + addInstructions( + insertIndex, """ + invoke-static {v$insertRegister}, ${INTEGRATIONS_RYD_CLASS_DESCRIPTOR}->onShortsComponentCreated(Landroid/text/Spanned;)Landroid/text/Spanned; + move-result-object v$insertRegister + """ + ) + } + + } ?: return ShortsTextComponentParentFingerprint.toErrorResult() + + MainstreamVideoIdPatch.injectCall("$INTEGRATIONS_RYD_CLASS_DESCRIPTOR->newVideoLoaded(Ljava/lang/String;)V") val createComponentResult = TextComponentSpecFingerprint.result ?: return PatchResultError("Failed to find TextComponentSpecFingerprint method.") val createComponentMethod = createComponentResult.mutableMethod