From ca3ff3d28d45aa1a506a9c121149d3f47d58e66c Mon Sep 17 00:00:00 2001 From: inotia00 Date: Fri, 23 Jun 2023 18:57:25 +0900 Subject: [PATCH] feat(reddit): add `hide-screenshot-popup` patch --- .../ScreenshotTakenBannerFingerprint.kt | 13 ++++ .../patch/ScreenshotPopupPatch.kt | 61 +++++++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 36 +++++++++++ .../reddit/settings/host/values/strings.xml | 2 + 4 files changed, 112 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/fingerprints/ScreenshotTakenBannerFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/patch/ScreenshotPopupPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/utils/resourceid/patch/SharedResourceIdPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/fingerprints/ScreenshotTakenBannerFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/fingerprints/ScreenshotTakenBannerFingerprint.kt new file mode 100644 index 000000000..5bbfa55cf --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/fingerprints/ScreenshotTakenBannerFingerprint.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.reddit.layout.screenshotpopup.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.reddit.utils.resourceid.patch.SharedResourceIdPatch.Companion.ScreenShotShareBanner +import app.revanced.util.bytecode.isWideLiteralExists +import org.jf.dexlib2.AccessFlags + +object ScreenshotTakenBannerFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + customFingerprint = { methodDef, classDef -> methodDef.isWideLiteralExists(ScreenShotShareBanner) && classDef.sourceFile == "ScreenshotTakenBanner.kt" } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/patch/ScreenshotPopupPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/patch/ScreenshotPopupPatch.kt new file mode 100644 index 000000000..5060387b1 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/screenshotpopup/patch/ScreenshotPopupPatch.kt @@ -0,0 +1,61 @@ +package app.revanced.patches.reddit.layout.screenshotpopup.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +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.util.smali.ExternalLabel +import app.revanced.patches.reddit.layout.screenshotpopup.fingerprints.ScreenshotTakenBannerFingerprint +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility +import app.revanced.patches.reddit.utils.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch.Companion.updateSettingsStatus + +@Patch +@Name("hide-screenshot-popup") +@Description("Hides the popup when taking a screenshot.") +@DependsOn( + [ + SettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@RedditCompatibility +@Version("0.0.1") +class ScreenshotPopupPatch : BytecodePatch( + listOf(ScreenshotTakenBannerFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + + ScreenshotTakenBannerFingerprint.result?.let { + it.mutableMethod.apply { + addInstructionsWithLabels( + 0, """ + invoke-static {}, $INTEGRATIONS_METHOD_DESCRIPTOR + move-result v0 + if-eqz v0, :dismiss + return-void + """, ExternalLabel("dismiss", getInstruction(0)) + ) + } + } ?: return ScreenshotTakenBannerFingerprint.toErrorResult() + + updateSettingsStatus("ScreenshotPopup") + + return PatchResultSuccess() + } + + private companion object { + private const val INTEGRATIONS_METHOD_DESCRIPTOR = + "Lapp/revanced/reddit/patches/ScreenshotPopupPatch;" + + "->hideScreenshotPopup()Z" + } +} diff --git a/src/main/kotlin/app/revanced/patches/reddit/utils/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/utils/resourceid/patch/SharedResourceIdPatch.kt new file mode 100644 index 000000000..277d32c01 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/utils/resourceid/patch/SharedResourceIdPatch.kt @@ -0,0 +1,36 @@ +package app.revanced.patches.reddit.utils.resourceid.patch + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultError +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility +import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch +import app.revanced.util.enum.ResourceType +import app.revanced.util.enum.ResourceType.STRING + +@Name("reddit-resource-id") +@DependsOn([ResourceMappingPatch::class]) +@RedditCompatibility +@Version("0.0.1") +class SharedResourceIdPatch : ResourcePatch { + internal companion object { + var ScreenShotShareBanner: Long = -1 + } + + override fun execute(context: ResourceContext): PatchResult { + + fun find(resourceType: ResourceType, resourceName: String) = ResourceMappingPatch + .resourceMappings + .find { it.type == resourceType.value && it.name == resourceName }?.id + ?: throw PatchResultError("Failed to find resource id : $resourceName") + + ScreenShotShareBanner = find(STRING, "screenshot_share_banner_title") + + return PatchResultSuccess() + } +} \ No newline at end of file diff --git a/src/main/resources/reddit/settings/host/values/strings.xml b/src/main/resources/reddit/settings/host/values/strings.xml index 726a9c55b..ffc1f6257 100644 --- a/src/main/resources/reddit/settings/host/values/strings.xml +++ b/src/main/resources/reddit/settings/host/values/strings.xml @@ -3,4 +3,6 @@ Removes (tracking) query parameters from the URLs when sharing links Sanitize sharing links ReVanced Extended + Hides the popup when taking a screenshot + Hide screenshot popup