2023-09-28 04:47:41 +02:00
|
|
|
package app.revanced.patches.youtube.misc.links
|
|
|
|
|
|
|
|
import app.revanced.patcher.data.BytecodeContext
|
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
|
|
|
|
import app.revanced.patcher.patch.BytecodePatch
|
|
|
|
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
|
|
|
import app.revanced.patcher.patch.annotation.Patch
|
2024-01-27 02:34:01 +01:00
|
|
|
import app.revanced.patches.all.misc.resources.AddResourcesPatch
|
|
|
|
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
|
2023-09-28 04:47:41 +02:00
|
|
|
import app.revanced.patches.youtube.misc.integrations.IntegrationsPatch
|
2023-11-12 00:47:21 +01:00
|
|
|
import app.revanced.patches.youtube.misc.links.fingerprints.ABUriParserFingerprint
|
|
|
|
import app.revanced.patches.youtube.misc.links.fingerprints.HTTPUriParserFingerprint
|
2023-09-28 04:47:41 +02:00
|
|
|
import app.revanced.patches.youtube.misc.settings.SettingsPatch
|
2024-01-27 02:34:01 +01:00
|
|
|
import app.revanced.util.exception
|
2023-09-28 04:47:41 +02:00
|
|
|
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
|
|
|
|
|
|
|
@Patch(
|
|
|
|
name = "Bypass URL redirects",
|
2024-01-01 16:30:04 +01:00
|
|
|
description = "Adds an option to bypass URL redirects and open the original URL directly.",
|
2024-01-27 02:34:01 +01:00
|
|
|
dependencies = [IntegrationsPatch::class, SettingsPatch::class, AddResourcesPatch::class],
|
2023-09-28 04:47:41 +02:00
|
|
|
compatiblePackages = [
|
|
|
|
CompatiblePackage(
|
|
|
|
"com.google.android.youtube",
|
|
|
|
[
|
2023-11-12 17:01:49 +01:00
|
|
|
"18.43.45",
|
|
|
|
"18.44.41",
|
2024-01-16 19:54:06 +01:00
|
|
|
"18.45.43",
|
|
|
|
"18.48.39",
|
|
|
|
"18.49.37",
|
2024-01-17 21:24:55 +01:00
|
|
|
"19.01.34",
|
2024-01-24 14:19:02 +01:00
|
|
|
"19.02.39",
|
2024-02-04 18:38:19 +01:00
|
|
|
"19.03.35",
|
|
|
|
"19.03.36",
|
|
|
|
"19.04.37"
|
2023-09-28 04:47:41 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
2024-01-16 19:54:06 +01:00
|
|
|
@Suppress("unused")
|
2023-09-28 04:47:41 +02:00
|
|
|
object BypassURLRedirectsPatch : BytecodePatch(
|
2023-11-12 00:47:21 +01:00
|
|
|
setOf(ABUriParserFingerprint, HTTPUriParserFingerprint)
|
2023-09-28 04:47:41 +02:00
|
|
|
) {
|
|
|
|
override fun execute(context: BytecodeContext) {
|
2024-01-27 02:34:01 +01:00
|
|
|
AddResourcesPatch(this::class)
|
|
|
|
|
2024-03-02 08:27:05 +01:00
|
|
|
SettingsPatch.PreferenceScreen.MISC.addPreferences(
|
|
|
|
SwitchPreference("revanced_bypass_url_redirects")
|
|
|
|
)
|
2023-09-28 04:47:41 +02:00
|
|
|
|
2023-11-12 00:47:21 +01:00
|
|
|
mapOf(
|
|
|
|
ABUriParserFingerprint to 7, // Offset to Uri.parse.
|
|
|
|
HTTPUriParserFingerprint to 0 // Offset to Uri.parse.
|
|
|
|
).map { (fingerprint, offset) ->
|
|
|
|
(fingerprint.result ?: throw fingerprint.exception) to offset
|
|
|
|
}.forEach { (result, offset) ->
|
2023-09-28 04:47:41 +02:00
|
|
|
result.mutableMethod.apply {
|
2023-11-12 00:47:21 +01:00
|
|
|
val insertIndex = result.scanResult.patternScanResult!!.startIndex + offset
|
2023-09-28 04:47:41 +02:00
|
|
|
val uriStringRegister = getInstruction<FiveRegisterInstruction>(insertIndex).registerC
|
|
|
|
|
|
|
|
replaceInstruction(
|
|
|
|
insertIndex,
|
|
|
|
"invoke-static {v$uriStringRegister}," +
|
2024-01-01 16:33:07 +01:00
|
|
|
"Lapp/revanced/integrations/youtube/patches/BypassURLRedirectsPatch;" +
|
2023-09-28 04:47:41 +02:00
|
|
|
"->" +
|
|
|
|
"parseRedirectUri(Ljava/lang/String;)Landroid/net/Uri;"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|