From f155e261d4973d304c57e0144ddd8e115e6103ee Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 18 Feb 2023 21:23:29 +0100 Subject: [PATCH] feat(youtube/open-links-directly): skip every redirect url Signed-off-by: oSumAtrIX --- .../OpenLinksDirectlyPrimaryFingerprint.kt | 4 +- .../OpenLinksDirectlySecondaryFingerprint.kt | 14 +---- .../patch/OpenLinksDirectlyPatch.kt | 51 ++++++++----------- 3 files changed, 24 insertions(+), 45 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/fingerprints/OpenLinksDirectlyPrimaryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/fingerprints/OpenLinksDirectlyPrimaryFingerprint.kt index 3cd25f036..19c68c62b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/fingerprints/OpenLinksDirectlyPrimaryFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/fingerprints/OpenLinksDirectlyPrimaryFingerprint.kt @@ -9,11 +9,11 @@ import org.jf.dexlib2.Opcode @OpenLinksDirectlyCompatibility object OpenLinksDirectlyPrimaryFingerprint : 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 + Opcode.SGET, + Opcode.SGET_OBJECT ) ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/fingerprints/OpenLinksDirectlySecondaryFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/fingerprints/OpenLinksDirectlySecondaryFingerprint.kt index 790f02b2b..d10861446 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/fingerprints/OpenLinksDirectlySecondaryFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/fingerprints/OpenLinksDirectlySecondaryFingerprint.kt @@ -9,16 +9,6 @@ import org.jf.dexlib2.Opcode @OpenLinksDirectlyCompatibility object OpenLinksDirectlySecondaryFingerprint : 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") + Opcode.INVOKE_STATIC, Opcode.MOVE_RESULT_OBJECT + ), listOf("://") ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/patch/OpenLinksDirectlyPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/patch/OpenLinksDirectlyPatch.kt index 61548a166..a037bea47 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/patch/OpenLinksDirectlyPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/openlinksdirectly/patch/OpenLinksDirectlyPatch.kt @@ -1,11 +1,12 @@ package app.revanced.patches.youtube.misc.openlinksdirectly.patch +import app.revanced.extensions.toErrorResult 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.extensions.instruction +import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess @@ -18,8 +19,6 @@ import app.revanced.patches.youtube.misc.openlinksdirectly.annotations.OpenLinks import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.OpenLinksDirectlyPrimaryFingerprint import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.OpenLinksDirectlySecondaryFingerprint import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch -import org.jf.dexlib2.iface.instruction.Instruction -import org.jf.dexlib2.iface.instruction.formats.Instruction11x import org.jf.dexlib2.iface.instruction.formats.Instruction35c @Patch @@ -29,9 +28,7 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction35c @OpenLinksDirectlyCompatibility @Version("0.0.1") class OpenLinksDirectlyPatch : BytecodePatch( - listOf( - OpenLinksDirectlyPrimaryFingerprint, OpenLinksDirectlySecondaryFingerprint - ) + listOf(OpenLinksDirectlyPrimaryFingerprint, OpenLinksDirectlySecondaryFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { SettingsPatch.PreferenceScreen.MISC.addPreferences( @@ -44,29 +41,21 @@ class OpenLinksDirectlyPatch : BytecodePatch( ) ) - OpenLinksDirectlyPrimaryFingerprint.hookUriParser(true) - OpenLinksDirectlySecondaryFingerprint.hookUriParser(false) - + arrayOf(OpenLinksDirectlyPrimaryFingerprint, OpenLinksDirectlySecondaryFingerprint) + .map { it.result ?: return it.toErrorResult() } + .forEach { result -> + result.mutableMethod.apply { + val insertIndex = result.scanResult.patternScanResult!!.startIndex + val uriRegister = (instruction(insertIndex) as Instruction35c).registerC + replaceInstruction( + insertIndex, + "invoke-static {v$uriRegister}," + + "Lapp/revanced/integrations/patches/OpenLinksDirectlyPatch;" + + "->" + + "transformRedirectUri(Ljava/lang/String;)Landroid/net/Uri;" + ) + } + } 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 - """ - ) - } -} +} \ No newline at end of file