diff --git a/zygisk/module/jni/module.cpp b/zygisk/module/jni/module.cpp index 41cc9d5..ec352a2 100644 --- a/zygisk/module/jni/module.cpp +++ b/zygisk/module/jni/module.cpp @@ -26,6 +26,15 @@ public: preSpecialize(process); } + void postAppSpecialize(const zygisk::AppSpecializeArgs *args) override { + // Inject if module was loaded, otherwise this would've been unloaded by now (for non-GMS) + if (!moduleDex.empty()) { + LOGD("Injecting payload..."); + injectPayload(); + LOGI("Payload injected"); + } + } + private: zygisk::Api *api; JNIEnv *env; @@ -81,10 +90,12 @@ private: // caused by model detection and flag provisioning, such as broken weather with the new // smartspace on Android 12. if (process == "com.google.android.gms.unstable") { - // This is post-fork, so just inject the payload now + // Load the payload, but don't inject it yet until after specialization + // Otherwise, specialization fails if any code from the payload still happens to be + // running + LOGD("Loading payload..."); loadPayload(); - injectPayload(); - LOGI("Payload injected"); + LOGD("Payload loaded"); } }