fix: broken patch

This commit is contained in:
inotia00
2023-01-06 16:55:25 +09:00
parent 054b36ecf3
commit 9690d8bd07
5 changed files with 71 additions and 100 deletions

View File

@ -0,0 +1,18 @@
package app.revanced.patches.music.audio.codecs.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object AllCodecsFingerprint : MethodFingerprint(
returnType = "J",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
opcodes = listOf(
Opcode.IF_NEZ,
Opcode.GOTO,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT,
Opcode.INVOKE_STATIC
)
)

View File

@ -0,0 +1,16 @@
package app.revanced.patches.music.audio.codecs.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object AllCodecsParentFingerprint : MethodFingerprint(
returnType = "J",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.INVOKE_SUPER
),
strings = listOf("itag")
)

View File

@ -1,55 +0,0 @@
package app.revanced.patches.music.audio.codecs.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value.
object AllCodecsReferenceFingerprint : MethodFingerprint(
returnType = "J",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT,
Opcode.CONST_4,
Opcode.IF_EQZ,
Opcode.IGET_BOOLEAN,
Opcode.IF_NEZ,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.IPUT_BOOLEAN,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.GOTO,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT,
Opcode.IF_NEZ,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.MOVE_RESULT,
Opcode.IF_EQZ,
Opcode.IGET_BOOLEAN,
Opcode.IF_NEZ,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.IPUT_BOOLEAN,
Opcode.IGET_OBJECT,
Opcode.INVOKE_INTERFACE,
Opcode.GOTO,
Opcode.MOVE_EXCEPTION,
Opcode.INVOKE_SUPER,
Opcode.MOVE_RESULT_WIDE,
Opcode.RETURN_WIDE
),
strings = listOf("itag")
)

View File

@ -1,30 +1,18 @@
package app.revanced.patches.music.audio.codecs.fingerprints package app.revanced.patches.music.audio.codecs.fingerprints
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
@FuzzyPatternScanMethod(2) // FIXME: Test this threshold and find the best value.
object CodecsLockFingerprint : MethodFingerprint( object CodecsLockFingerprint : MethodFingerprint(
returnType = "L", returnType = "L",
access = AccessFlags.PUBLIC or AccessFlags.STATIC, access = AccessFlags.PUBLIC or AccessFlags.STATIC,
opcodes = listOf( opcodes = listOf(
Opcode.INVOKE_DIRECT, Opcode.NEW_INSTANCE,
Opcode.INVOKE_VIRTUAL, Opcode.NEW_INSTANCE,
Opcode.MOVE_RESULT,
Opcode.IF_NEZ,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT,
Opcode.IF_NEZ,
Opcode.SGET_OBJECT,
Opcode.IGET_OBJECT,
Opcode.INVOKE_STATIC, Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT, Opcode.MOVE_RESULT_OBJECT
Opcode.INVOKE_INTERFACE,
Opcode.INVOKE_DIRECT,
Opcode.RETURN_OBJECT
), ),
strings = listOf("eac3_supported") strings = listOf("eac3_supported")
) )

View File

@ -7,19 +7,21 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.data.toMethodWalker import app.revanced.patcher.data.toMethodWalker
import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.music.audio.codecs.fingerprints.AllCodecsReferenceFingerprint import app.revanced.patches.music.audio.codecs.fingerprints.*
import app.revanced.patches.music.audio.codecs.fingerprints.CodecsLockFingerprint
import app.revanced.patches.music.misc.integrations.patch.MusicIntegrationsPatch import app.revanced.patches.music.misc.integrations.patch.MusicIntegrationsPatch
import app.revanced.patches.music.misc.settings.patch.MusicSettingsPatch import app.revanced.patches.music.misc.settings.patch.MusicSettingsPatch
import app.revanced.shared.annotation.YouTubeMusicCompatibility import app.revanced.shared.annotation.YouTubeMusicCompatibility
import app.revanced.shared.extensions.toErrorResult
import app.revanced.shared.util.integrations.Constants.MUSIC_SETTINGS_PATH import app.revanced.shared.util.integrations.Constants.MUSIC_SETTINGS_PATH
import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
import org.jf.dexlib2.iface.Method
@Patch @Patch
@DependsOn([MusicIntegrationsPatch::class, MusicSettingsPatch::class]) @DependsOn([MusicIntegrationsPatch::class, MusicSettingsPatch::class])
@ -29,41 +31,43 @@ import org.jf.dexlib2.Opcode
@Version("0.0.1") @Version("0.0.1")
class CodecsUnlockPatch : BytecodePatch( class CodecsUnlockPatch : BytecodePatch(
listOf( listOf(
CodecsLockFingerprint, AllCodecsReferenceFingerprint AllCodecsParentFingerprint,
CodecsLockFingerprint
) )
) { ) {
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
val codecsLockResult = CodecsLockFingerprint.result!!
val codecsLockMethod = codecsLockResult.mutableMethod
val implementation = codecsLockMethod.implementation!! AllCodecsParentFingerprint.result?.let { parentResult ->
AllCodecsFingerprint.also { it.resolve(context, parentResult.classDef) }.result?.let { result ->
allCodecsMethod =
context.toMethodWalker(result.method)
.nextMethod(result.scanResult.patternScanResult!!.endIndex)
.getMethod()
val scanResultStartIndex = codecsLockResult.scanResult.patternScanResult!!.startIndex } ?: return AllCodecsFingerprint.toErrorResult()
val instructionIndex = scanResultStartIndex + } ?: return AllCodecsParentFingerprint.toErrorResult()
if (implementation.instructions[scanResultStartIndex - 1].opcode == Opcode.CHECK_CAST) {
// for 5.16.xx and lower
-3
} else {
// since 5.17.xx
-2
}
val allCodecsResult = AllCodecsReferenceFingerprint.result!! CodecsLockFingerprint.result?.let { result ->
val allCodecsMethod = val endIndex = result.scanResult.patternScanResult!!.endIndex
context.toMethodWalker(allCodecsResult.method)
.nextMethod(allCodecsResult.scanResult.patternScanResult!!.startIndex)
.getMethod()
codecsLockMethod.addInstructions( with(result.mutableMethod) {
instructionIndex + 2, """ val register = (instruction(endIndex) as OneRegisterInstruction).registerA
invoke-static {}, $MUSIC_SETTINGS_PATH->enableOpusCodec()Z addInstructions(
move-result v7 endIndex + 1, """
if-eqz v7, :mp4a invoke-static {}, $MUSIC_SETTINGS_PATH->enableOpusCodec()Z
invoke-static {}, ${allCodecsMethod.definingClass}->${allCodecsMethod.name}()Ljava/util/Set; move-result v7
move-result-object p4 if-eqz v7, :mp4a
""", listOf(ExternalLabel("mp4a", codecsLockMethod.instruction(instructionIndex + 2))) invoke-static {}, ${allCodecsMethod.definingClass}->${allCodecsMethod.name}()Ljava/util/Set;
) move-result-object v$register
""", listOf(ExternalLabel("mp4a", instruction(endIndex + 1)))
)
}
} ?: return CodecsLockFingerprint.toErrorResult()
return PatchResultSuccess() return PatchResultSuccess()
} }
private companion object {
lateinit var allCodecsMethod: Method
}
} }