From 7f85e802c2bff1d9b0e8d7c05f32f10b60506648 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Mon, 31 Mar 2025 20:54:10 +0900 Subject: [PATCH] fix(Reddit - Disable screenshot popup): Patch does not work in certain environments https://github.com/inotia00/ReVanced_Extended/issues/2891 --- .../layout/screenshotpopup/Fingerprints.kt | 45 +++++++++++++++++ .../screenshotpopup/ScreenshotPopupPatch.kt | 49 ++++++++++++++++++- .../utils/resourceid/SharedResourceIdPatch.kt | 25 ++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 patches/src/main/kotlin/app/revanced/patches/reddit/utils/resourceid/SharedResourceIdPatch.kt diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/Fingerprints.kt index 01f630b2b..42d350793 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/Fingerprints.kt @@ -1,5 +1,8 @@ package app.revanced.patches.reddit.layout.screenshotpopup +import app.revanced.patches.reddit.utils.resourceid.actionShare +import app.revanced.patches.reddit.utils.resourceid.screenShotShareBanner +import app.revanced.util.containsLiteralInstruction import app.revanced.util.fingerprint.legacyFingerprint import app.revanced.util.or import com.android.tools.smali.dexlib2.AccessFlags @@ -13,3 +16,45 @@ internal val screenshotBannerContainerFingerprint = legacyFingerprint( "scope", ) ) + +/** + * Reddit 2025.06.0 ~ + */ +internal val screenshotTakenBannerComposableFingerprint = legacyFingerprint( + name = "screenshotTakenBannerComposableFingerprint", + returnType = "L", + customFingerprint = { method, classDef -> + method.containsLiteralInstruction(actionShare) && + method.containsLiteralInstruction(screenShotShareBanner) && + classDef.type.startsWith("Lcom/reddit/sharing/screenshot/composables/") && + method.name == "invoke" + } +) + +/** + * ~ Reddit 2025.05.1 + */ +internal val screenshotTakenBannerLambdaActionFingerprint = legacyFingerprint( + name = "screenshotTakenBannerLambdaFingerprint", + returnType = "V", + parameters = listOf("Landroidx/compose/runtime/", "I"), + customFingerprint = { method, _ -> + method.containsLiteralInstruction(actionShare) && + method.name == "invoke" + } +) + +/** + * ~ Reddit 2025.05.1 + */ +internal val screenshotTakenBannerLambdaBannerFingerprint = legacyFingerprint( + name = "screenshotTakenBannerLambdaFingerprint", + returnType = "V", + parameters = listOf("Landroidx/compose/runtime/", "I"), + customFingerprint = { method, _ -> + method.containsLiteralInstruction(screenShotShareBanner) && + method.name == "invoke" + } +) + + diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/ScreenshotPopupPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/ScreenshotPopupPatch.kt index 4de050ce9..3b43169b2 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/ScreenshotPopupPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/ScreenshotPopupPatch.kt @@ -9,6 +9,10 @@ import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.reddit.utils.extension.Constants.PATCHES_PATH import app.revanced.patches.reddit.utils.patch.PatchList.DISABLE_SCREENSHOT_POPUP +import app.revanced.patches.reddit.utils.resourceid.actionShare +import app.revanced.patches.reddit.utils.resourceid.screenShotShareBanner +import app.revanced.patches.reddit.utils.resourceid.sharedResourceIdPatch +import app.revanced.patches.reddit.utils.settings.is_2025_06_or_greater import app.revanced.patches.reddit.utils.settings.settingsPatch import app.revanced.patches.reddit.utils.settings.updatePatchStatus import app.revanced.util.findMutableMethodOf @@ -17,6 +21,8 @@ import app.revanced.util.fingerprint.methodOrThrow import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction import app.revanced.util.indexOfFirstInstructionOrThrow +import app.revanced.util.indexOfFirstInstructionReversedOrThrow +import app.revanced.util.indexOfFirstLiteralInstructionOrThrow import app.revanced.util.indexOfFirstStringInstruction import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.Method @@ -33,7 +39,10 @@ val screenshotPopupPatch = bytecodePatch( ) { compatibleWith(COMPATIBLE_PACKAGE) - dependsOn(settingsPatch) + dependsOn( + settingsPatch, + sharedResourceIdPatch, + ) execute { @@ -107,6 +116,44 @@ val screenshotPopupPatch = bytecodePatch( throw PatchException("Failed to find hook method") } + if (is_2025_06_or_greater) { + screenshotTakenBannerComposableFingerprint.methodOrThrow().apply { + arrayOf( + actionShare, + screenShotShareBanner + ).forEach { literal -> + val literalIndex = indexOfFirstLiteralInstructionOrThrow(literal) + val insertIndex = indexOfFirstInstructionReversedOrThrow(literalIndex, Opcode.CONST_4) + val insertRegister = getInstruction(insertIndex).registerA + val jumpIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.SGET_OBJECT) + + addInstructionsWithLabels( + insertIndex, """ + invoke-static {}, $EXTENSION_METHOD_DESCRIPTOR + move-result v$insertRegister + if-nez v$insertRegister, :hidden + """, ExternalLabel("hidden", getInstruction(jumpIndex)) + ) + } + } + } else { + arrayOf( + screenshotTakenBannerLambdaActionFingerprint, + screenshotTakenBannerLambdaBannerFingerprint + ).forEach { fingerprint -> + fingerprint.methodOrThrow().addInstructionsWithLabels( + 0, """ + invoke-static {}, $EXTENSION_METHOD_DESCRIPTOR + move-result v0 + if-eqz v0, :ignore + return-void + :ignore + nop + """ + ) + } + } + updatePatchStatus( "enableScreenshotPopup", DISABLE_SCREENSHOT_POPUP diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/utils/resourceid/SharedResourceIdPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/utils/resourceid/SharedResourceIdPatch.kt new file mode 100644 index 000000000..cb0ec3341 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/utils/resourceid/SharedResourceIdPatch.kt @@ -0,0 +1,25 @@ +package app.revanced.patches.reddit.utils.resourceid + +import app.revanced.patcher.patch.resourcePatch +import app.revanced.patches.shared.mapping.ResourceType.STRING +import app.revanced.patches.shared.mapping.getResourceId +import app.revanced.patches.shared.mapping.resourceMappingPatch + +var actionShare = -1L + private set +var nsfwDialogTitle = -1L + private set +var screenShotShareBanner = -1L + private set + +internal val sharedResourceIdPatch = resourcePatch( + description = "sharedResourceIdPatch" +) { + dependsOn(resourceMappingPatch) + + execute { + actionShare = getResourceId(STRING, "action_share") + nsfwDialogTitle = getResourceId(STRING, "nsfw_dialog_title") + screenShotShareBanner = getResourceId(STRING, "screenshot_share_banner_title") + } +} \ No newline at end of file