Fix module not loading on first run

This commit is contained in:
Nullptr 2022-05-27 23:01:06 +08:00
parent 4e41e141dd
commit 641ed369fa
No known key found for this signature in database
GPG Key ID: 0B9D02052FF536BD
4 changed files with 18 additions and 10 deletions

2
core

@ -1 +1 @@
Subproject commit dd8dcfbab1d8aa8a408ab57cb5e934684679533d Subproject commit d36d284f3908e7f5eb8bcb873e637cac2db27b01

View File

@ -93,10 +93,11 @@ public class LSPApplication {
try { try {
disableProfile(context); disableProfile(context);
Startup.initXposed(false, ActivityThread.currentProcessName(), service); Startup.initXposed(false, ActivityThread.currentProcessName(), service);
Log.i(TAG, "Start loading modules"); Log.i(TAG, "Bootstrap Xposed");
Startup.bootstrapXposed(); Startup.bootstrapXposed();
// WARN: Since it uses `XResource`, the following class should not be initialized // WARN: Since it uses `XResource`, the following class should not be initialized
// before forkPostCommon is invoke. Otherwise, you will get failure of XResources // before forkPostCommon is invoke. Otherwise, you will get failure of XResources
Log.i(TAG, "Load modules");
LSPLoader.initModules(appLoadedApk); LSPLoader.initModules(appLoadedApk);
Log.i(TAG, "Modules initialized"); Log.i(TAG, "Modules initialized");

View File

@ -71,11 +71,15 @@ namespace lspd {
env->DeleteLocalRef(dex_buffer); env->DeleteLocalRef(dex_buffer);
} }
void PatchLoader::InitHooks(JNIEnv* env, const lsplant::InitInfo& initInfo) { void PatchLoader::InitArtHooker(JNIEnv* env, const InitInfo& initInfo) {
Context::InitArtHooker(env, initInfo);
handler = initInfo; handler = initInfo;
Context::InitHooks(env, handler); art::DisableInline(initInfo);
art::DisableInline(handler); art::DisableBackgroundVerification(initInfo);
art::DisableBackgroundVerification(handler); }
void PatchLoader::InitHooks(JNIEnv* env) {
Context::InitHooks(env);
RegisterBypass(env); RegisterBypass(env);
} }
@ -88,7 +92,7 @@ namespace lspd {
void PatchLoader::Load(JNIEnv* env) { void PatchLoader::Load(JNIEnv* env) {
InitSymbolCache(nullptr); InitSymbolCache(nullptr);
lsplant::InitInfo initInfo{ lsplant::InitInfo initInfo {
.inline_hooker = [](auto t, auto r) { .inline_hooker = [](auto t, auto r) {
void* bk = nullptr; void* bk = nullptr;
return HookFunction(t, r, &bk) == RS_SUCCESS ? bk : nullptr; return HookFunction(t, r, &bk) == RS_SUCCESS ? bk : nullptr;
@ -108,10 +112,11 @@ namespace lspd {
auto dex_field = JNI_GetStaticFieldID(env, stub, "dex", "[B"); auto dex_field = JNI_GetStaticFieldID(env, stub, "dex", "[B");
auto array = (jbyteArray) env->GetStaticObjectField(stub, dex_field); auto array = (jbyteArray) env->GetStaticObjectField(stub, dex_field);
auto dex = PreloadedDex{env->GetByteArrayElements(array, nullptr), static_cast<size_t>(JNI_GetArrayLength(env, array))}; auto dex = PreloadedDex {env->GetByteArrayElements(array, nullptr), static_cast<size_t>(JNI_GetArrayLength(env, array))};
InitArtHooker(env, initInfo);
LoadDex(env, std::move(dex)); LoadDex(env, std::move(dex));
InitHooks(env, initInfo); InitHooks(env);
GetArt(true); GetArt(true);

View File

@ -42,7 +42,9 @@ namespace lspd {
void Load(JNIEnv* env); void Load(JNIEnv* env);
protected: protected:
void InitHooks(JNIEnv* env, const lsplant::InitInfo& initInfo) override; void InitArtHooker(JNIEnv* env, const lsplant::InitInfo& initInfo) override;
void InitHooks(JNIEnv* env) override;
void LoadDex(JNIEnv* env, PreloadedDex&& dex) override; void LoadDex(JNIEnv* env, PreloadedDex&& dex) override;