diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/links/BypassURLRedirectsPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/links/BypassURLRedirectsPatch.kt new file mode 100644 index 0000000000..b164b15825 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/links/BypassURLRedirectsPatch.kt @@ -0,0 +1,70 @@ +package app.revanced.patches.youtube.misc.links + +import app.revanced.extensions.exception +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 +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.links.fingerprints.OpenLinksDirectlyPrimaryFingerprint +import app.revanced.patches.youtube.misc.links.fingerprints.OpenLinksDirectlySecondaryFingerprint +import app.revanced.patches.youtube.misc.settings.SettingsPatch +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction + +@Patch( + name = "Bypass URL redirects", + description = "Bypass URL redirects and open the original URL directly.", + dependencies = [IntegrationsPatch::class, SettingsPatch::class], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.youtube", + [ + "18.16.37", + "18.19.35", + "18.20.39", + "18.23.35", + "18.29.38", + "18.32.39", + "18.37.36" + ] + ) + ] +) +object BypassURLRedirectsPatch : BytecodePatch( + setOf(OpenLinksDirectlyPrimaryFingerprint, OpenLinksDirectlySecondaryFingerprint) +) { + override fun execute(context: BytecodeContext) { + SettingsPatch.PreferenceScreen.MISC.addPreferences( + SwitchPreference( + "revanced_bypass_url_redirects", + StringResource("revanced_bypass_url_redirects_title", "Bypass URL redirects"), + StringResource("revanced_bypass_url_redirects_summary_on", "URL redirects are bypassed"), + StringResource("revanced_bypass_url_redirects_summary_off", "URL redirects are not bypassed"), + ) + ) + + arrayOf( + OpenLinksDirectlyPrimaryFingerprint, + OpenLinksDirectlySecondaryFingerprint + ).map { + it.result ?: throw it.exception + }.forEach { result -> + result.mutableMethod.apply { + val insertIndex = result.scanResult.patternScanResult!!.startIndex + val uriStringRegister = getInstruction(insertIndex).registerC + + replaceInstruction( + insertIndex, + "invoke-static {v$uriStringRegister}," + + "Lapp/revanced/integrations/patches/BypassURLRedirectsPatch;" + + "->" + + "parseRedirectUri(Ljava/lang/String;)Landroid/net/Uri;" + ) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/links/fingerprints/OpenLinksDirectlyPrimaryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/links/fingerprints/OpenLinksDirectlyPrimaryFingerprint.kt new file mode 100644 index 0000000000..3cdfe2f414 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/links/fingerprints/OpenLinksDirectlyPrimaryFingerprint.kt @@ -0,0 +1,20 @@ +package app.revanced.patches.youtube.misc.links.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +object OpenLinksDirectlyPrimaryFingerprint : MethodFingerprint( + returnType = "Ljava/lang/Object", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("Ljava/lang/Object"), + opcodes = listOf( + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.RETURN_OBJECT, + Opcode.CHECK_CAST, + Opcode.SGET, + Opcode.SGET_OBJECT + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/links/fingerprints/OpenLinksDirectlySecondaryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/links/fingerprints/OpenLinksDirectlySecondaryFingerprint.kt new file mode 100644 index 0000000000..cdb55bc0f0 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/links/fingerprints/OpenLinksDirectlySecondaryFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.youtube.misc.links.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.Opcode + +object OpenLinksDirectlySecondaryFingerprint : MethodFingerprint( + returnType = "Landroid/net/Uri", + accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC, + parameters = listOf("Ljava/lang/String"), + opcodes = listOf( + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT + ), + strings = listOf("://") +) \ No newline at end of file