generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reddit): add
sanitize-sharing-links
patch (#2192)
Co-authored-by: oSumAtrIX <[email protected]>
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...pp/revanced/patches/reddit/misc/tracking/url/annotations/SanitizeUrlQueryCompatibility.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.reddit.misc.tracking.url.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility([Package("com.reddit.frontpage", arrayOf("2023.12.0", "2023.17.1"))]) | ||
@Target(AnnotationTarget.CLASS) | ||
internal annotation class SanitizeUrlQueryCompatibility |
22 changes: 22 additions & 0 deletions
22
...app/revanced/patches/reddit/misc/tracking/url/fingerprints/ShareLinkFactoryFingerprint.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,22 @@ | ||
package app.revanced.patches.reddit.misc.tracking.url.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
object ShareLinkFactoryFingerprint : MethodFingerprint( | ||
returnType = "L", | ||
access = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
opcodes = listOf( | ||
Opcode.CONST_STRING, | ||
Opcode.CONST_STRING, | ||
Opcode.INVOKE_DIRECT, | ||
Opcode.APUT_OBJECT, | ||
Opcode.INVOKE_STATIC, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.INVOKE_STATIC, // Returns the URL. | ||
Opcode.MOVE_RESULT_OBJECT | ||
), | ||
customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("ShareLinkFactory;") } | ||
) |
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/app/revanced/patches/reddit/misc/tracking/url/patch/SanitizeUrlQueryPatch.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,52 @@ | ||
package app.revanced.patches.reddit.misc.tracking.url.patch | ||
|
||
import app.revanced.extensions.toErrorResult | ||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.addInstructions | ||
import app.revanced.patcher.extensions.instruction | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patcher.patch.annotations.RequiresIntegrations | ||
import app.revanced.patches.reddit.misc.tracking.url.annotations.SanitizeUrlQueryCompatibility | ||
import app.revanced.patches.reddit.misc.tracking.url.fingerprints.ShareLinkFactoryFingerprint | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
|
||
@Patch | ||
@Name("sanitize-sharing-links") | ||
@Description("Removes (tracking) query parameters from the URLs when sharing links.") | ||
@SanitizeUrlQueryCompatibility | ||
@Version("0.0.1") | ||
@RequiresIntegrations | ||
class SanitizeUrlQueryPatch : BytecodePatch( | ||
listOf(ShareLinkFactoryFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
ShareLinkFactoryFingerprint.result?.let { result -> | ||
result.mutableMethod.apply { | ||
val insertIndex = result.scanResult.patternScanResult!!.endIndex + 1 | ||
val urlRegister = instruction<OneRegisterInstruction>(insertIndex - 1).registerA | ||
|
||
addInstructions( | ||
insertIndex, | ||
""" | ||
invoke-static {v$urlRegister}, $SANITIZE_METHOD_DESCRIPTOR | ||
move-result-object v$urlRegister | ||
""" | ||
) | ||
} | ||
} ?: return ShareLinkFactoryFingerprint.toErrorResult() | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
private const val SANITIZE_METHOD_DESCRIPTOR = | ||
"Lapp/revanced/reddit/patches/SanitizeUrlQueryPatch;" + | ||
"->stripQueryParameters(Ljava/lang/String;)Ljava/lang/String;" | ||
} | ||
} |