From bb47c3fe43fa83e9c235dd24dc2fa39477c6e997 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Tue, 7 Nov 2023 21:36:12 +0900 Subject: [PATCH] fix(YouTube Music/SponsorBlock): when the app is in the background, segments are not fetched --- .../information/VideoInformationPatch.kt | 44 +++++++------------ .../fingerprints/VideoIdFingerprint.kt | 16 +++++++ .../fingerprints/VideoIdParentFingerprint.kt | 10 +---- 3 files changed, 32 insertions(+), 38 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt index d4caa5f10..ede57bca9 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/information/VideoInformationPatch.kt @@ -14,6 +14,7 @@ import app.revanced.patches.music.utils.fingerprints.SeekBarConstructorFingerpri import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.video.information.fingerprints.PlayerControllerSetTimeReferenceFingerprint import app.revanced.patches.music.video.information.fingerprints.VideoEndFingerprint +import app.revanced.patches.music.video.information.fingerprints.VideoIdFingerprint import app.revanced.patches.music.video.information.fingerprints.VideoIdParentFingerprint import app.revanced.patches.music.video.information.fingerprints.VideoLengthFingerprint import app.revanced.util.integrations.Constants.MUSIC_VIDEO_PATH @@ -183,37 +184,22 @@ object VideoInformationPatch : BytecodePatch( /** * Inject call for video id */ - VideoIdParentFingerprint.result?.let { - it.mutableMethod.apply { - val targetIndex = it.scanResult.patternScanResult!!.endIndex - - val targetReference = getInstruction(targetIndex).reference - val targetClass = (targetReference as FieldReference).type - - videoIdMethod = context - .findClass(targetClass)!! - .mutableClass.methods.first { method -> - method.name == "handleVideoStageEvent" - } - } + VideoIdParentFingerprint.result?.let { parentResult -> + VideoIdFingerprint.also { + it.resolve( + context, + parentResult.classDef + ) + }.result?.let { + it.mutableMethod.apply { + videoIdMethod = this + videoIdIndex = it.scanResult.patternScanResult!!.endIndex + videoIdRegister = getInstruction(videoIdIndex).registerA + } + offset++ // offset so setVideoId is called before any injected call + } ?: throw VideoIdFingerprint.exception } ?: throw VideoIdParentFingerprint.exception - videoIdMethod.apply { - for (index in implementation!!.instructions.size - 1 downTo 0) { - if (getInstruction(index).opcode != Opcode.INVOKE_INTERFACE) continue - - val targetReference = getInstruction(index).reference - - if (!targetReference.toString().endsWith("Ljava/lang/String;")) continue - - videoIdIndex = index + 1 - videoIdRegister = getInstruction(videoIdIndex).registerA - - break - } - offset++ // offset so setVideoId is called before any injected call - } - /** * Set current video id diff --git a/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdFingerprint.kt new file mode 100644 index 000000000..de7194c8b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.music.video.information.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 VideoIdFingerprint : MethodFingerprint( + returnType = "V", + parameters = listOf("L", "L", "L"), + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + opcodes = listOf( + Opcode.INVOKE_INTERFACE, + Opcode.MOVE_RESULT_OBJECT + ) +) diff --git a/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdParentFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdParentFingerprint.kt index 095133eb4..ed7487eb3 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdParentFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/information/fingerprints/VideoIdParentFingerprint.kt @@ -3,18 +3,10 @@ package app.revanced.patches.music.video.information.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 VideoIdParentFingerprint : MethodFingerprint( returnType = "V", parameters = emptyList(), accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - opcodes = listOf( - Opcode.INVOKE_SUPER, - Opcode.IGET_OBJECT, - Opcode.CONST_4, - Opcode.IPUT_OBJECT, - Opcode.IGET_OBJECT - ), - customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("/WatchFragment;") && methodDef.name == "onDestroyView" } + strings = listOf("currentWatchNextResponse") )