fix(spotify/disable-capture-restriction): make compatible with latest versions (#2095)
This commit is contained in:
parent
58632205e3
commit
e48f1278da
|
@ -8,18 +8,13 @@ import app.revanced.patcher.extensions.instruction
|
||||||
import app.revanced.patcher.extensions.replaceInstruction
|
import app.revanced.patcher.extensions.replaceInstruction
|
||||||
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.PatchResultError
|
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
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.patches.spotify.audio.annotation.DisableCaptureRestrictionCompatibility
|
import app.revanced.patches.spotify.audio.annotation.DisableCaptureRestrictionCompatibility
|
||||||
import app.revanced.patches.spotify.audio.fingerprints.DisableCaptureRestrictionAudioDriverFingerprint
|
import app.revanced.patches.spotify.audio.fingerprints.DisableCaptureRestrictionAudioDriverFingerprint
|
||||||
import app.revanced.patches.spotify.audio.resource.patch.DisableCaptureRestrictionResourcePatch
|
import app.revanced.patches.spotify.audio.resource.patch.DisableCaptureRestrictionResourcePatch
|
||||||
import org.jf.dexlib2.Opcode
|
|
||||||
import org.jf.dexlib2.iface.instruction.FiveRegisterInstruction
|
|
||||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
|
||||||
import org.jf.dexlib2.iface.reference.MethodReference
|
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@Name("disable-capture-restriction")
|
@Name("disable-capture-restriction")
|
||||||
|
@ -35,51 +30,16 @@ class DisableCaptureRestrictionBytecodePatch : BytecodePatch(
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
val method = DisableCaptureRestrictionAudioDriverFingerprint.result!!.mutableMethod
|
val method = DisableCaptureRestrictionAudioDriverFingerprint.result!!.mutableMethod
|
||||||
|
|
||||||
var invokePosition: Int? = null
|
method.apply {
|
||||||
var invokeParamRegister: Int? = null
|
// Replace constant
|
||||||
|
val original = instruction(0) as OneRegisterInstruction
|
||||||
// Find INVOKE_VIRTUAL opcode with call to AudioAttributesBuilder.setAllowedCapturePolicy(I)
|
replaceInstruction(
|
||||||
for ((index, instruction) in method.implementation!!.instructions.withIndex()) {
|
0,
|
||||||
if(instruction.opcode != Opcode.INVOKE_VIRTUAL)
|
"const/4 v${original.registerA}, $ALLOW_CAPTURE_BY_ALL"
|
||||||
continue
|
|
||||||
|
|
||||||
val methodName = ((instruction as ReferenceInstruction).reference as MethodReference).name
|
|
||||||
if (methodName != "setAllowedCapturePolicy")
|
|
||||||
continue
|
|
||||||
|
|
||||||
// Store register of the integer parameter for setAllowedCapturePolicy
|
|
||||||
invokeParamRegister = (instruction as FiveRegisterInstruction).registerD
|
|
||||||
invokePosition = index
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if(invokePosition == null || invokeParamRegister == null)
|
|
||||||
return PatchResultError("Cannot find setAllowedCapturePolicy method call")
|
|
||||||
|
|
||||||
// Walk back to the const/4 instruction that sets the parameter register
|
|
||||||
var matchFound = false
|
|
||||||
for (index in invokePosition downTo 0) {
|
|
||||||
val instruction = method.instruction(index)
|
|
||||||
if(instruction.opcode != Opcode.CONST_4)
|
|
||||||
continue
|
|
||||||
|
|
||||||
val register = (instruction as OneRegisterInstruction).registerA
|
|
||||||
if(register != invokeParamRegister)
|
|
||||||
continue
|
|
||||||
|
|
||||||
// Replace parameter value
|
|
||||||
method.replaceInstruction(
|
|
||||||
index, "const/4 v$register, $ALLOW_CAPTURE_BY_ALL"
|
|
||||||
)
|
)
|
||||||
matchFound = true
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (matchFound)
|
return PatchResultSuccess()
|
||||||
PatchResultSuccess()
|
|
||||||
else
|
|
||||||
PatchResultError("Const instruction not found")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
|
|
@ -1,10 +1,27 @@
|
||||||
package app.revanced.patches.spotify.audio.fingerprints
|
package app.revanced.patches.spotify.audio.fingerprints
|
||||||
|
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.or
|
||||||
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.Opcode
|
||||||
|
import org.jf.dexlib2.iface.instruction.ReferenceInstruction
|
||||||
|
import org.jf.dexlib2.iface.reference.MethodReference
|
||||||
|
|
||||||
object DisableCaptureRestrictionAudioDriverFingerprint : MethodFingerprint(
|
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 ->
|
customFingerprint = { methodDef ->
|
||||||
methodDef.definingClass == "Lcom/spotify/playback/playbacknative/AudioDriver;" && methodDef.name == "constructAudioAttributes"
|
// Check for method call to AudioAttributes$Builder.setAllowedCapturePolicy Android API
|
||||||
|
methodDef.implementation?.instructions?.any {
|
||||||
|
((it as? ReferenceInstruction)?.reference as? MethodReference)?.name == "setAllowedCapturePolicy"
|
||||||
|
} == true
|
||||||
}
|
}
|
||||||
)
|
)
|
Loading…
Reference in a new issue