Skip to content

Commit 21be41c

Browse files
committed
fix(Reddit - Disable screenshot popup): Screenshot popup not being completely removed inotia00/ReVanced_Extended#1810
1 parent 56d2f7c commit 21be41c

File tree

3 files changed

+77
-74
lines changed

3 files changed

+77
-74
lines changed
Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
11
package app.revanced.patches.reddit.layout.screenshotpopup
22

3-
import app.revanced.patches.reddit.utils.resourceid.screenShotShareBanner
4-
import app.revanced.util.containsLiteralInstruction
53
import app.revanced.util.fingerprint.legacyFingerprint
6-
import com.android.tools.smali.dexlib2.Opcode
4+
import app.revanced.util.or
5+
import com.android.tools.smali.dexlib2.AccessFlags
76

8-
/**
9-
* Reddit 2025.06.0 ~
10-
*/
11-
internal val screenshotTakenBannerFingerprint = legacyFingerprint(
7+
internal val screenshotBannerContainerFingerprint = legacyFingerprint(
128
name = "screenshotTakenBannerFingerprint",
13-
returnType = "L",
14-
opcodes = listOf(
15-
Opcode.CONST_4,
16-
Opcode.IF_NE,
17-
),
18-
customFingerprint = { method, classDef ->
19-
method.containsLiteralInstruction(screenShotShareBanner) &&
20-
classDef.type.startsWith("Lcom/reddit/sharing/screenshot/composables/") &&
21-
method.name == "invoke"
22-
}
23-
)
24-
25-
/**
26-
* ~ Reddit 2025.05.1
27-
*/
28-
internal val screenshotTakenBannerLegacyFingerprint = legacyFingerprint(
29-
name = "screenshotTakenBannerLegacyFingerprint",
309
returnType = "V",
31-
parameters = listOf("Landroidx/compose/runtime/", "I"),
32-
customFingerprint = { method, classDef ->
33-
classDef.type.endsWith("\$ScreenshotTakenBannerKt\$lambda-1\$1;") &&
34-
method.name == "invoke"
35-
}
10+
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
11+
strings = listOf(
12+
"bannerContainer",
13+
"scope",
14+
)
3615
)

patches/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/ScreenshotPopupPatch.kt

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@ package app.revanced.patches.reddit.layout.screenshotpopup
22

33
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
44
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
5+
import app.revanced.patcher.patch.PatchException
56
import app.revanced.patcher.patch.bytecodePatch
7+
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
68
import app.revanced.patcher.util.smali.ExternalLabel
79
import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACKAGE
810
import app.revanced.patches.reddit.utils.extension.Constants.PATCHES_PATH
911
import app.revanced.patches.reddit.utils.patch.PatchList.DISABLE_SCREENSHOT_POPUP
10-
import app.revanced.patches.reddit.utils.resourceid.screenShotShareBanner
11-
import app.revanced.patches.reddit.utils.resourceid.sharedResourceIdPatch
12-
import app.revanced.patches.reddit.utils.settings.is_2025_06_or_greater
1312
import app.revanced.patches.reddit.utils.settings.settingsPatch
1413
import app.revanced.patches.reddit.utils.settings.updatePatchStatus
14+
import app.revanced.util.findMutableMethodOf
15+
import app.revanced.util.fingerprint.methodCall
1516
import app.revanced.util.fingerprint.methodOrThrow
17+
import app.revanced.util.getReference
18+
import app.revanced.util.indexOfFirstInstruction
1619
import app.revanced.util.indexOfFirstInstructionOrThrow
17-
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
18-
import app.revanced.util.indexOfFirstLiteralInstructionOrThrow
20+
import app.revanced.util.indexOfFirstStringInstruction
1921
import com.android.tools.smali.dexlib2.Opcode
22+
import com.android.tools.smali.dexlib2.iface.Method
2023
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
24+
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
2125

2226
private const val EXTENSION_METHOD_DESCRIPTOR =
2327
"$PATCHES_PATH/ScreenshotPopupPatch;->disableScreenshotPopup()Z"
@@ -29,41 +33,80 @@ val screenshotPopupPatch = bytecodePatch(
2933
) {
3034
compatibleWith(COMPATIBLE_PACKAGE)
3135

32-
dependsOn(
33-
settingsPatch,
34-
sharedResourceIdPatch,
35-
)
36+
dependsOn(settingsPatch)
3637

3738
execute {
3839

39-
if (is_2025_06_or_greater) {
40-
screenshotTakenBannerFingerprint.methodOrThrow().apply {
41-
val literalIndex = indexOfFirstLiteralInstructionOrThrow(screenShotShareBanner)
42-
val insertIndex = indexOfFirstInstructionReversedOrThrow(literalIndex, Opcode.CONST_4)
43-
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
44-
val jumpIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.SGET_OBJECT)
40+
val screenshotTriggerSharingListenerMethodCall =
41+
screenshotBannerContainerFingerprint.methodCall()
4542

46-
addInstructionsWithLabels(
47-
insertIndex, """
48-
invoke-static {}, $EXTENSION_METHOD_DESCRIPTOR
49-
move-result v$insertRegister
50-
if-nez v$insertRegister, :hidden
51-
""", ExternalLabel("hidden", getInstruction(jumpIndex))
52-
)
43+
fun indexOfScreenshotTriggerInstruction(method: Method) =
44+
method.indexOfFirstInstruction {
45+
getReference<MethodReference>()?.toString() == screenshotTriggerSharingListenerMethodCall
5346
}
54-
} else {
55-
screenshotTakenBannerLegacyFingerprint.methodOrThrow().apply {
47+
48+
val isScreenshotTriggerMethod: Method.() -> Boolean = {
49+
indexOfScreenshotTriggerInstruction(this) >= 0
50+
}
51+
52+
var hookCount = 0
53+
54+
fun MutableMethod.hook() {
55+
if (returnType == "V") {
5656
addInstructionsWithLabels(
5757
0, """
5858
invoke-static {}, $EXTENSION_METHOD_DESCRIPTOR
5959
move-result v0
60-
if-eqz v0, :dismiss
60+
if-eqz v0, :shown
6161
return-void
62-
""", ExternalLabel("dismiss", getInstruction(0))
62+
""", ExternalLabel("shown", getInstruction(0))
6363
)
64+
65+
hookCount++
66+
} else if (returnType.startsWith("L")) { // Reddit 2025.06+
67+
val insertIndex =
68+
indexOfFirstStringInstruction("screenshotTriggerSharingListener")
69+
70+
if (insertIndex >= 0) {
71+
val insertRegister =
72+
getInstruction<OneRegisterInstruction>(insertIndex).registerA
73+
val triggerIndex =
74+
indexOfScreenshotTriggerInstruction(this)
75+
val jumpIndex =
76+
indexOfFirstInstructionOrThrow(triggerIndex, Opcode.RETURN_OBJECT)
77+
78+
addInstructionsWithLabels(
79+
insertIndex, """
80+
invoke-static {}, $EXTENSION_METHOD_DESCRIPTOR
81+
move-result v$insertRegister
82+
if-nez v$insertRegister, :hidden
83+
""", ExternalLabel("hidden", getInstruction(jumpIndex))
84+
)
85+
86+
hookCount++
87+
}
88+
}
89+
}
90+
91+
screenshotBannerContainerFingerprint
92+
.methodOrThrow()
93+
.hook()
94+
95+
classes.forEach { classDef ->
96+
classDef.methods.forEach { method ->
97+
if (method.isScreenshotTriggerMethod()) {
98+
proxy(classDef)
99+
.mutableClass
100+
.findMutableMethodOf(method)
101+
.hook()
102+
}
64103
}
65104
}
66105

106+
if (hookCount == 0) {
107+
throw PatchException("Failed to find hook method")
108+
}
109+
67110
updatePatchStatus(
68111
"enableScreenshotPopup",
69112
DISABLE_SCREENSHOT_POPUP

patches/src/main/kotlin/app/revanced/patches/reddit/utils/resourceid/SharedResourceIdPatch.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)