Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
)
Loading