fix(GmsCore support): Insert check after necessary context hook
This commit is contained in:
parent
784bcdace4
commit
03e8e3d75c
5 changed files with 27 additions and 11 deletions
|
|
@ -11,7 +11,7 @@ import app.revanced.patches.shared.misc.gms.gmsCoreSupportResourcePatch
|
||||||
val gmsCoreSupportPatch = gmsCoreSupportPatch(
|
val gmsCoreSupportPatch = gmsCoreSupportPatch(
|
||||||
fromPackageName = MAGAZINES_PACKAGE_NAME,
|
fromPackageName = MAGAZINES_PACKAGE_NAME,
|
||||||
toPackageName = REVANCED_MAGAZINES_PACKAGE_NAME,
|
toPackageName = REVANCED_MAGAZINES_PACKAGE_NAME,
|
||||||
mainActivityOnCreateFingerprint = magazinesActivityOnCreateFingerprint,
|
mainActivityOnCreateFingerprintToInsertIndex = magazinesActivityOnCreateFingerprint to { 0 },
|
||||||
extensionPatch = extensionPatch,
|
extensionPatch = extensionPatch,
|
||||||
gmsCoreSupportResourcePatchFactory = ::gmsCoreSupportResourcePatch,
|
gmsCoreSupportResourcePatchFactory = ::gmsCoreSupportResourcePatch,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,24 @@ import app.revanced.patches.googlephotos.misc.extension.extensionPatch
|
||||||
import app.revanced.patches.googlephotos.misc.gms.Constants.PHOTOS_PACKAGE_NAME
|
import app.revanced.patches.googlephotos.misc.gms.Constants.PHOTOS_PACKAGE_NAME
|
||||||
import app.revanced.patches.googlephotos.misc.gms.Constants.REVANCED_PHOTOS_PACKAGE_NAME
|
import app.revanced.patches.googlephotos.misc.gms.Constants.REVANCED_PHOTOS_PACKAGE_NAME
|
||||||
import app.revanced.patches.shared.misc.gms.gmsCoreSupportPatch
|
import app.revanced.patches.shared.misc.gms.gmsCoreSupportPatch
|
||||||
|
import app.revanced.util.getReference
|
||||||
|
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||||
|
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
val gmsCoreSupportPatch = gmsCoreSupportPatch(
|
val gmsCoreSupportPatch = gmsCoreSupportPatch(
|
||||||
fromPackageName = PHOTOS_PACKAGE_NAME,
|
fromPackageName = PHOTOS_PACKAGE_NAME,
|
||||||
toPackageName = REVANCED_PHOTOS_PACKAGE_NAME,
|
toPackageName = REVANCED_PHOTOS_PACKAGE_NAME,
|
||||||
mainActivityOnCreateFingerprint = homeActivityOnCreateFingerprint,
|
mainActivityOnCreateFingerprintToInsertIndex = homeActivityOnCreateFingerprint to {
|
||||||
|
val index = homeActivityOnCreateFingerprint.method.indexOfFirstInstructionOrThrow {
|
||||||
|
getReference<MethodReference>()?.name == "getApplicationContext"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Below the move-result-object instruction,
|
||||||
|
// because the extension patch is used by the GmsCore support patch
|
||||||
|
// which hooks the getApplicationContext call.
|
||||||
|
index + 2
|
||||||
|
},
|
||||||
extensionPatch = extensionPatch,
|
extensionPatch = extensionPatch,
|
||||||
gmsCoreSupportResourcePatchFactory = ::gmsCoreSupportResourcePatch,
|
gmsCoreSupportResourcePatchFactory = ::gmsCoreSupportResourcePatch,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ val gmsCoreSupportPatch = gmsCoreSupportPatch(
|
||||||
earlyReturnFingerprints = setOf(
|
earlyReturnFingerprints = setOf(
|
||||||
castContextFetchFingerprint,
|
castContextFetchFingerprint,
|
||||||
),
|
),
|
||||||
mainActivityOnCreateFingerprint = musicActivityOnCreateFingerprint,
|
mainActivityOnCreateFingerprintToInsertIndex = musicActivityOnCreateFingerprint to { 0 },
|
||||||
extensionPatch = sharedExtensionPatch,
|
extensionPatch = sharedExtensionPatch,
|
||||||
gmsCoreSupportResourcePatchFactory = ::gmsCoreSupportResourcePatch,
|
gmsCoreSupportResourcePatchFactory = ::gmsCoreSupportResourcePatch,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ private const val PACKAGE_NAME_REGEX_PATTERN = "^[a-z]\\w*(\\.[a-z]\\w*)+\$"
|
||||||
* @param toPackageName The package name to fall back to if no custom package name is specified in patch options.
|
* @param toPackageName The package name to fall back to if no custom package name is specified in patch options.
|
||||||
* @param primeMethodFingerprint The fingerprint of the "prime" method that needs to be patched.
|
* @param primeMethodFingerprint The fingerprint of the "prime" method that needs to be patched.
|
||||||
* @param earlyReturnFingerprints The fingerprints of methods that need to be returned early.
|
* @param earlyReturnFingerprints The fingerprints of methods that need to be returned early.
|
||||||
* @param mainActivityOnCreateFingerprint The fingerprint of the main activity onCreate method.
|
* @param mainActivityOnCreateFingerprintToInsertIndex The fingerprint of the main activity onCreate method
|
||||||
|
* and a function to get the index to insert the GmsCore check instruction at.
|
||||||
* @param extensionPatch The patch responsible for the extension.
|
* @param extensionPatch The patch responsible for the extension.
|
||||||
* @param gmsCoreSupportResourcePatchFactory The factory for the corresponding resource patch
|
* @param gmsCoreSupportResourcePatchFactory The factory for the corresponding resource patch
|
||||||
* that is used to patch the resources.
|
* that is used to patch the resources.
|
||||||
|
|
@ -47,7 +48,7 @@ fun gmsCoreSupportPatch(
|
||||||
toPackageName: String,
|
toPackageName: String,
|
||||||
primeMethodFingerprint: Fingerprint? = null,
|
primeMethodFingerprint: Fingerprint? = null,
|
||||||
earlyReturnFingerprints: Set<Fingerprint> = setOf(),
|
earlyReturnFingerprints: Set<Fingerprint> = setOf(),
|
||||||
mainActivityOnCreateFingerprint: Fingerprint,
|
mainActivityOnCreateFingerprintToInsertIndex: Pair<Fingerprint, BytecodePatchContext.() -> Int>,
|
||||||
extensionPatch: Patch<*>,
|
extensionPatch: Patch<*>,
|
||||||
gmsCoreSupportResourcePatchFactory: (gmsCoreVendorGroupIdOption: Option<String>) -> Patch<*>,
|
gmsCoreSupportResourcePatchFactory: (gmsCoreVendorGroupIdOption: Option<String>) -> Patch<*>,
|
||||||
executeBlock: BytecodePatchContext.() -> Unit = {},
|
executeBlock: BytecodePatchContext.() -> Unit = {},
|
||||||
|
|
@ -189,11 +190,14 @@ fun gmsCoreSupportPatch(
|
||||||
originalPackageNameExtensionFingerprint.method.returnEarly(fromPackageName)
|
originalPackageNameExtensionFingerprint.method.returnEarly(fromPackageName)
|
||||||
|
|
||||||
// Verify GmsCore is installed and whitelisted for power optimizations and background usage.
|
// Verify GmsCore is installed and whitelisted for power optimizations and background usage.
|
||||||
mainActivityOnCreateFingerprint.method.addInstruction(
|
|
||||||
0,
|
mainActivityOnCreateFingerprintToInsertIndex.let { (fingerprint, getInsertIndex) ->
|
||||||
"invoke-static/range { p0 .. p0 }, $EXTENSION_CLASS_DESCRIPTOR->" +
|
fingerprint.method.addInstruction(
|
||||||
"checkGmsCore(Landroid/app/Activity;)V",
|
getInsertIndex(),
|
||||||
)
|
"invoke-static/range { p0 .. p0 }, $EXTENSION_CLASS_DESCRIPTOR->" +
|
||||||
|
"checkGmsCore(Landroid/app/Activity;)V",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Change the vendor of GmsCore in the extension.
|
// Change the vendor of GmsCore in the extension.
|
||||||
getGmsCoreVendorGroupIdFingerprint.method.returnEarly(gmsCoreVendorGroupId)
|
getGmsCoreVendorGroupIdFingerprint.method.returnEarly(gmsCoreVendorGroupId)
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ val gmsCoreSupportPatch = gmsCoreSupportPatch(
|
||||||
earlyReturnFingerprints = setOf(
|
earlyReturnFingerprints = setOf(
|
||||||
castContextFetchFingerprint,
|
castContextFetchFingerprint,
|
||||||
),
|
),
|
||||||
mainActivityOnCreateFingerprint = mainActivityOnCreateFingerprint,
|
mainActivityOnCreateFingerprintToInsertIndex = mainActivityOnCreateFingerprint to { 0 },
|
||||||
extensionPatch = sharedExtensionPatch,
|
extensionPatch = sharedExtensionPatch,
|
||||||
gmsCoreSupportResourcePatchFactory = ::gmsCoreSupportResourcePatch,
|
gmsCoreSupportResourcePatchFactory = ::gmsCoreSupportResourcePatch,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue