2023-09-20 05:33:02 +02:00
|
|
|
package app.revanced.patches.youtube.misc.links
|
2023-08-27 21:40:49 +02:00
|
|
|
|
|
|
|
import app.revanced.patcher.data.BytecodeContext
|
|
|
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
2023-09-20 05:33:02 +02:00
|
|
|
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
|
|
|
import app.revanced.patcher.patch.annotation.Patch
|
2023-08-27 21:40:49 +02:00
|
|
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
|
|
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
|
|
|
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
2023-09-20 05:33:02 +02:00
|
|
|
import app.revanced.patches.youtube.misc.settings.SettingsPatch
|
2023-12-02 22:35:13 +01:00
|
|
|
import app.revanced.patches.all.misc.transformation.AbstractTransformInstructionsPatch
|
2023-08-27 21:40:49 +02:00
|
|
|
import com.android.tools.smali.dexlib2.iface.ClassDef
|
|
|
|
import com.android.tools.smali.dexlib2.iface.Method
|
|
|
|
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
|
|
|
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
|
|
|
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
|
|
|
|
import com.android.tools.smali.dexlib2.iface.reference.StringReference
|
|
|
|
|
2023-09-20 05:33:02 +02:00
|
|
|
@Patch(
|
|
|
|
name = "Open links externally",
|
|
|
|
description = "Open links outside of the app directly in your browser.",
|
2023-09-28 01:28:25 +02:00
|
|
|
compatiblePackages = [
|
|
|
|
CompatiblePackage(
|
|
|
|
"com.google.android.youtube",
|
|
|
|
[
|
|
|
|
"18.32.39",
|
2023-10-08 03:37:42 +02:00
|
|
|
"18.37.36",
|
2023-11-12 16:43:11 +01:00
|
|
|
"18.38.44",
|
2023-11-12 17:01:49 +01:00
|
|
|
"18.43.45",
|
|
|
|
"18.44.41",
|
2023-12-02 00:07:29 +01:00
|
|
|
"18.45.41",
|
|
|
|
"18.45.43"
|
2023-09-28 01:28:25 +02:00
|
|
|
]
|
|
|
|
)
|
|
|
|
]
|
2023-09-20 05:33:02 +02:00
|
|
|
)
|
|
|
|
@Suppress("unused")
|
|
|
|
object OpenLinksExternallyPatch : AbstractTransformInstructionsPatch<Pair<Int, Int>>(
|
2023-08-27 21:40:49 +02:00
|
|
|
) {
|
|
|
|
override fun filterMap(
|
|
|
|
classDef: ClassDef, method: Method, instruction: Instruction, instructionIndex: Int
|
|
|
|
): Pair<Int, Int>? {
|
|
|
|
if (instruction !is ReferenceInstruction) return null
|
|
|
|
val reference = instruction.reference as? StringReference ?: return null
|
|
|
|
|
|
|
|
if (reference.string != "android.support.customtabs.action.CustomTabsService") return null
|
|
|
|
|
|
|
|
return instructionIndex to (instruction as OneRegisterInstruction).registerA
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun transform(mutableMethod: MutableMethod, entry: Pair<Int, Int>) {
|
|
|
|
val (intentStringIndex, register) = entry
|
|
|
|
|
|
|
|
// Hook the intent string.
|
|
|
|
mutableMethod.addInstructions(
|
|
|
|
intentStringIndex + 1,
|
|
|
|
"""
|
|
|
|
invoke-static {v$register}, Lapp/revanced/integrations/patches/OpenLinksExternallyPatch;->getIntent(Ljava/lang/String;)Ljava/lang/String;
|
|
|
|
move-result-object v$register
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun execute(context: BytecodeContext) {
|
|
|
|
SettingsPatch.PreferenceScreen.MISC.addPreferences(
|
|
|
|
SwitchPreference(
|
|
|
|
"revanced_external_browser",
|
|
|
|
StringResource("revanced_external_browser_title", "Open links in browser"),
|
|
|
|
StringResource("revanced_external_browser_summary_on", "Opening links externally"),
|
|
|
|
StringResource("revanced_external_browser_summary_off", "Opening links in app")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
super.execute(context)
|
|
|
|
}
|
|
|
|
}
|