From c02510a289e34efe6f3c82cab9d034a24022d43b Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Mon, 25 Mar 2024 06:54:57 +0900 Subject: [PATCH] fix(YouTube/Disable resuming shorts on startup): not worked due to A/B tests --- .../DisableResumingShortsOnStartupPatch.kt | 32 ++++++++++++++++++- .../UserWasInShortsABConfigFingerprint.kt | 21 ++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/fingerprints/UserWasInShortsABConfigFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/DisableResumingShortsOnStartupPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/DisableResumingShortsOnStartupPatch.kt index 9d772f2c6..05b8b1b6c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/DisableResumingShortsOnStartupPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/DisableResumingShortsOnStartupPatch.kt @@ -8,11 +8,15 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.youtube.shorts.startupshortsreset.fingerprints.UserWasInShortsABConfigFingerprint import app.revanced.patches.youtube.shorts.startupshortsreset.fingerprints.UserWasInShortsFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.util.exception import app.revanced.util.getStringInstructionIndex +import app.revanced.util.getTargetIndex import app.revanced.util.getTargetIndexReversed import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -54,10 +58,36 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction ) @Suppress("unused") object DisableResumingShortsOnStartupPatch : BytecodePatch( - setOf(UserWasInShortsFingerprint) + setOf( + UserWasInShortsABConfigFingerprint, + UserWasInShortsFingerprint + ) ) { override fun execute(context: BytecodeContext) { + UserWasInShortsABConfigFingerprint.result?.let { + val insertMethod = context.toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.startIndex, true) + .getMethod() as MutableMethod + + // This method will only be called for the user being A/B tested. + // Presumably a method that processes the ProtoDataStore value (boolean) for the 'user_was_in_shorts' key. + insertMethod.apply { + val insertIndex = getTargetIndex(Opcode.IGET_OBJECT) + val insertRegister = getInstruction(insertIndex).registerA + + addInstructionsWithLabels( + insertIndex, """ + invoke-static {}, $SHORTS->disableResumingStartupShortsPlayer()Z + move-result v$insertRegister + if-eqz v$insertRegister, :show + const/4 v$insertRegister, 0x0 + return v$insertRegister + """, ExternalLabel("show", getInstruction(insertIndex)) + ) + } + } ?: throw UserWasInShortsABConfigFingerprint.exception + UserWasInShortsFingerprint.result?.let { it.mutableMethod.apply { val startIndex = getStringInstructionIndex("Failed to read user_was_in_shorts proto after successful warmup") diff --git a/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/fingerprints/UserWasInShortsABConfigFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/fingerprints/UserWasInShortsABConfigFingerprint.kt new file mode 100644 index 000000000..7354a9dfe --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/shorts/startupshortsreset/fingerprints/UserWasInShortsABConfigFingerprint.kt @@ -0,0 +1,21 @@ +package app.revanced.patches.youtube.shorts.startupshortsreset.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.Opcode + +/** + * This fingerprint is compatible with all YouTube versions after v18.15.40. + */ +object UserWasInShortsABConfigFingerprint : MethodFingerprint( + returnType = "V", + opcodes = listOf( + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.INVOKE_VIRTUAL + ), + strings = listOf("Failed to get offline response: ") +) \ No newline at end of file