feat(Instagram): Add Open links externally patch (#6012)

This commit is contained in:
Swakshan
2025-10-01 11:47:19 +05:30
committed by GitHub
parent d238a42708
commit 08e8ead04f
12 changed files with 153 additions and 24 deletions

View File

@@ -0,0 +1,9 @@
package app.revanced.patches.instagram.misc.links
import app.revanced.patcher.fingerprint
internal const val TARGET_STRING = "Tracking.ARG_CLICK_SOURCE"
internal val inAppBrowserFunctionFingerprint = fingerprint {
returns("Z")
strings("TrackingInfo.ARG_MODULE_NAME", TARGET_STRING)
}

View File

@@ -0,0 +1,47 @@
package app.revanced.patches.instagram.misc.links
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.instagram.misc.extension.sharedExtensionPatch
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/instagram/misc/links/OpenLinksExternallyPatch;"
@Suppress("unused")
val openLinksExternallyPatch = bytecodePatch(
name = "Open links externally",
description = "Changes links to always open in your external browser, instead of the in-app browser.",
use = false,
) {
dependsOn(sharedExtensionPatch)
compatibleWith("com.instagram.android")
execute {
inAppBrowserFunctionFingerprint.let {
val stringMatchIndex = it.stringMatches?.first { match -> match.string == TARGET_STRING }!!.index
it.method.apply {
val urlResultObjIndex = indexOfFirstInstructionOrThrow(
stringMatchIndex, Opcode.MOVE_OBJECT_FROM16
)
// Register that contains the url after moving from a higher register.
val urlRegister = getInstruction<TwoRegisterInstruction>(urlResultObjIndex).registerA
addInstructions(
urlResultObjIndex + 1,
"""
invoke-static { v$urlRegister }, $EXTENSION_CLASS_DESCRIPTOR->openExternally(Ljava/lang/String;)Z
move-result v$urlRegister
return v$urlRegister
"""
)
}
}
}
}

View File

@@ -1,5 +1,6 @@
package app.revanced.patches.twitter.misc.extension
import app.revanced.patches.shared.misc.extension.sharedExtensionPatch
import app.revanced.patches.twitter.misc.extension.hooks.applicationInitHook
val sharedExtensionPatch = sharedExtensionPatch("twitter")
val sharedExtensionPatch = sharedExtensionPatch("twitter", applicationInitHook)

View File

@@ -0,0 +1,10 @@
package app.revanced.patches.twitter.misc.extension.hooks
import app.revanced.patches.shared.misc.extension.extensionHook
internal val applicationInitHook =
extensionHook {
custom { method, classDef ->
classDef.type == "Lcom/twitter/app/TwitterApplication;" && method.name == "onCreate"
}
}

View File

@@ -53,28 +53,28 @@ val changeLinkSharingDomainPatch = bytecodePatch(
)
execute {
val replacementIndex =
linkSharingDomainFingerprint.stringMatches!!.first().index
val domainRegister =
linkSharingDomainFingerprint.method.getInstruction<OneRegisterInstruction>(replacementIndex).registerA
linkSharingDomainFingerprint.let {
val replacementIndex = it.stringMatches!!.first().index
val domainRegister = it.method.getInstruction<OneRegisterInstruction>(
replacementIndex
).registerA
linkSharingDomainFingerprint.method.replaceInstruction(
replacementIndex,
"const-string v$domainRegister, \"https://$domainName\"",
)
// Replace the domain name when copying a link with "Copy link" button.
linkBuilderFingerprint.method.apply {
addInstructions(
0,
"""
invoke-static { p0, p1, p2 }, $EXTENSION_CLASS_DESCRIPTOR->formatLink(JLjava/lang/String;)Ljava/lang/String;
move-result-object p0
return-object p0
""",
it.method.replaceInstruction(
replacementIndex,
"const-string v$domainRegister, \"https://$domainName\"",
)
}
// Replace the domain name when copying a link with "Copy link" button.
linkBuilderFingerprint.method.addInstructions(
0,
"""
invoke-static { p0, p1, p2 }, $EXTENSION_CLASS_DESCRIPTOR->formatLink(JLjava/lang/String;)Ljava/lang/String;
move-result-object p0
return-object p0
"""
)
// Used in the Share via... dialog.
linkResourceGetterFingerprint.method.apply {
val templateIdConstIndex = indexOfFirstLiteralInstructionOrThrow(tweetShareLinkTemplateId)

View File

@@ -9,7 +9,7 @@ import app.revanced.patches.twitter.misc.extension.sharedExtensionPatch
@Suppress("unused")
val openLinksWithAppChooserPatch = bytecodePatch(
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.",
"As a result you can select a browser to open the link with.",
) {
dependsOn(sharedExtensionPatch)
@@ -18,7 +18,7 @@ val openLinksWithAppChooserPatch = bytecodePatch(
execute {
val methodReference =
"Lapp/revanced/extension/twitter/patches/links/OpenLinksWithAppChooserPatch;->" +
"openWithChooser(Landroid/content/Context;Landroid/content/Intent;)V"
"openWithChooser(Landroid/content/Context;Landroid/content/Intent;)V"
openLinkFingerprint.method.addInstructions(
0,