refactor: enable-open-links-directly patch now applies to all URLs, not just video descriptions

This commit is contained in:
inotia00 2023-02-18 14:46:29 +09:00
parent b9931deca4
commit 03f2ee8e11
3 changed files with 22 additions and 42 deletions

View File

@ -8,13 +8,13 @@ import org.jf.dexlib2.Opcode
object OpenLinksDirectlyFingerprintPrimary : MethodFingerprint(
returnType = "Ljava/lang/Object",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L"),
parameters = listOf("Ljava/lang/Object"),
opcodes = listOf(
Opcode.CHECK_CAST,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.RETURN_OBJECT,
Opcode.CHECK_CAST,
Opcode.SGET
Opcode.SGET,
Opcode.SGET_OBJECT
)
)

View File

@ -6,20 +6,12 @@ import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object OpenLinksDirectlyFingerprintSecondary : MethodFingerprint(
returnType = "L",
returnType = "Landroid/net/Uri",
access = AccessFlags.PUBLIC or AccessFlags.STATIC,
parameters = listOf("L"),
parameters = listOf("Ljava/lang/String"),
opcodes = 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
Opcode.MOVE_RESULT_OBJECT
),
strings = listOf("Uri must have an absolute scheme")
strings = listOf("://")
)

View File

@ -5,19 +5,17 @@ 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.MethodFingerprintResult
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.patch.BytecodePatch
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.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.openlinksdirectly.fingerprints.*
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.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.MISC_PATH
import org.jf.dexlib2.iface.instruction.Instruction
import org.jf.dexlib2.iface.instruction.formats.Instruction11x
import org.jf.dexlib2.iface.instruction.formats.Instruction35c
@Patch
@ -35,10 +33,18 @@ class OpenLinksDirectlyPatch : BytecodePatch(
override fun execute(context: BytecodeContext): PatchResult {
arrayOf(
OpenLinksDirectlyFingerprintPrimary to true,
OpenLinksDirectlyFingerprintSecondary to false
).map { (fingerprint, boolean) ->
fingerprint.result?.hookUriParser(boolean) ?: return fingerprint.toErrorResult()
OpenLinksDirectlyFingerprintPrimary,
OpenLinksDirectlyFingerprintSecondary
).forEach {
val result = it.result?: return it.toErrorResult()
val insertIndex = result.scanResult.patternScanResult!!.startIndex
with (result.mutableMethod) {
val register = (implementation!!.instructions[insertIndex] as Instruction35c).registerC
replaceInstruction(
insertIndex,
"invoke-static {v$register}, $MISC_PATH/OpenLinksDirectlyPatch;->enableBypassRedirect(Ljava/lang/String;)Landroid/net/Uri;"
)
}
}
/*
@ -55,21 +61,3 @@ class OpenLinksDirectlyPatch : BytecodePatch(
return PatchResultSuccess()
}
}
fun MethodFingerprintResult.hookUriParser(isPrimaryFingerprint: Boolean) {
fun getTargetRegister(instruction: Instruction): Int {
if (isPrimaryFingerprint) return (instruction as Instruction35c).registerC
return (instruction as Instruction11x).registerA
}
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}, $MISC_PATH/OpenLinksDirectlyPatch;->enableBypassRedirect(Ljava/lang/String;)Ljava/lang/String;
move-result-object v$targetRegister
"""
)
}