2023-11-12 01:27:20 +01:00
|
|
|
package app.revanced.patches.youtube.misc.privacy
|
|
|
|
|
2023-12-02 22:35:13 +01:00
|
|
|
import app.revanced.util.exception
|
2023-11-12 01:27:20 +01:00
|
|
|
import app.revanced.patcher.data.BytecodeContext
|
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
2023-11-21 23:09:57 +01:00
|
|
|
import app.revanced.patcher.fingerprint.MethodFingerprint
|
|
|
|
import app.revanced.patcher.fingerprint.MethodFingerprintResult.MethodFingerprintScanResult.PatternScanResult
|
2023-11-12 01:27:20 +01:00
|
|
|
import app.revanced.patcher.patch.BytecodePatch
|
|
|
|
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
|
|
|
import app.revanced.patcher.patch.annotation.Patch
|
2023-11-21 23:09:57 +01:00
|
|
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
2023-11-12 01:27:20 +01:00
|
|
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
|
|
|
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
|
|
|
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
|
|
|
|
import app.revanced.patches.youtube.misc.privacy.fingerprints.CopyTextFingerprint
|
2023-11-21 23:09:57 +01:00
|
|
|
import app.revanced.patches.youtube.misc.privacy.fingerprints.SystemShareSheetFingerprint
|
|
|
|
import app.revanced.patches.youtube.misc.privacy.fingerprints.YouTubeShareSheetFingerprint
|
2023-11-12 01:27:20 +01:00
|
|
|
import app.revanced.patches.youtube.misc.settings.SettingsPatch
|
2023-11-21 23:09:57 +01:00
|
|
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
2023-11-12 01:27:20 +01:00
|
|
|
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
|
|
|
|
|
|
|
|
@Patch(
|
|
|
|
name = "Remove tracking query parameter",
|
2023-12-02 23:54:49 +01:00
|
|
|
description = "Remove the tracking query parameter from links you share.",
|
2023-11-12 01:27:20 +01:00
|
|
|
dependencies = [IntegrationsPatch::class, SettingsPatch::class],
|
|
|
|
compatiblePackages = [
|
|
|
|
CompatiblePackage(
|
|
|
|
"com.google.android.youtube",
|
|
|
|
[
|
|
|
|
"18.43.45",
|
2023-11-12 17:01:49 +01:00
|
|
|
"18.44.41",
|
2023-12-02 00:07:29 +01:00
|
|
|
"18.45.41",
|
|
|
|
"18.45.43"
|
2023-11-12 01:27:20 +01:00
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
@Suppress("unused")
|
|
|
|
object RemoveTrackingQueryParameterPatch : BytecodePatch(
|
2023-11-21 23:09:57 +01:00
|
|
|
setOf(CopyTextFingerprint, SystemShareSheetFingerprint, YouTubeShareSheetFingerprint)
|
2023-11-12 01:27:20 +01:00
|
|
|
) {
|
2023-12-02 22:35:13 +01:00
|
|
|
private const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/RemoveTrackingQueryParameterPatch;"
|
2023-11-12 01:27:20 +01:00
|
|
|
|
|
|
|
override fun execute(context: BytecodeContext) {
|
|
|
|
SettingsPatch.PreferenceScreen.MISC.addPreferences(
|
|
|
|
SwitchPreference(
|
|
|
|
"revanced_remove_tracking_query_parameter",
|
|
|
|
StringResource(
|
|
|
|
"revanced_remove_tracking_query_parameter_title",
|
|
|
|
"Remove tracking query parameter"
|
|
|
|
),
|
|
|
|
StringResource(
|
|
|
|
"revanced_remove_tracking_query_parameter_summary_on",
|
|
|
|
"Tracking query parameter is removed from links"
|
|
|
|
),
|
|
|
|
StringResource(
|
|
|
|
"revanced_remove_tracking_query_parameter_summary_off",
|
|
|
|
"Tracking query parameter is not removed from links"
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-11-21 23:09:57 +01:00
|
|
|
fun MethodFingerprint.hook(
|
|
|
|
getInsertIndex: PatternScanResult.() -> Int,
|
|
|
|
getUrlRegister: MutableMethod.(insertIndex: Int) -> Int
|
|
|
|
) = result?.let {
|
|
|
|
val insertIndex = it.scanResult.patternScanResult!!.getInsertIndex()
|
|
|
|
val urlRegister = it.mutableMethod.getUrlRegister(insertIndex)
|
2023-11-12 01:27:20 +01:00
|
|
|
|
2023-11-21 23:09:57 +01:00
|
|
|
it.mutableMethod.addInstructions(
|
|
|
|
insertIndex,
|
|
|
|
"""
|
|
|
|
invoke-static {v$urlRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->sanitize(Ljava/lang/String;)Ljava/lang/String;
|
|
|
|
move-result-object v$urlRegister
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
} ?: throw exception
|
|
|
|
|
|
|
|
// Native YouTube share sheet.
|
|
|
|
YouTubeShareSheetFingerprint.hook(getInsertIndex = { startIndex + 1 })
|
|
|
|
{ insertIndex -> getInstruction<OneRegisterInstruction>(insertIndex - 1).registerA }
|
2023-11-12 01:27:20 +01:00
|
|
|
|
2023-11-21 23:09:57 +01:00
|
|
|
// Native system share sheet.
|
|
|
|
SystemShareSheetFingerprint.hook(getInsertIndex = { endIndex })
|
|
|
|
{ insertIndex -> getInstruction<OneRegisterInstruction>(insertIndex - 1).registerA }
|
2023-11-12 01:27:20 +01:00
|
|
|
|
2023-11-21 23:09:57 +01:00
|
|
|
CopyTextFingerprint.hook(getInsertIndex = { startIndex + 2 })
|
|
|
|
{ insertIndex -> getInstruction<TwoRegisterInstruction>(insertIndex - 2).registerA }
|
2023-11-12 01:27:20 +01:00
|
|
|
}
|
|
|
|
}
|