diff --git a/patches/api/patches.api b/patches/api/patches.api index 52f732b31..abe4c4027 100644 --- a/patches/api/patches.api +++ b/patches/api/patches.api @@ -124,6 +124,10 @@ public final class app/revanced/patches/all/misc/screencapture/RemoveScreenCaptu public static final fun getRemoveScreenCaptureRestrictionPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } +public final class app/revanced/patches/all/misc/screenshot/PreventScreenshotDetectionPatchKt { + public static final fun getPreventScreenshotDetectionPatch ()Lapp/revanced/patcher/patch/BytecodePatch; +} + public final class app/revanced/patches/all/misc/screenshot/RemoveScreenshotRestrictionPatchKt { public static final fun getRemoveScreenshotRestrictionPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/screenshot/PreventScreenshotDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/screenshot/PreventScreenshotDetectionPatch.kt new file mode 100644 index 000000000..46e9eefa8 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/screenshot/PreventScreenshotDetectionPatch.kt @@ -0,0 +1,51 @@ +package app.revanced.patches.all.misc.screenshot + +import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction +import app.revanced.patcher.patch.bytecodePatch +import app.revanced.patches.all.misc.transformation.transformInstructionsPatch +import app.revanced.util.getReference +import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.reference.MethodReference +import com.android.tools.smali.dexlib2.immutable.reference.ImmutableMethodReference +import com.android.tools.smali.dexlib2.util.MethodUtil + +private val registerScreenCaptureCallbackMethodReference = ImmutableMethodReference( + "Landroid/app/Activity;", + "registerScreenCaptureCallback", + listOf( + "Ljava/util/concurrent/Executor;", + "Landroid/app/Activity\$ScreenCaptureCallback;", + ), + "V" +) + +private val unregisterScreenCaptureCallbackMethodReference = ImmutableMethodReference( + "Landroid/app/Activity;", + "unregisterScreenCaptureCallback", + listOf( + "Landroid/app/Activity\$ScreenCaptureCallback;", + ), + "V" +) + +@Suppress("unused") +val preventScreenshotDetectionPatch = bytecodePatch( + name = "Prevent screenshot detection", + description = "Removes the registration of all screen capture callbacks. This prevents the app from detecting screenshots.", +) { + dependsOn(transformInstructionsPatch( + filterMap = { _, _, instruction, instructionIndex -> + if (instruction.opcode != Opcode.INVOKE_VIRTUAL) return@transformInstructionsPatch null + + val reference = instruction.getReference() ?: return@transformInstructionsPatch null + + instructionIndex.takeIf { + MethodUtil.methodSignaturesMatch(reference, registerScreenCaptureCallbackMethodReference) || + MethodUtil.methodSignaturesMatch(reference, unregisterScreenCaptureCallbackMethodReference) + } + }, + transform = { mutableMethod, instructionIndex -> + mutableMethod.removeInstruction(instructionIndex) + } + )) +}