-
-
Notifications
You must be signed in to change notification settings - Fork 455
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
feat(Twitter): Add Change link sharing domain
patch
#3118
Closed
Closed
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
08659a5
Make FxTwitter patch
FrozenAlex 6a666c0
Fix replacing logic. Add dynamic source registers
FrozenAlex 8e071a1
Fixes for the patch. Change the patching algo to make the patch more …
FrozenAlex 15cc3c0
Add removal of telemetry from links too (not sure if should be its ow…
FrozenAlex 5b0eec2
Fix comment
FrozenAlex 243bae3
Moved telemetry patch to its own file
FrozenAlex a34205f
Simplify patch
FrozenAlex 32394be
Update src/main/kotlin/app/revanced/patches/twitter/misc/links/Change…
FrozenAlex 9368538
Update src/main/kotlin/app/revanced/patches/twitter/misc/links/Remove…
FrozenAlex d67acd4
Simplify stuff
FrozenAlex 788ecff
Fixup comments
FrozenAlex a69d916
Reduce size of fingerprints
FrozenAlex 4fc5925
Fix semantic stuff
FrozenAlex 200641b
Make the register dynamic
FrozenAlex e28a346
Merge branch 'dev' into dev
FrozenAlex 97dfa84
Fix building revanced
FrozenAlex 422d702
Merge branch 'dev' into dev-twittrer
oSumAtrIX 3ca6466
refactor: Use better names
oSumAtrIX 45f84de
fix: Make option required
oSumAtrIX d884f91
style: Punctuate comments
oSumAtrIX c48b22d
refactor: Simplify code
oSumAtrIX 1197354
Merge branch 'dev' of https://github.com/revanced/revanced-patches in…
FrozenAlex fbcee66
Merge branch 'dev' of github.com:FrozenAlex/revanced-patches into dev
FrozenAlex 6f313c1
Fix the typo, improve code readability attempt #1
FrozenAlex 6d3409a
Remove for loops, remove useless variables
FrozenAlex 6e084b3
Remove useless comments, mark regions
FrozenAlex c1ffa29
Rename stuff
FrozenAlex 3084500
Make code even more readable
FrozenAlex 457733c
Remove invalid comment
FrozenAlex c8c976c
Remove comment
FrozenAlex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package app.revanced.patches.twitter.misc.links | ||
|
||
import app.revanced.extensions.exception | ||
import app.revanced.extensions.getReference | ||
import app.revanced.extensions.indexOfFirstInstruction | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions | ||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchException | ||
import app.revanced.patcher.patch.annotation.CompatiblePackage | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption | ||
import app.revanced.patches.twitter.misc.links.fingerprints.LinkBuilderFingerprint | ||
import app.revanced.patches.twitter.misc.links.fingerprints.LinkResourceGetterFingerprint | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.builder.BuilderInstruction | ||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction | ||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction | ||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference | ||
|
||
|
||
@Patch( | ||
name = "Change link sharing domain", | ||
description = "Replaces the domain name of Twitter links when sharing them.", | ||
compatiblePackages = [CompatiblePackage("com.twitter.android")] | ||
) | ||
@Suppress("unused") | ||
object ChangeLinkSharingDomainPatch : BytecodePatch( | ||
setOf(LinkBuilderFingerprint, LinkResourceGetterFingerprint) | ||
) { | ||
private var domainName by stringPatchOption( | ||
key = "domainName", | ||
default = "fxtwitter.com", | ||
title = "Domain name", | ||
description = "The domain to use when sharing links.", | ||
required = true | ||
) | ||
|
||
override fun execute(context: BytecodeContext) { | ||
val linkBuilderResult = LinkBuilderFingerprint.result ?: throw LinkBuilderFingerprint.exception | ||
|
||
// region Copy link button. | ||
val buildShareLinkMethod = linkBuilderResult.mutableMethod.apply { | ||
val stringIndex = linkBuilderResult.scanResult.stringsScanResult!!.matches | ||
.first().index | ||
|
||
val targetRegister = getInstruction<OneRegisterInstruction>(stringIndex).registerA | ||
replaceInstruction( | ||
stringIndex, | ||
"const-string v$targetRegister, \"https://$domainName/%1\$s/status/%2\$d\"" | ||
) | ||
} | ||
|
||
|
||
// endregion | ||
|
||
// Used in the Share via... dialog. | ||
LinkResourceGetterFingerprint.result?.apply { | ||
// Remove the original call to the method that uses the resources template to build the link. | ||
val originalMethodIndex = mutableMethod.indexOfFirstInstruction { | ||
opcode == Opcode.INVOKE_VIRTUAL && | ||
FrozenAlex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getReference<MethodReference>()?.definingClass == "Landroid/content/res/Resources;" | ||
} | ||
if (originalMethodIndex == -1) throw PatchException("Could not find originalMethodIndex") | ||
|
||
val shareLinkRegister = | ||
mutableMethod.getInstruction<OneRegisterInstruction>(originalMethodIndex + 1).registerA | ||
|
||
mutableMethod.apply { | ||
removeInstructions(originalMethodIndex, 2) | ||
|
||
// Remove the instruction that uses the resultRegister as an array reference to prevent an error. | ||
removeInstructions(originalMethodIndex - 2, 1) | ||
} | ||
|
||
|
||
// Get the nickname of the user that posted the tweet. This is used to build the link. | ||
val getNicknameIndex = mutableMethod.indexOfFirstInstruction { | ||
opcode == Opcode.INVOKE_VIRTUAL && | ||
FrozenAlex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getReference<MethodReference>().toString().endsWith("Ljava/lang/String;") | ||
} | ||
if (getNicknameIndex == -1) throw PatchException("Could not find getNicknameIndex") | ||
|
||
val sourceNicknameRegister = | ||
this.mutableMethod.getInstruction<OneRegisterInstruction>(getNicknameIndex + 1).registerA | ||
FrozenAlex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
val tempInstruction = mutableMethod.getInstruction<TwoRegisterInstruction>(getNicknameIndex - 1) | ||
val nicknameRegister = tempInstruction.registerA | ||
|
||
// Save the user nickname to the register that was used to store "this". | ||
mutableMethod.addInstruction( | ||
getNicknameIndex + 2, | ||
"move-object v${nicknameRegister}, v$sourceNicknameRegister" | ||
) | ||
|
||
|
||
// Call the patched method and save the result to resultRegister. | ||
val convertTweetIdToLongIndex = mutableMethod.indexOfFirstInstruction { | ||
opcode == Opcode.INVOKE_VIRTUAL && | ||
getReference<MethodReference>()?.definingClass == "Ljava/lang/Long;" | ||
} | ||
if (convertTweetIdToLongIndex == -1) throw PatchException("Could not find convertTweetIdToLongIndex") | ||
|
||
// Get tweet id (long) | ||
val tweetIdP1 = | ||
mutableMethod.getInstruction<OneRegisterInstruction>(convertTweetIdToLongIndex + 1).registerA | ||
val tweetIdP2 = tweetIdP1 + 1 | ||
|
||
// Call the patched method with the tweet ID and username and save the result to shareLinkRegister. | ||
this.mutableMethod.addInstructions( | ||
convertTweetIdToLongIndex + 2, | ||
""" | ||
invoke-static { v$tweetIdP1, v$tweetIdP2, v$nicknameRegister }, $buildShareLinkMethod | ||
move-result-object v$shareLinkRegister | ||
""" | ||
) | ||
|
||
// Restore the register that was used to store our string by duplicating the instruction that got "this". | ||
this.mutableMethod.addInstruction(convertTweetIdToLongIndex + 4, tempInstruction as BuilderInstruction) | ||
} ?: throw LinkResourceGetterFingerprint.exception | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/app/revanced/patches/twitter/misc/links/RemoveTrackingQueryParameterPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package app.revanced.patches.twitter.misc.links | ||
|
||
import app.revanced.extensions.exception | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.annotation.CompatiblePackage | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.twitter.misc.links.fingerprints.AddTrackingQueryToLinkFingerprint | ||
|
||
@Patch( | ||
name = "Remove tracking query parameter", | ||
description = "Remove the tracking query parameter from links.", | ||
compatiblePackages = [CompatiblePackage("com.twitter.android")] | ||
) | ||
@Suppress("unused") | ||
object RemoveTrackingQueryParameterPatch : BytecodePatch( | ||
setOf(AddTrackingQueryToLinkFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext) { | ||
AddTrackingQueryToLinkFingerprint.result?.mutableMethod?.addInstruction(0, "return-object p0") | ||
?: throw AddTrackingQueryToLinkFingerprint.exception | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...app/revanced/patches/twitter/misc/links/fingerprints/AddTrackingQueryToLinkFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app.revanced.patches.twitter.misc.links.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
object AddTrackingQueryToLinkFingerprint : MethodFingerprint( | ||
strings = listOf("<this>", "shareParam", "sessionToken"), | ||
) |
8 changes: 8 additions & 0 deletions
8
...ain/kotlin/app/revanced/patches/twitter/misc/links/fingerprints/LinkBuilderFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package app.revanced.patches.twitter.misc.links.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
// Returns a shareable link string based on a tweet ID and a username. | ||
object LinkBuilderFingerprint : MethodFingerprint( | ||
strings = listOf("/%1\$s/status/%2\$d"), | ||
) |
21 changes: 21 additions & 0 deletions
21
...lin/app/revanced/patches/twitter/misc/links/fingerprints/LinkResourceGetterFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package app.revanced.patches.twitter.misc.links.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
// Gets Resource string for share link view available by pressing "Share via" button. | ||
object LinkResourceGetterFingerprint : MethodFingerprint( | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
opcodes = listOf( | ||
Opcode.CONST_STRING, | ||
Opcode.INVOKE_STATIC, | ||
Opcode.CONST_4, | ||
Opcode.NEW_ARRAY, | ||
Opcode.IGET_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
), | ||
parameters = listOf("Landroid/content/res/Resources;"), | ||
strings = listOf("res.getString"), | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.