generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube):
open-links-directly
patch (#999)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
1 parent
88eca1e
commit eae9359
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...nced/patches/youtube/misc/openlinksdirectly/annotations/OpenLinksDirectlyCompatibility.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,13 @@ | ||
package app.revanced.patches.youtube.misc.openlinksdirectly.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.34.36", "17.36.39", "17.38.36", "17.39.35" , "17.40.41", "17.42.35", "17.43.36") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class OpenLinksDirectlyCompatibility |
23 changes: 23 additions & 0 deletions
23
...atches/youtube/misc/openlinksdirectly/fingerprints/OpenLinksDirectlyFingerprintPrimary.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,23 @@ | ||
package app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.misc.openlinksdirectly.annotations.OpenLinksDirectlyCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("open-links-directly-primary-fingerprint") | ||
@OpenLinksDirectlyCompatibility | ||
@Version("0.0.1") | ||
object OpenLinksDirectlyFingerprintPrimary : MethodFingerprint( | ||
"L", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("L"), listOf( | ||
Opcode.CHECK_CAST, | ||
Opcode.INVOKE_STATIC, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.RETURN_OBJECT, | ||
Opcode.CHECK_CAST, | ||
Opcode.SGET | ||
) | ||
) |
28 changes: 28 additions & 0 deletions
28
...ches/youtube/misc/openlinksdirectly/fingerprints/OpenLinksDirectlyFingerprintSecondary.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,28 @@ | ||
package app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints | ||
|
||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.misc.openlinksdirectly.annotations.OpenLinksDirectlyCompatibility | ||
import org.jf.dexlib2.AccessFlags | ||
import org.jf.dexlib2.Opcode | ||
|
||
@Name("open-links-directly-secondary-fingerprint") | ||
@OpenLinksDirectlyCompatibility | ||
@Version("0.0.1") | ||
object OpenLinksDirectlyFingerprintSecondary : MethodFingerprint( | ||
"L", AccessFlags.PUBLIC or AccessFlags.STATIC, listOf("L"), listOf( | ||
Opcode.INVOKE_STATIC, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.INVOKE_STATIC, | ||
Opcode.MOVE_RESULT_OBJECT, | ||
Opcode.INVOKE_VIRTUAL, | ||
Opcode.MOVE_RESULT, | ||
Opcode.IF_EQZ, | ||
Opcode.RETURN_OBJECT, | ||
Opcode.NEW_INSTANCE, | ||
Opcode.CONST_STRING | ||
), | ||
strings = listOf("Uri must have an absolute scheme") | ||
) |
72 changes: 72 additions & 0 deletions
72
...otlin/app/revanced/patches/youtube/misc/openlinksdirectly/patch/OpenLinksDirectlyPatch.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,72 @@ | ||
package app.revanced.patches.youtube.misc.openlinksdirectly.patch | ||
|
||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.addInstructions | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch | ||
import app.revanced.patches.youtube.misc.openlinksdirectly.annotations.OpenLinksDirectlyCompatibility | ||
import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.OpenLinksDirectlyFingerprintPrimary | ||
import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.OpenLinksDirectlyFingerprintSecondary | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource | ||
import app.revanced.patches.youtube.misc.settings.framework.components.impl.SwitchPreference | ||
import org.jf.dexlib2.iface.instruction.Instruction | ||
import org.jf.dexlib2.iface.instruction.formats.Instruction11x | ||
import org.jf.dexlib2.iface.instruction.formats.Instruction35c | ||
|
||
@Patch | ||
@DependsOn([IntegrationsPatch::class, SettingsPatch::class]) | ||
@Name("open-links-directly") | ||
@Description("Bypasses redirect links and allows opening links directly.") | ||
@OpenLinksDirectlyCompatibility | ||
@Version("0.0.1") | ||
class OpenLinksDirectlyPatch : BytecodePatch( | ||
listOf( | ||
OpenLinksDirectlyFingerprintPrimary, OpenLinksDirectlyFingerprintSecondary | ||
) | ||
) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
SettingsPatch.PreferenceScreen.MISC.addPreferences( | ||
SwitchPreference( | ||
"revanced_uri_redirect", | ||
StringResource("revanced_uri_redirect_title", "Open links directly"), | ||
true, | ||
StringResource("revanced_uri_redirect_summary_on", "Enabled"), | ||
StringResource("revanced_uri_redirect_summary_off", "Disabled") | ||
) | ||
) | ||
|
||
OpenLinksDirectlyFingerprintPrimary.hookUriParser(true) | ||
OpenLinksDirectlyFingerprintSecondary.hookUriParser(false) | ||
|
||
return PatchResultSuccess() | ||
} | ||
} | ||
|
||
fun MethodFingerprint.hookUriParser(isPrimaryFingerprint: Boolean) { | ||
fun getTargetRegister(instruction: Instruction): Int { | ||
if (isPrimaryFingerprint) return (instruction as Instruction35c).registerC | ||
return (instruction as Instruction11x).registerA | ||
} | ||
with(this.result!!) { | ||
val startIndex = scanResult.patternScanResult!!.startIndex | ||
val instruction = method.implementation!!.instructions.elementAt(startIndex + 1) | ||
val insertIndex = if (isPrimaryFingerprint) 1 else 2 | ||
val targetRegister = getTargetRegister(instruction) | ||
|
||
mutableMethod.addInstructions( | ||
startIndex + insertIndex, """ | ||
invoke-static {v$targetRegister}, Lapp/revanced/integrations/patches/OpenLinksDirectlyPatch;->parseRedirectUri(Ljava/lang/String;)Ljava/lang/String; | ||
move-result-object v$targetRegister | ||
""" | ||
) | ||
} | ||
} |