From b54592cf9c5d859e1af2f02e8e6aaad7d47ab760 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 23 Oct 2024 01:03:33 +0400 Subject: [PATCH] fix(Twitter - Change link sharing domain): Support latest app version (#3786) --- .../misc/links/ChangeLinkSharingDomainPatch.kt | 16 ++++++++-------- .../ChangeLinkSharingDomainResourcePatch.kt | 17 +++++++++++++++++ .../LinkResourceGetterFingerprint.kt | 7 ++++--- 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainResourcePatch.kt diff --git a/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt b/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt index 06597dd81d..c165d41a24 100644 --- a/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt +++ b/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt @@ -12,15 +12,16 @@ import app.revanced.patches.twitter.misc.links.fingerprints.LinkBuilderFingerpri import app.revanced.patches.twitter.misc.links.fingerprints.LinkResourceGetterFingerprint import app.revanced.patches.twitter.misc.links.fingerprints.LinkSharingDomainFingerprint import app.revanced.util.exception -import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstructionOrThrow +import app.revanced.util.indexOfFirstWideLiteralInstructionValueOrThrow import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c -import com.android.tools.smali.dexlib2.iface.reference.StringReference @Patch( name = "Change link sharing domain", description = "Replaces the domain name of Twitter links when sharing them.", + dependencies = [ + ChangeLinkSharingDomainResourcePatch::class, + ], compatiblePackages = [CompatiblePackage("com.twitter.android")], ) @Suppress("unused") @@ -75,12 +76,11 @@ object ChangeLinkSharingDomainPatch : BytecodePatch( // Used in the Share via... dialog. LinkResourceGetterFingerprint.result?.mutableMethod?.apply { - val constWithParameterName = indexOfFirstInstructionOrThrow { - getReference()?.string?.contains("id.toString()") == true - } + val templateIdConstIndex = + indexOfFirstWideLiteralInstructionValueOrThrow(ChangeLinkSharingDomainResourcePatch.tweetShareLinkTemplateId) - // Format the link with the new domain name register (2 instructions above the const-string). - val formatLinkCallIndex = constWithParameterName - 2 + // Format the link with the new domain name register (1 instruction below the const). + val formatLinkCallIndex = templateIdConstIndex + 1 val formatLinkCall = getInstruction(formatLinkCallIndex) // Replace the original method call with the new method call. diff --git a/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainResourcePatch.kt b/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainResourcePatch.kt new file mode 100644 index 0000000000..52845a48e0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainResourcePatch.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.twitter.misc.links + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.shared.misc.mapping.ResourceMappingPatch + +@Patch( + dependencies = [ResourceMappingPatch::class], +) +internal object ChangeLinkSharingDomainResourcePatch : ResourcePatch() { + internal var tweetShareLinkTemplateId: Long = -1 + + override fun execute(context: ResourceContext) { + tweetShareLinkTemplateId = ResourceMappingPatch["string", "tweet_share_link"] + } +} diff --git a/src/main/kotlin/app/revanced/patches/twitter/misc/links/fingerprints/LinkResourceGetterFingerprint.kt b/src/main/kotlin/app/revanced/patches/twitter/misc/links/fingerprints/LinkResourceGetterFingerprint.kt index a84181f62c..343c9dce3d 100644 --- a/src/main/kotlin/app/revanced/patches/twitter/misc/links/fingerprints/LinkResourceGetterFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/twitter/misc/links/fingerprints/LinkResourceGetterFingerprint.kt @@ -1,12 +1,13 @@ package app.revanced.patches.twitter.misc.links.fingerprints import app.revanced.patcher.extensions.or -import app.revanced.patcher.fingerprint.MethodFingerprint +import app.revanced.patches.twitter.misc.links.ChangeLinkSharingDomainResourcePatch +import app.revanced.util.patch.LiteralValueFingerprint import com.android.tools.smali.dexlib2.AccessFlags // Gets Resource string for share link view available by pressing "Share via" button. -internal object LinkResourceGetterFingerprint : MethodFingerprint( +internal object LinkResourceGetterFingerprint : LiteralValueFingerprint( accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("Landroid/content/res/Resources;"), - strings = listOf("res.getString(R.string.t…lUsername, id.toString())"), + literalSupplier = { ChangeLinkSharingDomainResourcePatch.tweetShareLinkTemplateId } ) \ No newline at end of file