generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): Add
Bypass URL redirects
patch
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
src/main/kotlin/app/revanced/patches/youtube/misc/links/BypassURLRedirectsPatch.kt
This file contains 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.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<FiveRegisterInstruction>(insertIndex).registerC | ||
|
||
replaceInstruction( | ||
insertIndex, | ||
"invoke-static {v$uriStringRegister}," + | ||
"Lapp/revanced/integrations/patches/BypassURLRedirectsPatch;" + | ||
"->" + | ||
"parseRedirectUri(Ljava/lang/String;)Landroid/net/Uri;" | ||
) | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...p/revanced/patches/youtube/misc/links/fingerprints/OpenLinksDirectlyPrimaryFingerprint.kt
This file contains 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,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 | ||
) | ||
) |
17 changes: 17 additions & 0 deletions
17
...revanced/patches/youtube/misc/links/fingerprints/OpenLinksDirectlySecondaryFingerprint.kt
This file contains 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,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("://") | ||
) |