fix(Twitter - Change link sharing domain): Support latest app version (#3786)

This commit is contained in:
Alex 2024-10-23 01:03:33 +04:00 committed by GitHub
parent e5f3849446
commit b54592cf9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 11 deletions

View File

@ -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<StringReference>()?.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<Instruction35c>(formatLinkCallIndex)
// Replace the original method call with the new method call.

View File

@ -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"]
}
}

View File

@ -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 }
)