fix(YouTube): Do not crash if root installation opens a video in the Play store

BREAKING CHANGE: Integrations hook fingerprints have changed
This commit is contained in:
LisoUseInAIKyrios 2024-04-24 13:03:43 +04:00
parent 5242cbde99
commit 7ce9aad85a
7 changed files with 11 additions and 52 deletions

View File

@ -691,7 +691,6 @@ public final class app/revanced/patches/shared/misc/hex/BaseHexPatch$Replacement
}
public abstract class app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch : app/revanced/patcher/patch/BytecodePatch {
public fun <init> (Ljava/lang/String;Ljava/util/Set;)V
public fun <init> (Ljava/util/Set;)V
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
@ -699,8 +698,6 @@ public abstract class app/revanced/patches/shared/misc/integrations/BaseIntegrat
public abstract class app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch$IntegrationsFingerprint : app/revanced/patcher/fingerprint/MethodFingerprint {
public fun <init> ()V
public fun <init> (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun invoke (Ljava/lang/String;)V
@ -715,11 +712,11 @@ public final class app/revanced/patches/shared/misc/integrations/BaseIntegration
}
public abstract interface class app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch$IntegrationsFingerprint$IRegisterResolver : kotlin/jvm/functions/Function1 {
public abstract fun invoke (Lcom/android/tools/smali/dexlib2/iface/Method;)Ljava/lang/Integer;
public abstract fun invoke (Lcom/android/tools/smali/dexlib2/iface/Method;)Ljava/lang/String;
}
public final class app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch$IntegrationsFingerprint$IRegisterResolver$DefaultImpls {
public static fun invoke (Lapp/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch$IntegrationsFingerprint$IRegisterResolver;Lcom/android/tools/smali/dexlib2/iface/Method;)Ljava/lang/Integer;
public static fun invoke (Lapp/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch$IntegrationsFingerprint$IRegisterResolver;Lcom/android/tools/smali/dexlib2/iface/Method;)Ljava/lang/String;
}
public final class app/revanced/patches/shared/misc/mapping/ResourceMappingPatch : app/revanced/patcher/patch/ResourcePatch {

View File

@ -20,16 +20,6 @@ abstract class BaseIntegrationsPatch(
private val hooks: Set<IntegrationsFingerprint>,
) : BytecodePatch(hooks + setOf(ReVancedUtilsPatchesVersionFingerprint)) {
@Deprecated(
"Use the constructor without the integrationsDescriptor parameter",
ReplaceWith("BaseIntegrationsPatch(hooks)"),
)
@Suppress("UNUSED_PARAMETER")
constructor(
integrationsDescriptor: String,
hooks: Set<IntegrationsFingerprint>,
) : this(hooks)
override fun execute(context: BytecodeContext) {
if (context.findClass(INTEGRATIONS_CLASS_DESCRIPTOR) == null) {
throw PatchException(
@ -96,7 +86,7 @@ abstract class BaseIntegrationsPatch(
strings: Iterable<String>? = null,
customFingerprint: ((methodDef: Method, classDef: ClassDef) -> Boolean)? = null,
private val insertIndexResolver: ((Method) -> Int) = object : IHookInsertIndexResolver {},
private val contextRegisterResolver: (Method) -> Int = object : IRegisterResolver {},
private val contextRegisterResolver: (Method) -> String = object : IRegisterResolver {},
) : MethodFingerprint(
returnType,
accessFlags,
@ -105,29 +95,6 @@ abstract class BaseIntegrationsPatch(
strings,
customFingerprint,
) {
@Deprecated(
"Previous constructor that is missing the insert index." +
"Here only for binary compatibility, " +
"and this can be removed after the next major version update.",
)
constructor(
returnType: String? = null,
accessFlags: Int? = null,
parameters: Iterable<String>? = null,
opcodes: Iterable<Opcode?>? = null,
strings: Iterable<String>? = null,
customFingerprint: ((methodDef: Method, classDef: ClassDef) -> Boolean)? = null,
contextRegisterResolver: (Method) -> Int = object : IRegisterResolver {},
) : this(
returnType,
accessFlags,
parameters,
opcodes,
strings,
customFingerprint,
object : IHookInsertIndexResolver {},
contextRegisterResolver,
)
fun invoke(integrationsDescriptor: String) {
result?.mutableMethod?.let { method ->
@ -136,7 +103,7 @@ abstract class BaseIntegrationsPatch(
method.addInstruction(
insertIndex,
"invoke-static/range { v$contextRegister .. v$contextRegister }, " +
"invoke-static/range { $contextRegister .. $contextRegister }, " +
"$integrationsDescriptor->setContext(Landroid/content/Context;)V",
)
} ?: throw PatchException("Could not find hook target fingerprint.")
@ -146,8 +113,8 @@ abstract class BaseIntegrationsPatch(
override operator fun invoke(method: Method) = 0
}
interface IRegisterResolver : (Method) -> Int {
override operator fun invoke(method: Method) = method.implementation!!.registerCount - 1
interface IRegisterResolver : (Method) -> String {
override operator fun invoke(method: Method) = "p0"
}
}

View File

@ -12,6 +12,5 @@ import com.android.tools.smali.dexlib2.AccessFlags
internal object APIPlayerServiceFingerprint : IntegrationsFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
customFingerprint = { methodDef, _ -> methodDef.definingClass == "Lcom/google/android/apps/youtube/embeddedplayer/service/service/jar/ApiPlayerService;" },
// Integrations context is the first method parameter.
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size }
contextRegisterResolver = { "p1" }
)

View File

@ -17,6 +17,5 @@ internal object EmbeddedPlayerControlsOverlayFingerprint : IntegrationsFingerpri
customFingerprint = { methodDef, _ ->
methodDef.definingClass.startsWith("Lcom/google/android/apps/youtube/embeddedplayer/service/ui/overlays/controlsoverlay/remoteloaded/")
},
// Integrations context is the first method parameter.
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size }
contextRegisterResolver = { "p1" }
)

View File

@ -15,6 +15,5 @@ internal object EmbeddedPlayerFingerprint : IntegrationsFingerprint(
returnType = "L",
parameters = listOf("L", "L", "Landroid/content/Context;"),
strings = listOf("android.hardware.type.television"), // String is also found in other classes
// Integrations context is the third method parameter.
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size + 2 }
contextRegisterResolver = { "p2" }
)

View File

@ -14,6 +14,5 @@ internal object RemoteEmbedFragmentFingerprint : IntegrationsFingerprint(
customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lcom/google/android/apps/youtube/embeddedplayer/service/jar/client/RemoteEmbedFragment;"
},
// Integrations context is the first method parameter.
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size }
contextRegisterResolver = { "p1" }
)

View File

@ -14,6 +14,5 @@ internal object RemoteEmbeddedPlayerFingerprint : IntegrationsFingerprint(
customFingerprint = { methodDef, _ ->
methodDef.definingClass == "Lcom/google/android/youtube/api/jar/client/RemoteEmbeddedPlayer;"
},
// Integrations context is the first method parameter.
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size }
contextRegisterResolver = { "p1" }
)