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
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
)
)

View file

@ -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("://")
)

View file

@ -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
"""
)
}
}
}