From a1fa3a2594c75b2f4c00d855e41a46191f7b8976 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Tue, 5 Sep 2023 12:05:33 +0900 Subject: [PATCH] fix(music/exclusive audio playback): not compatible with latest version --- .../AudioOnlyEnablerFingerprint.kt | 31 ------------- .../MusicBrowserServiceFingerprint.kt | 15 +++++++ .../patch/ExclusiveAudioPatch.kt | 45 +++++++++++++++---- 3 files changed, 52 insertions(+), 39 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/fingerprints/AudioOnlyEnablerFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/fingerprints/MusicBrowserServiceFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/fingerprints/AudioOnlyEnablerFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/fingerprints/AudioOnlyEnablerFingerprint.kt deleted file mode 100644 index 257ab183a..000000000 --- a/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/fingerprints/AudioOnlyEnablerFingerprint.kt +++ /dev/null @@ -1,31 +0,0 @@ -package app.revanced.patches.music.misc.exclusiveaudio.fingerprints - -import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode - -object AudioOnlyEnablerFingerprint : MethodFingerprint( - returnType = "Z", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - parameters = emptyList(), - opcodes = listOf( - Opcode.IGET_OBJECT, - Opcode.INVOKE_INTERFACE, - Opcode.MOVE_RESULT_OBJECT, - Opcode.IGET_OBJECT, - Opcode.INVOKE_INTERFACE, - Opcode.MOVE_RESULT_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.CHECK_CAST, - Opcode.IF_NEZ, - Opcode.IGET_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT, - Opcode.GOTO, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT, - Opcode.RETURN - ) -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/fingerprints/MusicBrowserServiceFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/fingerprints/MusicBrowserServiceFingerprint.kt new file mode 100644 index 000000000..23ee80032 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/fingerprints/MusicBrowserServiceFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.music.misc.exclusiveaudio.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +object MusicBrowserServiceFingerprint : MethodFingerprint( + returnType = "L", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("Ljava/lang/String;", "Landroid/os/Bundle;"), + strings = listOf("MBS: Return empty root for client: %s, isFullMediaBrowserEnabled: %b, is client browsable: %b, isRedAccount: %b"), + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/MusicBrowserService;") + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/patch/ExclusiveAudioPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/patch/ExclusiveAudioPatch.kt index 600412e2b..1d06ce9d5 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/patch/ExclusiveAudioPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/exclusiveaudio/patch/ExclusiveAudioPatch.kt @@ -4,26 +4,55 @@ import app.revanced.extensions.exception import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstruction -import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.music.misc.exclusiveaudio.fingerprints.AudioOnlyEnablerFingerprint +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.music.misc.exclusiveaudio.fingerprints.MusicBrowserServiceFingerprint import app.revanced.patches.music.utils.annotations.MusicCompatibility +import app.revanced.util.bytecode.getStringIndex +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @Patch @Name("Exclusive audio playback") @Description("Enables the option to play music without video.") @MusicCompatibility class ExclusiveAudioPatch : BytecodePatch( - listOf(AudioOnlyEnablerFingerprint) + listOf(MusicBrowserServiceFingerprint) ) { override fun execute(context: BytecodeContext) { - AudioOnlyEnablerFingerprint.result?.mutableMethod?.let { - it.replaceInstruction(it.implementation!!.instructions.count() - 1, "const/4 v0, 0x1") - it.addInstruction("return v0") - } ?: throw AudioOnlyEnablerFingerprint.exception + MusicBrowserServiceFingerprint.result?.let { + it.mutableMethod.apply { + val targetIndex = + getStringIndex("MBS: Return empty root for client: %s, isFullMediaBrowserEnabled: %b, is client browsable: %b, isRedAccount: %b") + + for (index in targetIndex downTo 0) { + if (getInstruction(index).opcode != Opcode.INVOKE_VIRTUAL) continue + + val targetReference = getInstruction(index).reference + + if (!targetReference.toString().endsWith("()Z")) continue + + with( + context + .toMethodWalker(it.method) + .nextMethod(index, true) + .getMethod() as MutableMethod + ) { + addInstructions( + 0, """ + const/4 v0, 0x1 + return v0 + """ + ) + } + break + } + } + } ?: throw MusicBrowserServiceFingerprint.exception } }