From 49ce47c3eed6a1626674d0f60ae0fdbe349e804b Mon Sep 17 00:00:00 2001 From: Tim Schneeberger Date: Fri, 26 May 2023 20:09:42 +0200 Subject: [PATCH] feat(remove-screen-capture-restriction): remove app constraint (#2260) Co-authored-by: oSumAtrIX --- .../patch/RemoveCaptureRestrictionPatch.kt | 66 +++++++++++++++++++ .../RemoveCaptureRestrictionResourcePatch.kt} | 10 ++- .../DisableCaptureRestrictionCompatibility.kt | 11 ---- .../DisableCaptureRestrictionBytecodePatch.kt | 48 -------------- ...aptureRestrictionAudioDriverFingerprint.kt | 27 -------- 5 files changed, 70 insertions(+), 92 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/all/screencapture/removerestriction/bytecode/patch/RemoveCaptureRestrictionPatch.kt rename src/main/kotlin/app/revanced/patches/{spotify/audio/resource/patch/DisableCaptureRestrictionResourcePatch.kt => all/screencapture/removerestriction/resource/patch/RemoveCaptureRestrictionResourcePatch.kt} (75%) delete mode 100644 src/main/kotlin/app/revanced/patches/spotify/audio/annotation/DisableCaptureRestrictionCompatibility.kt delete mode 100644 src/main/kotlin/app/revanced/patches/spotify/audio/bytecode/patch/DisableCaptureRestrictionBytecodePatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/spotify/audio/fingerprints/DisableCaptureRestrictionAudioDriverFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/all/screencapture/removerestriction/bytecode/patch/RemoveCaptureRestrictionPatch.kt b/src/main/kotlin/app/revanced/patches/all/screencapture/removerestriction/bytecode/patch/RemoveCaptureRestrictionPatch.kt new file mode 100644 index 000000000..39a433531 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/all/screencapture/removerestriction/bytecode/patch/RemoveCaptureRestrictionPatch.kt @@ -0,0 +1,66 @@ +package app.revanced.patches.all.screencapture.removerestriction.bytecode.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.annotations.RequiresIntegrations +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.all.screencapture.removerestriction.resource.patch.RemoveCaptureRestrictionResourcePatch +import app.revanced.util.patch.* +import org.jf.dexlib2.iface.ClassDef +import org.jf.dexlib2.iface.Method +import org.jf.dexlib2.iface.instruction.Instruction + +@Patch(false) +@Name("remove-screen-capture-restriction") +@Description("Removes the restriction of capturing audio from apps that normally wouldn't allow it.") +@Version("0.0.1") +@DependsOn([RemoveCaptureRestrictionResourcePatch::class]) +@RequiresIntegrations +internal class RemoveCaptureRestrictionPatch : AbstractTransformInstructionsPatch() { + // Information about method calls we want to replace + enum class MethodCall( + override val definedClassName: String, + override val methodName: String, + override val methodParams: Array, + override val returnType: String + ): IMethodCall { + SetAllowedCapturePolicySingle( + "Landroid/media/AudioAttributes\$Builder;", + "setAllowedCapturePolicy", + arrayOf("I"), + "Landroid/media/AudioAttributes\$Builder;", + ), + SetAllowedCapturePolicyGlobal( + "Landroid/media/AudioManager;", + "setAllowedCapturePolicy", + arrayOf("I"), + "V", + ); + } + + override fun filterMap( + classDef: ClassDef, + method: Method, + instruction: Instruction, + instructionIndex: Int + ) = filterMapInstruction35c( + INTEGRATIONS_CLASS_DESCRIPTOR_PREFIX, + classDef, + instruction, + instructionIndex + ) + + override fun transform(mutableMethod: MutableMethod, entry: Instruction35cInfo) { + val (methodType, instruction, instructionIndex) = entry + methodType.replaceInvokeVirtualWithIntegrations(INTEGRATIONS_CLASS_DESCRIPTOR, mutableMethod, instruction, instructionIndex) + } + + private companion object { + const val INTEGRATIONS_CLASS_DESCRIPTOR_PREFIX = + "Lapp/revanced/all/screencapture/removerestriction/RemoveScreencaptureRestrictionPatch" + const val INTEGRATIONS_CLASS_DESCRIPTOR = "$INTEGRATIONS_CLASS_DESCRIPTOR_PREFIX;" + } +} diff --git a/src/main/kotlin/app/revanced/patches/spotify/audio/resource/patch/DisableCaptureRestrictionResourcePatch.kt b/src/main/kotlin/app/revanced/patches/all/screencapture/removerestriction/resource/patch/RemoveCaptureRestrictionResourcePatch.kt similarity index 75% rename from src/main/kotlin/app/revanced/patches/spotify/audio/resource/patch/DisableCaptureRestrictionResourcePatch.kt rename to src/main/kotlin/app/revanced/patches/all/screencapture/removerestriction/resource/patch/RemoveCaptureRestrictionResourcePatch.kt index 5088cce81..5fe2f77fa 100644 --- a/src/main/kotlin/app/revanced/patches/spotify/audio/resource/patch/DisableCaptureRestrictionResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/all/screencapture/removerestriction/resource/patch/RemoveCaptureRestrictionResourcePatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.spotify.audio.resource.patch +package app.revanced.patches.all.screencapture.removerestriction.resource.patch import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name @@ -7,14 +7,12 @@ import app.revanced.patcher.data.ResourceContext import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.ResourcePatch -import app.revanced.patches.spotify.audio.annotation.DisableCaptureRestrictionCompatibility import org.w3c.dom.Element -@Name("disable-capture-restriction-resource-patch") +@Name("remove-screen-capture-restriction-resource-patch") @Description("Sets allowAudioPlaybackCapture in manifest to true.") -@DisableCaptureRestrictionCompatibility -@Version("0.0.2") -class DisableCaptureRestrictionResourcePatch : ResourcePatch { +@Version("0.0.1") +internal class RemoveCaptureRestrictionResourcePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { // create an xml editor instance context.xmlEditor["AndroidManifest.xml"].use { dom -> diff --git a/src/main/kotlin/app/revanced/patches/spotify/audio/annotation/DisableCaptureRestrictionCompatibility.kt b/src/main/kotlin/app/revanced/patches/spotify/audio/annotation/DisableCaptureRestrictionCompatibility.kt deleted file mode 100644 index 849e34b5d..000000000 --- a/src/main/kotlin/app/revanced/patches/spotify/audio/annotation/DisableCaptureRestrictionCompatibility.kt +++ /dev/null @@ -1,11 +0,0 @@ -package app.revanced.patches.spotify.audio.annotation - -import app.revanced.patcher.annotation.Compatibility -import app.revanced.patcher.annotation.Package - -@Compatibility( - [Package("com.spotify.music")] -) -@Target(AnnotationTarget.CLASS) -internal annotation class DisableCaptureRestrictionCompatibility - diff --git a/src/main/kotlin/app/revanced/patches/spotify/audio/bytecode/patch/DisableCaptureRestrictionBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/spotify/audio/bytecode/patch/DisableCaptureRestrictionBytecodePatch.kt deleted file mode 100644 index cc656d112..000000000 --- a/src/main/kotlin/app/revanced/patches/spotify/audio/bytecode/patch/DisableCaptureRestrictionBytecodePatch.kt +++ /dev/null @@ -1,48 +0,0 @@ -package app.revanced.patches.spotify.audio.bytecode.patch - -import app.revanced.patcher.annotation.Description -import app.revanced.patcher.annotation.Name -import app.revanced.patcher.annotation.Version -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.instruction -import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patches.spotify.audio.annotation.DisableCaptureRestrictionCompatibility -import app.revanced.patches.spotify.audio.fingerprints.DisableCaptureRestrictionAudioDriverFingerprint -import app.revanced.patches.spotify.audio.resource.patch.DisableCaptureRestrictionResourcePatch -import org.jf.dexlib2.iface.instruction.OneRegisterInstruction - -@Patch -@Name("disable-capture-restriction") -@DependsOn([DisableCaptureRestrictionResourcePatch::class]) -@Description("Allows capturing Spotify's audio output while screen sharing or screen recording.") -@DisableCaptureRestrictionCompatibility -@Version("0.0.2") -class DisableCaptureRestrictionBytecodePatch : BytecodePatch( - listOf( - DisableCaptureRestrictionAudioDriverFingerprint - ) -) { - override fun execute(context: BytecodeContext): PatchResult { - val method = DisableCaptureRestrictionAudioDriverFingerprint.result!!.mutableMethod - - method.apply { - // Replace constant - val original = instruction(0) as OneRegisterInstruction - replaceInstruction( - 0, - "const/4 v${original.registerA}, $ALLOW_CAPTURE_BY_ALL" - ) - } - - return PatchResultSuccess() - } - - private companion object { - const val ALLOW_CAPTURE_BY_ALL = 0x01 - } -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/spotify/audio/fingerprints/DisableCaptureRestrictionAudioDriverFingerprint.kt b/src/main/kotlin/app/revanced/patches/spotify/audio/fingerprints/DisableCaptureRestrictionAudioDriverFingerprint.kt deleted file mode 100644 index 97b9193e6..000000000 --- a/src/main/kotlin/app/revanced/patches/spotify/audio/fingerprints/DisableCaptureRestrictionAudioDriverFingerprint.kt +++ /dev/null @@ -1,27 +0,0 @@ -package app.revanced.patches.spotify.audio.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 -import org.jf.dexlib2.iface.instruction.ReferenceInstruction -import org.jf.dexlib2.iface.reference.MethodReference - -object DisableCaptureRestrictionAudioDriverFingerprint : MethodFingerprint( - "L", - AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.SYNTHETIC or AccessFlags.BRIDGE, - listOf("L"), - listOf( - Opcode.CONST_4, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.RETURN_OBJECT - ), - customFingerprint = { methodDef, _ -> - // Check for method call to AudioAttributes$Builder.setAllowedCapturePolicy Android API - methodDef.implementation?.instructions?.any { - ((it as? ReferenceInstruction)?.reference as? MethodReference)?.name == "setAllowedCapturePolicy" - } == true - } -) \ No newline at end of file