mirror of
https://github.com/revanced/revanced-patches
synced 2024-12-03 01:22:56 +01:00
refactor(integrations): merge integrations code (#1052)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
08bc92da58
commit
ca459ab5bf
@ -2,13 +2,13 @@ package app.revanced.patches.tiktok.misc.integrations.fingerprints
|
|||||||
|
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import app.revanced.patches.tiktok.misc.integrations.annotations.TikTokIntegrationsCompatibility
|
import app.revanced.patches.tiktok.misc.integrations.annotations.TikTokIntegrationsCompatibility
|
||||||
|
import app.revanced.shared.patches.AbstractIntegrationsPatch.IntegrationsFingerprint
|
||||||
|
|
||||||
@Name("init-fingerprint")
|
@Name("init-fingerprint")
|
||||||
@TikTokIntegrationsCompatibility
|
@TikTokIntegrationsCompatibility
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
object InitFingerprint : MethodFingerprint(
|
object InitFingerprint : IntegrationsFingerprint(
|
||||||
customFingerprint = { methodDef ->
|
customFingerprint = { methodDef ->
|
||||||
methodDef.definingClass.endsWith("/AwemeHostApplication;") &&
|
methodDef.definingClass.endsWith("/AwemeHostApplication;") &&
|
||||||
methodDef.name == "onCreate"
|
methodDef.name == "onCreate"
|
||||||
|
@ -1,38 +1,13 @@
|
|||||||
package app.revanced.patches.tiktok.misc.integrations.patch
|
package app.revanced.patches.tiktok.misc.integrations.patch
|
||||||
|
|
||||||
import app.revanced.patcher.annotation.Description
|
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
|
||||||
import app.revanced.patcher.extensions.addInstruction
|
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
|
||||||
import app.revanced.patcher.patch.PatchResult
|
|
||||||
import app.revanced.patcher.patch.PatchResultError
|
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
|
||||||
import app.revanced.patches.tiktok.misc.integrations.annotations.TikTokIntegrationsCompatibility
|
import app.revanced.patches.tiktok.misc.integrations.annotations.TikTokIntegrationsCompatibility
|
||||||
import app.revanced.patches.tiktok.misc.integrations.fingerprints.InitFingerprint
|
import app.revanced.patches.tiktok.misc.integrations.fingerprints.InitFingerprint
|
||||||
|
import app.revanced.shared.patches.AbstractIntegrationsPatch
|
||||||
|
|
||||||
@Name("tiktok-integrations")
|
@Name("tiktok-integrations")
|
||||||
@Description("Applies mandatory patches to implement the ReVanced integrations into the application.")
|
|
||||||
@TikTokIntegrationsCompatibility
|
@TikTokIntegrationsCompatibility
|
||||||
@Version("0.0.1")
|
class TikTokIntegrationsPatch : AbstractIntegrationsPatch(
|
||||||
class TikTokIntegrationsPatch : BytecodePatch(
|
"Lapp/revanced/tiktok/utils/ReVancedUtils;",
|
||||||
listOf(
|
listOf(InitFingerprint)
|
||||||
InitFingerprint
|
)
|
||||||
)
|
|
||||||
) {
|
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
|
||||||
if (context.findClass("Lapp/revanced/tiktok/utils/ReVancedUtils") == null)
|
|
||||||
return PatchResultError("Integrations have not been merged yet. This patch can not succeed without the integrations.")
|
|
||||||
val result = InitFingerprint.result!!
|
|
||||||
|
|
||||||
val method = result.mutableMethod
|
|
||||||
val implementation = method.implementation!!
|
|
||||||
val count = implementation.registerCount - 1
|
|
||||||
|
|
||||||
method.addInstruction(
|
|
||||||
0, "sput-object v$count, Lapp/revanced/tiktok/utils/ReVancedUtils;->context:Landroid/content/Context;"
|
|
||||||
)
|
|
||||||
return PatchResultSuccess()
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,12 +2,12 @@ package app.revanced.patches.youtube.misc.integrations.fingerprints
|
|||||||
|
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
|
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
|
||||||
|
import app.revanced.shared.patches.AbstractIntegrationsPatch.IntegrationsFingerprint
|
||||||
|
|
||||||
@Name("init-fingerprint")
|
@Name("init-fingerprint")
|
||||||
@IntegrationsCompatibility
|
@IntegrationsCompatibility
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
object InitFingerprint : MethodFingerprint(
|
object InitFingerprint : IntegrationsFingerprint(
|
||||||
strings = listOf("Application creation")
|
strings = listOf("Application creation"),
|
||||||
)
|
)
|
@ -2,12 +2,13 @@ package app.revanced.patches.youtube.misc.integrations.fingerprints
|
|||||||
|
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
|
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
|
||||||
|
import app.revanced.shared.patches.AbstractIntegrationsPatch.IntegrationsFingerprint
|
||||||
|
|
||||||
@Name("service-fingerprint")
|
@Name("service-fingerprint")
|
||||||
@IntegrationsCompatibility
|
@IntegrationsCompatibility
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
object ServiceFingerprint : MethodFingerprint(
|
object ServiceFingerprint : IntegrationsFingerprint(
|
||||||
customFingerprint = { methodDef -> methodDef.definingClass.endsWith("ApiPlayerService;") && methodDef.name == "<init>" }
|
customFingerprint = { methodDef -> methodDef.definingClass.endsWith("ApiPlayerService;") && methodDef.name == "<init>" },
|
||||||
|
contextRegisterResolver = { it.implementation!!.registerCount - it.parameters.size }
|
||||||
)
|
)
|
@ -2,15 +2,15 @@ package app.revanced.patches.youtube.misc.integrations.fingerprints
|
|||||||
|
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
|
||||||
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
|
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
|
||||||
|
import app.revanced.shared.patches.AbstractIntegrationsPatch.IntegrationsFingerprint
|
||||||
|
|
||||||
@Name("standalone-player-fingerprint")
|
@Name("standalone-player-fingerprint")
|
||||||
@IntegrationsCompatibility
|
@IntegrationsCompatibility
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
object StandalonePlayerFingerprint : MethodFingerprint(
|
object StandalonePlayerFingerprint : IntegrationsFingerprint(
|
||||||
strings = listOf(
|
strings = listOf(
|
||||||
"Invalid PlaybackStartDescriptor. Returning the instance itself.",
|
"Invalid PlaybackStartDescriptor. Returning the instance itself.",
|
||||||
"com.google.android.music",
|
"com.google.android.music",
|
||||||
)
|
),
|
||||||
)
|
)
|
@ -1,59 +1,15 @@
|
|||||||
package app.revanced.patches.youtube.misc.integrations.patch
|
package app.revanced.patches.youtube.misc.integrations.patch
|
||||||
|
|
||||||
import app.revanced.patcher.annotation.Description
|
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
|
||||||
import app.revanced.patcher.extensions.MethodFingerprintExtensions.name
|
|
||||||
import app.revanced.patcher.extensions.addInstruction
|
|
||||||
import app.revanced.patcher.extensions.or
|
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
|
||||||
import app.revanced.patcher.patch.PatchResult
|
|
||||||
import app.revanced.patcher.patch.PatchResultError
|
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
|
||||||
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
|
|
||||||
import app.revanced.patcher.util.smali.toInstructions
|
|
||||||
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
|
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
|
||||||
import app.revanced.patches.youtube.misc.integrations.fingerprints.InitFingerprint
|
import app.revanced.patches.youtube.misc.integrations.fingerprints.InitFingerprint
|
||||||
import app.revanced.patches.youtube.misc.integrations.fingerprints.ServiceFingerprint
|
import app.revanced.patches.youtube.misc.integrations.fingerprints.ServiceFingerprint
|
||||||
import app.revanced.patches.youtube.misc.integrations.fingerprints.StandalonePlayerFingerprint
|
import app.revanced.patches.youtube.misc.integrations.fingerprints.StandalonePlayerFingerprint
|
||||||
import org.jf.dexlib2.AccessFlags
|
import app.revanced.shared.patches.AbstractIntegrationsPatch
|
||||||
import org.jf.dexlib2.immutable.ImmutableMethod
|
|
||||||
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
|
|
||||||
|
|
||||||
@Name("integrations")
|
@Name("integrations")
|
||||||
@Description("Applies mandatory patches to implement the ReVanced integrations into the application.")
|
|
||||||
@IntegrationsCompatibility
|
@IntegrationsCompatibility
|
||||||
@Version("0.0.1")
|
class IntegrationsPatch : AbstractIntegrationsPatch(
|
||||||
class IntegrationsPatch : BytecodePatch(
|
"Lapp/revanced/integrations/utils/ReVancedUtils;",
|
||||||
listOf(
|
listOf(InitFingerprint, StandalonePlayerFingerprint, ServiceFingerprint),
|
||||||
InitFingerprint, StandalonePlayerFingerprint, ServiceFingerprint
|
)
|
||||||
)
|
|
||||||
) {
|
|
||||||
companion object {
|
|
||||||
private const val INTEGRATIONS_DESCRIPTOR = "Lapp/revanced/integrations/utils/ReVancedUtils;"
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
|
||||||
if (context.findClass(INTEGRATIONS_DESCRIPTOR) == null)
|
|
||||||
return PatchResultError("Integrations have not been merged yet. This patch can not succeed without merging the integrations.")
|
|
||||||
|
|
||||||
arrayOf(InitFingerprint, StandalonePlayerFingerprint, ServiceFingerprint).map {
|
|
||||||
it to (it.result ?: return PatchResultError("${it.name} failed to resolve"))
|
|
||||||
}.forEach { (fingerprint, result) ->
|
|
||||||
with(result.mutableMethod) {
|
|
||||||
// parameter which holds the context
|
|
||||||
val contextParameter = if (fingerprint == ServiceFingerprint) parameters.size else 1
|
|
||||||
// register which holds the context
|
|
||||||
val contextRegister = implementation!!.registerCount - contextParameter
|
|
||||||
|
|
||||||
addInstruction(
|
|
||||||
0,
|
|
||||||
"sput-object v$contextRegister, $INTEGRATIONS_DESCRIPTOR->context:Landroid/content/Context;"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return PatchResultSuccess()
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,67 @@
|
|||||||
|
package app.revanced.shared.patches
|
||||||
|
|
||||||
|
import app.revanced.patcher.annotation.Description
|
||||||
|
import app.revanced.patcher.annotation.Version
|
||||||
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
|
import app.revanced.patcher.extensions.addInstruction
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
|
import app.revanced.patcher.patch.PatchResult
|
||||||
|
import app.revanced.patcher.patch.PatchResultError
|
||||||
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
|
import app.revanced.shared.patches.AbstractIntegrationsPatch.IntegrationsFingerprint.RegisterResolver
|
||||||
|
import org.jf.dexlib2.iface.Method
|
||||||
|
|
||||||
|
@Description("Applies mandatory patches to implement the ReVanced integrations into the application.")
|
||||||
|
@Version("0.0.1")
|
||||||
|
abstract class AbstractIntegrationsPatch(
|
||||||
|
private val integrationsDescriptor: String,
|
||||||
|
private val hooks: Iterable<IntegrationsFingerprint>
|
||||||
|
) : BytecodePatch(hooks) {
|
||||||
|
/**
|
||||||
|
* [MethodFingerprint] for integrations.
|
||||||
|
*
|
||||||
|
* @param contextRegisterResolver A [RegisterResolver] to get the register.
|
||||||
|
* @see MethodFingerprint
|
||||||
|
*/
|
||||||
|
abstract class IntegrationsFingerprint(
|
||||||
|
strings: Iterable<String>? = null,
|
||||||
|
customFingerprint: ((methodDef: Method) -> Boolean)? = null,
|
||||||
|
private val contextRegisterResolver: (Method) -> Int = object : RegisterResolver {}
|
||||||
|
) : MethodFingerprint(strings = strings, customFingerprint = customFingerprint) {
|
||||||
|
fun invoke(integrationsDescriptor: String): PatchResult {
|
||||||
|
result?.mutableMethod?.let { method ->
|
||||||
|
val contextRegister = contextRegisterResolver(method)
|
||||||
|
|
||||||
|
method.addInstruction(
|
||||||
|
0,
|
||||||
|
"sput-object v$contextRegister, " +
|
||||||
|
"$integrationsDescriptor->context:Landroid/content/Context;"
|
||||||
|
)
|
||||||
|
} ?: return PatchResultError("Could not find hook target fingerprint.")
|
||||||
|
|
||||||
|
return PatchResultSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RegisterResolver : (Method) -> Int {
|
||||||
|
override operator fun invoke(method: Method) = method.implementation!!.registerCount - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
|
if (context.findClass(integrationsDescriptor) == null) return MISSING_INTEGRATIONS
|
||||||
|
|
||||||
|
for (hook in hooks) hook.invoke(integrationsDescriptor).let {
|
||||||
|
if (it is PatchResultError) return it
|
||||||
|
}
|
||||||
|
|
||||||
|
return PatchResultSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
val MISSING_INTEGRATIONS = PatchResultError(
|
||||||
|
"Integrations have not been merged yet. " +
|
||||||
|
"This patch can not succeed without merging the integrations."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user