generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
disable-capture-restriction
patch (#655)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...n/app/revanced/patches/spotify/audio/annotation/DisableCaptureRestrictionCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class DisableCaptureRestrictionCompatibility | ||
|
53 changes: 53 additions & 0 deletions
53
...p/revanced/patches/spotify/audio/bytecode/patch/DisableCaptureRestrictionBytecodePatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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.impl.BytecodeData | ||
import app.revanced.patcher.extensions.instruction | ||
import app.revanced.patcher.extensions.replaceInstruction | ||
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.patcher.patch.impl.BytecodePatch | ||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod | ||
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.Instruction | ||
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.1") | ||
class DisableCaptureRestrictionBytecodePatch : BytecodePatch( | ||
listOf( | ||
DisableCaptureRestrictionAudioDriverFingerprint | ||
) | ||
) { | ||
private fun MutableMethod.replaceConstant4Instruction(index: Int, instruction: Instruction, with: Int) { | ||
val register = (instruction as OneRegisterInstruction).registerA | ||
this.replaceInstruction( | ||
index, "const/4 v$register, $with" | ||
) | ||
} | ||
|
||
override fun execute(data: BytecodeData): PatchResult { | ||
val method = DisableCaptureRestrictionAudioDriverFingerprint.result!!.mutableMethod | ||
|
||
// Replace constant that contains the capture policy parameter for AudioAttributesBuilder.setAllowedCapturePolicy() | ||
val instruction = method.instruction(CONST_INSTRUCTION_POSITION) | ||
method.replaceConstant4Instruction(CONST_INSTRUCTION_POSITION, instruction, ALLOW_CAPTURE_BY_ALL) | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
const val CONST_INSTRUCTION_POSITION = 2 | ||
const val ALLOW_CAPTURE_BY_ALL = 0x01 | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ced/patches/spotify/audio/fingerprints/DisableCaptureRestrictionAudioDriverFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package app.revanced.patches.spotify.audio.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.fingerprint.method.annotation.DirectPatternScanMethod | ||
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.spotify.audio.annotation.DisableCaptureRestrictionCompatibility | ||
|
||
@Name("disable-capture-restriction-audio-driver-fingerprint") | ||
@MatchingMethod( | ||
"Lcom/spotify/playback/playbacknative/AudioDriver;", "constructAudioAttributes" | ||
) | ||
@DirectPatternScanMethod | ||
@DisableCaptureRestrictionCompatibility | ||
@Version("0.0.1") | ||
object DisableCaptureRestrictionAudioDriverFingerprint : MethodFingerprint( | ||
customFingerprint = { methodDef -> | ||
methodDef.definingClass == "Lcom/spotify/playback/playbacknative/AudioDriver;" && methodDef.name == "constructAudioAttributes" | ||
} | ||
) |
35 changes: 35 additions & 0 deletions
35
...p/revanced/patches/spotify/audio/resource/patch/DisableCaptureRestrictionResourcePatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package app.revanced.patches.spotify.audio.resource.patch | ||
|
||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.impl.ResourceData | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.impl.ResourcePatch | ||
import app.revanced.patches.spotify.audio.annotation.DisableCaptureRestrictionCompatibility | ||
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch | ||
import org.w3c.dom.Element | ||
|
||
@Name("disable-capture-restriction-resource-patch") | ||
@Description("Sets allowAudioPlaybackCapture in manifest to true.") | ||
@DisableCaptureRestrictionCompatibility | ||
@Version("0.0.1") | ||
class DisableCaptureRestrictionResourcePatch : ResourcePatch() { | ||
override fun execute(data: ResourceData): PatchResult { | ||
// create an xml editor instance | ||
data.xmlEditor["AndroidManifest.xml"].use { dom -> | ||
// get the application node | ||
val applicationNode = dom | ||
.file | ||
.getElementsByTagName("application") | ||
.item(0) as Element | ||
|
||
// set allowAudioPlaybackCapture attribute to true | ||
applicationNode.setAttribute("android:allowAudioPlaybackCapture", "true") | ||
} | ||
|
||
return PatchResultSuccess() | ||
} | ||
} |