fix(youtube/integrations): set context for remaining activities (#828)

This commit is contained in:
Canny 2022-10-22 13:45:10 +03:00 committed by GitHub
parent 8d73183a6c
commit ba9cbaf127
3 changed files with 53 additions and 30 deletions

View File

@ -0,0 +1,13 @@
package app.revanced.patches.youtube.misc.integrations.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
@Name("service-fingerprint")
@IntegrationsCompatibility
@Version("0.0.1")
object ServiceFingerprint : MethodFingerprint(
customFingerprint = { methodDef -> methodDef.definingClass.endsWith("ApiPlayerService;") && methodDef.name == "<init>" }
)

View File

@ -0,0 +1,16 @@
package app.revanced.patches.youtube.misc.integrations.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.youtube.misc.integrations.annotations.IntegrationsCompatibility
@Name("standalone-player-fingerprint")
@IntegrationsCompatibility
@Version("0.0.1")
object StandalonePlayerFingerprint : MethodFingerprint(
strings = listOf(
"Invalid PlaybackStartDescriptor. Returning the instance itself.",
"com.google.android.music",
)
)

View File

@ -4,6 +4,7 @@ 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.annotation.Version
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.MethodFingerprintExtensions.name
import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.or import app.revanced.patcher.extensions.or
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
@ -14,6 +15,8 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMu
import app.revanced.patcher.util.smali.toInstructions 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.StandalonePlayerFingerprint
import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.immutable.ImmutableMethod import org.jf.dexlib2.immutable.ImmutableMethod
import org.jf.dexlib2.immutable.ImmutableMethodImplementation import org.jf.dexlib2.immutable.ImmutableMethodImplementation
@ -24,42 +27,33 @@ import org.jf.dexlib2.immutable.ImmutableMethodImplementation
@Version("0.0.1") @Version("0.0.1")
class IntegrationsPatch : BytecodePatch( class IntegrationsPatch : BytecodePatch(
listOf( listOf(
InitFingerprint InitFingerprint, StandalonePlayerFingerprint, ServiceFingerprint
) )
) { ) {
companion object {
private const val INTEGRATIONS_DESCRIPTOR = "Lapp/revanced/integrations/utils/ReVancedUtils;"
}
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
if (context.findClass("Lapp/revanced/integrations/utils/ReVancedUtils") == null) if (context.findClass(INTEGRATIONS_DESCRIPTOR) == null)
return PatchResultError("Integrations have not been merged yet. This patch can not succeed without the integrations.") return PatchResultError("Integrations have not been merged yet. This patch can not succeed without merging the integrations.")
val result = InitFingerprint.result!! 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
val method = result.mutableMethod addInstruction(
val implementation = method.implementation!! 0,
val count = implementation.registerCount - 1 "sput-object v$contextRegister, $INTEGRATIONS_DESCRIPTOR->context:Landroid/content/Context;"
method.addInstruction(
0, "sput-object v$count, Lapp/revanced/integrations/utils/ReVancedUtils;->context:Landroid/content/Context;"
)
val classDef = result.mutableClass
classDef.methods.add(
ImmutableMethod(
classDef.type,
"getAppContext",
null,
"Landroid/content/Context;",
AccessFlags.PUBLIC or AccessFlags.STATIC,
null,
null,
ImmutableMethodImplementation(
1, """
invoke-static { }, Lapp/revanced/integrations/utils/ReVancedUtils;->getAppContext()Landroid/content/Context;
move-result-object v0
return-object v0
""".toInstructions(), null, null
) )
).toMutable() }
) }
return PatchResultSuccess() return PatchResultSuccess()
} }
} }