From 8467b7058cbc5fed64ad682063ed919e4bf74c5f Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sat, 2 Dec 2023 11:43:18 +0900 Subject: [PATCH] fix(YouTube): `Force fullscreen` patch fails on some versions --- .../forcefullscreen/ForceFullscreenPatch.kt | 19 ++++++++++++++++++- .../VideoPortraitParentFingerprint.kt | 7 ------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/ForceFullscreenPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/ForceFullscreenPatch.kt index 4e37deefa..46fcb46a6 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/ForceFullscreenPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/ForceFullscreenPatch.kt @@ -9,11 +9,13 @@ 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.patches.youtube.fullscreen.forcefullscreen.fingerprints.ClientSettingEndpointFingerprint import app.revanced.patches.youtube.fullscreen.forcefullscreen.fingerprints.VideoPortraitParentFingerprint import app.revanced.patches.youtube.utils.settings.SettingsPatch import app.revanced.util.bytecode.getStringIndex import app.revanced.util.integrations.Constants.FULLSCREEN +import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -96,7 +98,9 @@ object ForceFullscreenPatch : BytecodePatch( */ VideoPortraitParentFingerprint.result?.let { it.mutableMethod.apply { - val targetIndex = it.scanResult.patternScanResult!!.endIndex - 1 + val stringIndex = getStringIndex("Acquiring NetLatencyActionLogger failed. taskId=") + val invokeIndex = getTargetIndexTo(stringIndex, Opcode.INVOKE_INTERFACE) + val targetIndex = getTargetIndexTo(invokeIndex, Opcode.CHECK_CAST) val targetClass = context .findClass(getInstruction(targetIndex).reference.toString())!! .mutableClass @@ -125,4 +129,17 @@ object ForceFullscreenPatch : BytecodePatch( SettingsPatch.updatePatchStatus("Force fullscreen") } + + private fun MutableMethod.getTargetIndexTo( + startIndex: Int, + opcode: Opcode + ): Int { + for (index in startIndex until implementation!!.instructions.size) { + if (getInstruction(index).opcode != opcode) + continue + + return index + } + throw PatchException("Failed to find target index") + } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/fingerprints/VideoPortraitParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/fingerprints/VideoPortraitParentFingerprint.kt index 4e6dd9108..1edd51148 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/fingerprints/VideoPortraitParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/fullscreen/forcefullscreen/fingerprints/VideoPortraitParentFingerprint.kt @@ -3,17 +3,10 @@ package app.revanced.patches.youtube.fullscreen.forcefullscreen.fingerprints import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.MethodFingerprint import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode object VideoPortraitParentFingerprint : MethodFingerprint( returnType = "V", accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("L", "Ljava/util/Map;"), - opcodes = listOf( - Opcode.INVOKE_INTERFACE, - Opcode.MOVE_RESULT_OBJECT, - Opcode.CHECK_CAST, - Opcode.GOTO - ), strings = listOf("Acquiring NetLatencyActionLogger failed. taskId=") ) \ No newline at end of file