From e5fd7cece94b1ff5342178f59b29576db806e0f6 Mon Sep 17 00:00:00 2001 From: epicsampler <102923070+epicsampler@users.noreply.github.com> Date: Tue, 26 Apr 2022 21:44:02 +0000 Subject: [PATCH] feat: added `codecs-unlock` patch --- src/main/kotlin/app/revanced/patches/Index.kt | 5 +- .../patches/music/audio/CodecsUnlockPatch.kt | 153 ++++++++++++++++++ 2 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/music/audio/CodecsUnlockPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/Index.kt b/src/main/kotlin/app/revanced/patches/Index.kt index 063b445f..55ce0e28 100644 --- a/src/main/kotlin/app/revanced/patches/Index.kt +++ b/src/main/kotlin/app/revanced/patches/Index.kt @@ -33,6 +33,7 @@ object Index { ::EnableSeekbarTappingPatch, ::EnableAudioOnlyPatch, ::RemoveUpgradeTabPatch, - ::BackgroundPlayPatch + ::BackgroundPlayPatch, + ::CodecsUnlockPatch ) -} \ No newline at end of file +} diff --git a/src/main/kotlin/app/revanced/patches/music/audio/CodecsUnlockPatch.kt b/src/main/kotlin/app/revanced/patches/music/audio/CodecsUnlockPatch.kt new file mode 100644 index 00000000..6323ff3e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/audio/CodecsUnlockPatch.kt @@ -0,0 +1,153 @@ +package app.revanced.patches + +import app.revanced.patcher.PatcherData +import app.revanced.patcher.extensions.or +import app.revanced.patcher.patch.* +import app.revanced.patcher.signature.MethodMetadata +import app.revanced.patcher.signature.MethodSignature +import app.revanced.patcher.signature.MethodSignatureMetadata +import app.revanced.patcher.signature.PatternScanMethod +import app.revanced.patcher.smali.toInstruction +import app.revanced.patcher.toMethodWalker +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +private val packageMetadata = listOf( + PackageMetadata( + "com.google.android.apps.youtube.music", + listOf("5.03.50") + ) +) + +private val patchMetadata = PatchMetadata( + "codecs-unlock", + "Audio codecs unlock patch", + "Patch to unlock more audio codecs", + packageMetadata, + "0.0.1" +) + +class CodecsUnlockPatch : Patch( + patchMetadata, + listOf( + MethodSignature( + MethodSignatureMetadata( + "codec-lock-method", + MethodMetadata( + "Labwj;", + "a", + ), + PatternScanMethod.Fuzzy(2),// FIXME: Test this threshold and find the best value. + packageMetadata, + "Required signature for ${patchMetadata.name}. Discovered in version 5.03.50.", + "0.0.1" + ), + "L", + AccessFlags.PUBLIC or AccessFlags.STATIC, + listOf("L", "L", "L", "L"), + listOf( + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_DIRECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_NEZ, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_NEZ, + Opcode.SGET, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_INTERFACE, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_NEZ, + Opcode.SGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CHECK_CAST, + Opcode.INVOKE_INTERFACE, + Opcode.INVOKE_DIRECT, + Opcode.RETURN_OBJECT + ) + ), + MethodSignature( + MethodSignatureMetadata( + "all-codecs-reference-method", + MethodMetadata( + "Laari;", + "b", + ), + PatternScanMethod.Fuzzy(2),// FIXME: Test this threshold and find the best value. + packageMetadata, + "Required signature for ${patchMetadata.name}. Discovered in version 5.03.50.", + "0.0.1" + ), + "J", + AccessFlags.PUBLIC or AccessFlags.FINAL, + listOf("L"), + 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 + ), + listOf("itag") + ) + ) +) { + override fun execute(patcherData: PatcherData): PatchResult { + var result = signatures.first().result!! + + val implementation = result.method.implementation!! + + val instructionIndex = result.scanData.startIndex + + result = signatures.last().result!! + val codecMethod = patcherData + .toMethodWalker(result.immutableMethod) + .walk(result.scanData.startIndex) + .getMethod() + + implementation.replaceInstruction( + instructionIndex, + "invoke-static {}, ${codecMethod.definingClass}->${codecMethod.name}()Ljava/util/Set;".toInstruction() + ) + + return PatchResultSuccess() + } +}