diff --git a/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/fingerprints/ScreenNavigatorFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/fingerprints/ScreenNavigatorFingerprint.kt new file mode 100644 index 000000000..05f494666 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/fingerprints/ScreenNavigatorFingerprint.kt @@ -0,0 +1,20 @@ +package app.revanced.patches.reddit.misc.openlink.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object ScreenNavigatorFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L", "L", "L", "Z"), + opcodes = listOf( + Opcode.CONST_STRING, + Opcode.INVOKE_STATIC, + Opcode.CONST_STRING, + Opcode.INVOKE_STATIC + ), + strings = listOf("uri", "android.intent.action.VIEW"), + customFingerprint = { it, _ -> it.definingClass.endsWith("/RedditScreenNavigator;") } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/patch/OpenLinksExternallyPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/patch/OpenLinksExternallyPatch.kt new file mode 100644 index 000000000..94da5a5bd --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/misc/openlink/patch/OpenLinksExternallyPatch.kt @@ -0,0 +1,57 @@ +package app.revanced.patches.reddit.misc.openlink.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.misc.openlink.fingerprints.ScreenNavigatorFingerprint +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch.Companion.updateSettingsStatus +import app.revanced.util.bytecode.getStringIndex + +@Patch +@Name("open-links-externally") +@Description("Open links outside of the app directly in your browser.") +@DependsOn([SettingsPatch::class]) +@RedditCompatibility +@Version("0.0.1") +class OpenLinksExternallyPatch : BytecodePatch( + listOf(ScreenNavigatorFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + ScreenNavigatorFingerprint.result?.let { + it.mutableMethod.apply { + val insertIndex = getStringIndex("uri") + 2 + + addInstructionsWithLabels( + insertIndex, """ + invoke-static {}, $INTEGRATIONS_METHOD_DESCRIPTOR->openLinksExternally()Z + move-result v0 + if-eqz v0, :dismiss + invoke-static {p1, p2}, $INTEGRATIONS_METHOD_DESCRIPTOR->openLinksExternally(Landroid/app/Activity;Landroid/net/Uri;)V + return-void + """, ExternalLabel("dismiss", getInstruction(insertIndex)) + ) + } + } ?: return ScreenNavigatorFingerprint.toErrorResult() + + updateSettingsStatus("OpenLinksExternally") + + return PatchResultSuccess() + } + + private companion object { + private const val INTEGRATIONS_METHOD_DESCRIPTOR = + "Lapp/revanced/reddit/patches/OpenLinksExternallyPatch;" + } +} \ 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 ffc1f6257..8cf12554b 100644 --- a/src/main/resources/reddit/settings/host/values/strings.xml +++ b/src/main/resources/reddit/settings/host/values/strings.xml @@ -1,5 +1,7 @@ + Open links outside of the app directly in your browser + Open links externally Removes (tracking) query parameters from the URLs when sharing links Sanitize sharing links ReVanced Extended