Skip to content

Commit

Permalink
fix(YouTube Music/Sanitize sharing links): tracking parameters are no…
Browse files Browse the repository at this point in the history
…t removed from the system share panel
  • Loading branch information
inotia00 committed Aug 11, 2024
1 parent 5ecbe49 commit 4aec1a1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 137 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import app.revanced.patcher.data.ResourceContext
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.SettingsPatch
import app.revanced.patches.shared.tracking.BaseSanitizeUrlQueryPatch
import app.revanced.util.patch.BaseResourcePatch

@Suppress("unused")
object SanitizeUrlQueryPatch : BaseResourcePatch(
name = "Sanitize sharing links",
description = "Adds an option to remove tracking query parameters from URLs when sharing links.",
dependencies = setOf(
SanitizeUrlQueryBytecodePatch::class,
BaseSanitizeUrlQueryPatch::class,
SettingsPatch::class
),
compatiblePackages = COMPATIBLE_PACKAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,69 @@ package app.revanced.patches.shared.tracking
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patches.shared.integrations.Constants.PATCHES_PATH
import app.revanced.patches.shared.tracking.fingerprints.CopyTextEndpointFingerprint
import app.revanced.patches.shared.tracking.fingerprints.ShareLinkFormatterFingerprint
import app.revanced.patches.shared.tracking.fingerprints.SystemShareLinkFormatterFingerprint
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction

abstract class BaseSanitizeUrlQueryPatch(
private val descriptor: String,
private val sharedFingerprints: List<MethodFingerprint>,
private val additionalFingerprints: List<MethodFingerprint>? = null
) : BytecodePatch(
buildSet {
addAll(sharedFingerprints)
additionalFingerprints?.let(::addAll)
}
object BaseSanitizeUrlQueryPatch : BytecodePatch(
setOf(
CopyTextEndpointFingerprint,
ShareLinkFormatterFingerprint,
SystemShareLinkFormatterFingerprint
)
) {
private fun MethodFingerprint.invoke() {
resultOrThrow().let {
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
"$PATCHES_PATH/SanitizeUrlQueryPatch;"

override fun execute(context: BytecodeContext) {
CopyTextEndpointFingerprint.resultOrThrow().let {
it.mutableMethod.apply {
val targetIndex = it.scanResult.patternScanResult!!.startIndex
val targetRegister = getInstruction<TwoRegisterInstruction>(targetIndex).registerA

addInstructions(
targetIndex + 2, """
invoke-static {v$targetRegister}, $descriptor->stripQueryParameters(Ljava/lang/String;)Ljava/lang/String;
invoke-static {v$targetRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->stripQueryParameters(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$targetRegister
"""
)
}
}
}

override fun execute(context: BytecodeContext) {
for (fingerprint in sharedFingerprints)
fingerprint.invoke()
arrayOf(
ShareLinkFormatterFingerprint,
SystemShareLinkFormatterFingerprint
).forEach { fingerprint ->
fingerprint.resultOrThrow().let {
it.mutableMethod.apply {
for ((index, instruction) in implementation!!.instructions.withIndex()) {
if (instruction.opcode != Opcode.INVOKE_VIRTUAL)
continue

if ((instruction as ReferenceInstruction).reference.toString() != "Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;")
continue

if (getInstruction(index + 1).opcode != Opcode.GOTO)
continue

val invokeInstruction = instruction as FiveRegisterInstruction

replaceInstruction(
index,
"invoke-static {v${invokeInstruction.registerC}, v${invokeInstruction.registerD}, v${invokeInstruction.registerE}}, "
+ "$INTEGRATIONS_CLASS_DESCRIPTOR->stripQueryParameters(Landroid/content/Intent;Ljava/lang/String;Ljava/lang/String;)V"
)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package app.revanced.patches.music.misc.tracking.fingerprints
package app.revanced.patches.shared.tracking.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference

/**
* Sharing panel of YouTube Music
* Sharing panel
*/
internal object ShareLinkFormatterFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("L", "Ljava/util/Map;"),
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.CHECK_CAST,
Opcode.GOTO,
Opcode.CONST_STRING,
null,
Opcode.INVOKE_VIRTUAL
),
customFingerprint = custom@{ methodDef, _ ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.tracking.fingerprints
package app.revanced.patches.shared.tracking.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.revanced.patches.youtube.misc.tracking

import app.revanced.patcher.data.ResourceContext
import app.revanced.patches.shared.tracking.BaseSanitizeUrlQueryPatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.patch.BaseResourcePatch
Expand All @@ -10,7 +11,7 @@ object SanitizeUrlQueryPatch : BaseResourcePatch(
name = "Sanitize sharing links",
description = "Adds an option to remove tracking query parameters from URLs when sharing links.",
dependencies = setOf(
SanitizeUrlQueryBytecodePatch::class,
BaseSanitizeUrlQueryPatch::class,
SettingsPatch::class
),
compatiblePackages = COMPATIBLE_PACKAGE
Expand Down

This file was deleted.

0 comments on commit 4aec1a1

Please sign in to comment.