Skip to content

Commit

Permalink
fix(Twitter - Change link sharing domain): Support latest app version (
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenAlex authored Oct 22, 2024
1 parent e5f3849 commit b54592c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]
}
}
Original file line number Diff line number Diff line change
@@ -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 }
)

0 comments on commit b54592c

Please sign in to comment.