generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 456
feat(Spotify): Add Sanitize sharing links
patch
#4829
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
Merged
LisoUseInAIKyrios
merged 12 commits into
ReVanced:dev
from
drobotk:feat/spotify/sanitize-sharing-links
May 6, 2025
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
50f8cb3
feat(Spotify): Add `Sanitize sharing links` patch
drobotk fd94472
fix: replace regex approach with proper parsing and rebuilding
drobotk 3d45bee
fix: improve fingerprints, add try-catch
drobotk f1b8d87
fix: improve constructor fingerprint
drobotk 05ca46d
work in progress: Modify share url while preserving logging
LisoUseInAIKyrios a267144
Revert "work in progress: Modify share url while preserving logging"
LisoUseInAIKyrios a2bee4e
refactor: Modify share urls while preserving remote logging
LisoUseInAIKyrios dcb9503
Update patches/src/main/kotlin/app/revanced/patches/spotify/misc/priv…
LisoUseInAIKyrios fa96a9b
refactor
LisoUseInAIKyrios aa205d9
refactor
LisoUseInAIKyrios 2f46048
Update extensions/spotify/src/main/java/app/revanced/extension/spotif…
LisoUseInAIKyrios 84a1b69
Update patches/src/main/kotlin/app/revanced/patches/spotify/misc/priv…
LisoUseInAIKyrios 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
43 changes: 43 additions & 0 deletions
43
.../src/main/java/app/revanced/extension/spotify/misc/privacy/SanitizeSharingLinksPatch.java
This file contains hidden or 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,43 @@ | ||
package app.revanced.extension.spotify.misc.privacy; | ||
|
||
import android.net.Uri; | ||
|
||
import java.util.List; | ||
|
||
import app.revanced.extension.shared.Logger; | ||
|
||
@SuppressWarnings("unused") | ||
public final class SanitizeSharingLinksPatch { | ||
|
||
/** | ||
* Parameters that are considered undesirable and should be stripped away. | ||
*/ | ||
private static final List<String> SHARE_PARAMETERS_TO_REMOVE = List.of( | ||
"si", // Share tracking parameter. | ||
"utm_source" // Share source, such as "copy-link". | ||
); | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static String sanitizeUrl(String url) { | ||
try { | ||
Uri uri = Uri.parse(url); | ||
Uri.Builder builder = uri.buildUpon().clearQuery(); | ||
|
||
for (String paramName : uri.getQueryParameterNames()) { | ||
if (!SHARE_PARAMETERS_TO_REMOVE.contains(paramName)) { | ||
for (String value : uri.getQueryParameters(paramName)) { | ||
builder.appendQueryParameter(paramName, value); | ||
} | ||
} | ||
} | ||
|
||
return builder.build().toString(); | ||
} catch (Exception ex) { | ||
Logger.printException(() -> "sanitizeUrl failure", ex); | ||
|
||
return url; | ||
} | ||
} | ||
} | ||
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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
This file contains hidden or 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
41 changes: 41 additions & 0 deletions
41
patches/src/main/kotlin/app/revanced/patches/spotify/misc/privacy/Fingerprints.kt
This file contains hidden or 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,41 @@ | ||
package app.revanced.patches.spotify.misc.privacy | ||
|
||
import app.revanced.patcher.fingerprint | ||
import app.revanced.util.literal | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
|
||
internal val shareCopyUrlFingerprint = fingerprint { | ||
returns("Ljava/lang/Object;") | ||
parameters("Ljava/lang/Object;") | ||
strings("clipboard", "Spotify Link") | ||
custom { method, _ -> | ||
method.name == "invokeSuspend" | ||
} | ||
} | ||
|
||
internal val shareCopyUrlLegacyFingerprint = fingerprint { | ||
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
returns("Ljava/lang/Object;") | ||
parameters("Ljava/lang/Object;") | ||
strings("clipboard", "createNewSession failed") | ||
custom { method, _ -> | ||
method.name == "apply" | ||
} | ||
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
internal val formatAndroidShareSheetUrlFingerprint = fingerprint { | ||
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC) | ||
returns("Ljava/lang/String;") | ||
parameters("L", "Ljava/lang/String;") | ||
literal { | ||
'\n'.code.toLong() | ||
} | ||
} | ||
|
||
internal val formatAndroidShareSheetUrlLegacyFingerprint = fingerprint { | ||
accessFlags(AccessFlags.PUBLIC) | ||
returns("Ljava/lang/String;") | ||
parameters("Lcom/spotify/share/social/sharedata/ShareData;", "Ljava/lang/String;") | ||
literal { | ||
'\n'.code.toLong() | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...es/src/main/kotlin/app/revanced/patches/spotify/misc/privacy/SanitizeSharingLinksPatch.kt
This file contains hidden or 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,70 @@ | ||
package app.revanced.patches.spotify.misc.privacy | ||
|
||
import app.revanced.patcher.Fingerprint | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.patch.bytecodePatch | ||
import app.revanced.patches.spotify.misc.extension.IS_SPOTIFY_LEGACY_APP_TARGET | ||
import app.revanced.patches.spotify.misc.extension.sharedExtensionPatch | ||
import app.revanced.util.getReference | ||
import app.revanced.util.indexOfFirstInstructionOrThrow | ||
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction | ||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference | ||
|
||
private const val EXTENSION_CLASS_DESCRIPTOR = | ||
"Lapp/revanced/extension/spotify/misc/privacy/SanitizeSharingLinksPatch;" | ||
|
||
@Suppress("unused") | ||
val sanitizeSharingLinksPatch = bytecodePatch( | ||
name = "Sanitize sharing links", | ||
description = "Removes the tracking query parameters from links before they are shared.", | ||
) { | ||
compatibleWith("com.spotify.music") | ||
|
||
dependsOn(sharedExtensionPatch) | ||
|
||
execute { | ||
val extensionMethodDescriptor = "$EXTENSION_CLASS_DESCRIPTOR->" + | ||
"sanitizeUrl(Ljava/lang/String;)Ljava/lang/String;" | ||
|
||
val copyFingerprint = if (IS_SPOTIFY_LEGACY_APP_TARGET) { | ||
shareCopyUrlLegacyFingerprint | ||
} else { | ||
shareCopyUrlFingerprint | ||
} | ||
|
||
copyFingerprint.method.apply { | ||
val newPlainTextInvokeIndex = indexOfFirstInstructionOrThrow { | ||
getReference<MethodReference>()?.name == "newPlainText" | ||
} | ||
val register = getInstruction<FiveRegisterInstruction>(newPlainTextInvokeIndex).registerD | ||
|
||
addInstructions( | ||
newPlainTextInvokeIndex, | ||
""" | ||
invoke-static { v$register }, $extensionMethodDescriptor | ||
move-result-object v$register | ||
""" | ||
) | ||
} | ||
|
||
// Android native share sheet is used for all other quick share types (X, WhatsApp, etc). | ||
val shareUrlParameter : String | ||
val shareSheetFingerprint : Fingerprint | ||
if (IS_SPOTIFY_LEGACY_APP_TARGET) { | ||
shareSheetFingerprint = formatAndroidShareSheetUrlLegacyFingerprint | ||
shareUrlParameter = "p2" | ||
} else { | ||
shareSheetFingerprint = formatAndroidShareSheetUrlFingerprint | ||
shareUrlParameter = "p1" | ||
} | ||
|
||
shareSheetFingerprint.method.addInstructions( | ||
0, | ||
""" | ||
invoke-static { $shareUrlParameter }, $extensionMethodDescriptor | ||
move-result-object $shareUrlParameter | ||
""" | ||
) | ||
} | ||
} | ||
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.