fix(TikTok): Hook application context earlier to prevent crash (#2893)
This commit is contained in:
parent
22a6905e2e
commit
395ccda7b9
|
@ -628,9 +628,19 @@ public abstract class app/revanced/patches/shared/misc/integrations/BaseIntegrat
|
||||||
public fun <init> ()V
|
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 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 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
|
public final fun invoke (Ljava/lang/String;)V
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract interface class app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch$IntegrationsFingerprint$IHookInsertIndexResolver : kotlin/jvm/functions/Function1 {
|
||||||
|
public abstract fun invoke (Lcom/android/tools/smali/dexlib2/iface/Method;)Ljava/lang/Integer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch$IntegrationsFingerprint$IHookInsertIndexResolver$DefaultImpls {
|
||||||
|
public static fun invoke (Lapp/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch$IntegrationsFingerprint$IHookInsertIndexResolver;Lcom/android/tools/smali/dexlib2/iface/Method;)Ljava/lang/Integer;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract interface class app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch$IntegrationsFingerprint$IRegisterResolver : kotlin/jvm/functions/Function1 {
|
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/Integer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,8 @@ abstract class BaseIntegrationsPatch(
|
||||||
opcodes: Iterable<Opcode?>? = null,
|
opcodes: Iterable<Opcode?>? = null,
|
||||||
strings: Iterable<String>? = null,
|
strings: Iterable<String>? = null,
|
||||||
customFingerprint: ((methodDef: Method, classDef: ClassDef) -> Boolean)? = null,
|
customFingerprint: ((methodDef: Method, classDef: ClassDef) -> Boolean)? = null,
|
||||||
private val contextRegisterResolver: (Method) -> Int = object : IRegisterResolver {},
|
private val insertIndexResolver: ((Method) -> Int) = object : IHookInsertIndexResolver {},
|
||||||
|
private val contextRegisterResolver: (Method) -> Int = object : IRegisterResolver {}
|
||||||
) : MethodFingerprint(
|
) : MethodFingerprint(
|
||||||
returnType,
|
returnType,
|
||||||
accessFlags,
|
accessFlags,
|
||||||
|
@ -58,18 +59,45 @@ abstract class BaseIntegrationsPatch(
|
||||||
strings,
|
strings,
|
||||||
customFingerprint,
|
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) {
|
fun invoke(integrationsDescriptor: String) {
|
||||||
result?.mutableMethod?.let { method ->
|
result?.mutableMethod?.let { method ->
|
||||||
|
val insertIndex = insertIndexResolver(method)
|
||||||
val contextRegister = contextRegisterResolver(method)
|
val contextRegister = contextRegisterResolver(method)
|
||||||
|
|
||||||
method.addInstruction(
|
method.addInstruction(
|
||||||
0,
|
insertIndex,
|
||||||
"invoke-static/range { v$contextRegister .. v$contextRegister }, " +
|
"invoke-static/range { v$contextRegister .. v$contextRegister }, " +
|
||||||
"$integrationsDescriptor->setContext(Landroid/content/Context;)V",
|
"$integrationsDescriptor->setContext(Landroid/content/Context;)V",
|
||||||
)
|
)
|
||||||
} ?: throw PatchException("Could not find hook target fingerprint.")
|
} ?: throw PatchException("Could not find hook target fingerprint.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IHookInsertIndexResolver : (Method) -> Int {
|
||||||
|
override operator fun invoke(method: Method) = 0
|
||||||
|
}
|
||||||
|
|
||||||
interface IRegisterResolver : (Method) -> Int {
|
interface IRegisterResolver : (Method) -> Int {
|
||||||
override operator fun invoke(method: Method) = method.implementation!!.registerCount - 1
|
override operator fun invoke(method: Method) = method.implementation!!.registerCount - 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package app.revanced.patches.tiktok.misc.integrations.fingerprints
|
package app.revanced.patches.tiktok.misc.integrations.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.extensions.or
|
||||||
import app.revanced.patches.shared.misc.integrations.BaseIntegrationsPatch.IntegrationsFingerprint
|
import app.revanced.patches.shared.misc.integrations.BaseIntegrationsPatch.IntegrationsFingerprint
|
||||||
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
|
||||||
internal object InitFingerprint : IntegrationsFingerprint(
|
internal object InitFingerprint : IntegrationsFingerprint(
|
||||||
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||||
customFingerprint = { methodDef, _ ->
|
customFingerprint = { methodDef, _ ->
|
||||||
methodDef.definingClass.endsWith("/AwemeHostApplication;") &&
|
methodDef.definingClass.endsWith("/AwemeHostApplication;") &&
|
||||||
methodDef.name == "onCreate"
|
methodDef.name == "<init>"
|
||||||
}
|
},
|
||||||
|
insertIndexResolver = { 1 } // Insert after call to super class.
|
||||||
)
|
)
|
Loading…
Reference in a new issue