feat(youtube/open-links-directly): skip every redirect url

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
oSumAtrIX 2023-02-18 21:23:29 +01:00
parent 8e37e0e39d
commit f155e261d4
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 24 additions and 45 deletions

View File

@ -9,11 +9,11 @@ import org.jf.dexlib2.Opcode
@OpenLinksDirectlyCompatibility @OpenLinksDirectlyCompatibility
object OpenLinksDirectlyPrimaryFingerprint : MethodFingerprint( object OpenLinksDirectlyPrimaryFingerprint : MethodFingerprint(
"L", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("L"), listOf( "L", AccessFlags.PUBLIC or AccessFlags.FINAL, listOf("L"), listOf(
Opcode.CHECK_CAST,
Opcode.INVOKE_STATIC, Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT, Opcode.MOVE_RESULT_OBJECT,
Opcode.RETURN_OBJECT, Opcode.RETURN_OBJECT,
Opcode.CHECK_CAST, Opcode.CHECK_CAST,
Opcode.SGET Opcode.SGET,
Opcode.SGET_OBJECT
) )
) )

View File

@ -9,16 +9,6 @@ import org.jf.dexlib2.Opcode
@OpenLinksDirectlyCompatibility @OpenLinksDirectlyCompatibility
object OpenLinksDirectlySecondaryFingerprint : MethodFingerprint( object OpenLinksDirectlySecondaryFingerprint : MethodFingerprint(
"L", AccessFlags.PUBLIC or AccessFlags.STATIC, listOf("L"), listOf( "L", AccessFlags.PUBLIC or AccessFlags.STATIC, listOf("L"), listOf(
Opcode.INVOKE_STATIC, Opcode.INVOKE_STATIC, Opcode.MOVE_RESULT_OBJECT
Opcode.MOVE_RESULT_OBJECT, ), listOf("://")
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")
) )

View File

@ -1,11 +1,12 @@
package app.revanced.patches.youtube.misc.openlinksdirectly.patch package app.revanced.patches.youtube.misc.openlinksdirectly.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess 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.OpenLinksDirectlyPrimaryFingerprint
import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.OpenLinksDirectlySecondaryFingerprint import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.OpenLinksDirectlySecondaryFingerprint
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch 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 import org.jf.dexlib2.iface.instruction.formats.Instruction35c
@Patch @Patch
@ -29,9 +28,7 @@ import org.jf.dexlib2.iface.instruction.formats.Instruction35c
@OpenLinksDirectlyCompatibility @OpenLinksDirectlyCompatibility
@Version("0.0.1") @Version("0.0.1")
class OpenLinksDirectlyPatch : BytecodePatch( class OpenLinksDirectlyPatch : BytecodePatch(
listOf( listOf(OpenLinksDirectlyPrimaryFingerprint, OpenLinksDirectlySecondaryFingerprint)
OpenLinksDirectlyPrimaryFingerprint, OpenLinksDirectlySecondaryFingerprint
)
) { ) {
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
SettingsPatch.PreferenceScreen.MISC.addPreferences( SettingsPatch.PreferenceScreen.MISC.addPreferences(
@ -44,29 +41,21 @@ class OpenLinksDirectlyPatch : BytecodePatch(
) )
) )
OpenLinksDirectlyPrimaryFingerprint.hookUriParser(true) arrayOf(OpenLinksDirectlyPrimaryFingerprint, OpenLinksDirectlySecondaryFingerprint)
OpenLinksDirectlySecondaryFingerprint.hookUriParser(false) .map { it.result ?: return it.toErrorResult() }
.forEach { result ->
return PatchResultSuccess() result.mutableMethod.apply {
} val insertIndex = result.scanResult.patternScanResult!!.startIndex
} val uriRegister = (instruction(insertIndex) as Instruction35c).registerC
replaceInstruction(
fun MethodFingerprint.hookUriParser(isPrimaryFingerprint: Boolean) { insertIndex,
fun getTargetRegister(instruction: Instruction): Int { "invoke-static {v$uriRegister}," +
if (isPrimaryFingerprint) return (instruction as Instruction35c).registerC "Lapp/revanced/integrations/patches/OpenLinksDirectlyPatch;" +
return (instruction as Instruction11x).registerA "->" +
} "transformRedirectUri(Ljava/lang/String;)Landroid/net/Uri;"
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
"""
) )
} }
} }
return PatchResultSuccess()
}
}