From 70f84357890c74580497dcca22ef8a1640accf4a Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sat, 2 Dec 2023 14:45:57 +0900 Subject: [PATCH] feat(YouTube/Disable HDR video): support version `18.46.43` --- .../youtube/video/hdr/DisableHdrVideoPatch.kt | 26 +++++---------- .../HdrCapabilitiesFingerprint.kt | 33 +++++++++++-------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/hdr/DisableHdrVideoPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/hdr/DisableHdrVideoPatch.kt index f6f8d4bb5..1d7f31fc3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/hdr/DisableHdrVideoPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/hdr/DisableHdrVideoPatch.kt @@ -7,7 +7,6 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch 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.utils.settings.SettingsPatch import app.revanced.patches.youtube.video.hdr.fingerprints.HdrCapabilitiesFingerprint @@ -50,22 +49,15 @@ object DisableHdrVideoPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { - HdrCapabilitiesFingerprint.result?.let { - with( - context - .toMethodWalker(it.method) - .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) - .getMethod() as MutableMethod - ) { - addInstructionsWithLabels( - 0, """ - invoke-static {}, $VIDEO_PATH/HDRVideoPatch;->disableHDRVideo()Z - move-result v0 - if-nez v0, :default - return v0 - """, ExternalLabel("default", getInstruction(0)) - ) - } + HdrCapabilitiesFingerprint.result?.mutableMethod?.apply { + addInstructionsWithLabels( + 0, """ + invoke-static {}, $VIDEO_PATH/HDRVideoPatch;->disableHDRVideo()Z + move-result v0 + if-nez v0, :default + return v0 + """, ExternalLabel("default", getInstruction(0)) + ) } ?: throw HdrCapabilitiesFingerprint.exception /** diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/hdr/fingerprints/HdrCapabilitiesFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/video/hdr/fingerprints/HdrCapabilitiesFingerprint.kt index 0b290c7ae..c98291a99 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/video/hdr/fingerprints/HdrCapabilitiesFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/video/hdr/fingerprints/HdrCapabilitiesFingerprint.kt @@ -1,20 +1,27 @@ package app.revanced.patches.youtube.video.hdr.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 +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference object HdrCapabilitiesFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = listOf("L", "L"), - opcodes = listOf( - Opcode.INVOKE_VIRTUAL_RANGE, - Opcode.MOVE_RESULT, - Opcode.INVOKE_INTERFACE, - Opcode.MOVE_RESULT_OBJECT, - Opcode.INVOKE_VIRTUAL, - ), - strings = listOf("av1_profile_main_10_hdr_10_plus_supported") + returnType = "Z", + parameters = listOf("I", "Landroid/view/Display;"), + customFingerprint = custom@{ methodDef, _ -> + if (methodDef.implementation == null) + return@custom false + + for (instruction in methodDef.implementation!!.instructions) { + if (instruction.opcode != Opcode.INVOKE_VIRTUAL) + continue + + val objectInstruction = instruction as ReferenceInstruction + if ((objectInstruction.reference as MethodReference).name != "getSupportedHdrTypes") + continue + + return@custom true + } + return@custom false + } )