From ba75a51b71dbb9157db230b3e97a90361019fe30 Mon Sep 17 00:00:00 2001 From: dic1911 Date: Wed, 21 Feb 2024 11:22:41 +0800 Subject: [PATCH] feat(X): Add `Open links as query` patch (#2730) Co-authored-by: oSumAtrIX --- api/revanced-patches.api | 6 ++++ .../links/OpenLinksWithAppChooserPatch.kt | 35 +++++++++++++++++++ .../links/fingerprints/OpenLinkFingerprint.kt | 8 +++++ 3 files changed, 49 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/twitter/misc/links/OpenLinksWithAppChooserPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/twitter/misc/links/fingerprints/OpenLinkFingerprint.kt diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 50a135fbe..5423b7edb 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -1114,6 +1114,12 @@ public final class app/revanced/patches/twitter/misc/hook/patch/recommendation/H public static final field INSTANCE Lapp/revanced/patches/twitter/misc/hook/patch/recommendation/HideRecommendedUsersPatch; } +public final class app/revanced/patches/twitter/misc/links/OpenLinksWithAppChooserPatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/twitter/misc/links/OpenLinksWithAppChooserPatch; + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V +} + public final class app/revanced/patches/vsco/misc/pro/UnlockProPatch : app/revanced/patcher/patch/BytecodePatch { public static final field INSTANCE Lapp/revanced/patches/vsco/misc/pro/UnlockProPatch; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V diff --git a/src/main/kotlin/app/revanced/patches/twitter/misc/links/OpenLinksWithAppChooserPatch.kt b/src/main/kotlin/app/revanced/patches/twitter/misc/links/OpenLinksWithAppChooserPatch.kt new file mode 100644 index 000000000..1807f0685 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitter/misc/links/OpenLinksWithAppChooserPatch.kt @@ -0,0 +1,35 @@ +package app.revanced.patches.twitter.misc.links + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.twitter.misc.links.fingerprints.OpenLinkFingerprint +import app.revanced.util.exception + +@Patch( + name = "Open links with app chooser", + description = "Instead of opening links directly, open them with an app chooser. " + + "As a result you can select a browser to open the link with.", + compatiblePackages = [CompatiblePackage("com.twitter.android")], + use = false, +) +@Suppress("unused") +object OpenLinksWithAppChooserPatch : BytecodePatch( + setOf(OpenLinkFingerprint), +) { + private const val METHOD_REFERENCE = + "Lapp/revanced/integrations/twitter/patches/links/OpenLinksWithAppChooserPatch;->" + + "openWithChooser(Landroid/content/Context;Landroid/content/Intent;)V" + + override fun execute(context: BytecodeContext) { + OpenLinkFingerprint.result?.mutableMethod?.addInstructions( + 0, + """ + invoke-static { p0, p1 }, $METHOD_REFERENCE + return-void + """, + ) ?: throw OpenLinkFingerprint.exception + } +} diff --git a/src/main/kotlin/app/revanced/patches/twitter/misc/links/fingerprints/OpenLinkFingerprint.kt b/src/main/kotlin/app/revanced/patches/twitter/misc/links/fingerprints/OpenLinkFingerprint.kt new file mode 100644 index 000000000..1689cd37d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitter/misc/links/fingerprints/OpenLinkFingerprint.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.twitter.misc.links.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object OpenLinkFingerprint : MethodFingerprint( + returnType = "V", + parameters = listOf("Landroid/content/Context;", "Landroid/content/Intent;", "Landroid/os/Bundle;"), +)