Free JNI memory

This commit is contained in:
chiteroman 2024-09-16 13:24:03 +02:00
parent 50b27de41c
commit 8701a60f2f
No known key found for this signature in database

View File

@ -202,12 +202,10 @@ public:
if (spoofProps) { if (spoofProps) {
if (!doHook()) { if (!doHook()) {
LOGD("dlclose zygisk lib"); dlclose();
api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
} }
} else { } else {
LOGD("dlclose zygisk lib"); dlclose();
api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
} }
json.clear(); json.clear();
@ -228,6 +226,11 @@ private:
bool spoofProvider = false; bool spoofProvider = false;
bool spoofSignature = false; bool spoofSignature = false;
void dlclose() {
LOGD("dlclose zygisk lib");
api->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
}
void parseJSON() { void parseJSON() {
if (json.empty()) return; if (json.empty()) return;
@ -274,6 +277,12 @@ private:
"()Ljava/lang/ClassLoader;"); "()Ljava/lang/ClassLoader;");
auto systemClassLoader = env->CallStaticObjectMethod(clClass, getSystemClassLoader); auto systemClassLoader = env->CallStaticObjectMethod(clClass, getSystemClassLoader);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
return;
}
LOGD("create class loader"); LOGD("create class loader");
auto dexClClass = env->FindClass("dalvik/system/InMemoryDexClassLoader"); auto dexClClass = env->FindClass("dalvik/system/InMemoryDexClassLoader");
auto dexClInit = env->GetMethodID(dexClClass, "<init>", auto dexClInit = env->GetMethodID(dexClClass, "<init>",
@ -282,19 +291,45 @@ private:
static_cast<jlong>(dexVector.size())); static_cast<jlong>(dexVector.size()));
auto dexCl = env->NewObject(dexClClass, dexClInit, buffer, systemClassLoader); auto dexCl = env->NewObject(dexClClass, dexClInit, buffer, systemClassLoader);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
return;
}
LOGD("load class"); LOGD("load class");
auto loadClass = env->GetMethodID(clClass, "loadClass", auto loadClass = env->GetMethodID(clClass, "loadClass",
"(Ljava/lang/String;)Ljava/lang/Class;"); "(Ljava/lang/String;)Ljava/lang/Class;");
auto entryClassName = env->NewStringUTF("es.chiteroman.playintegrityfix.EntryPoint"); auto entryClassName = env->NewStringUTF("es.chiteroman.playintegrityfix.EntryPoint");
auto entryClassObj = env->CallObjectMethod(dexCl, loadClass, entryClassName); auto entryClassObj = env->CallObjectMethod(dexCl, loadClass, entryClassName);
auto entryPointClass = (jclass) entryClassObj; auto entryPointClass = (jclass) entryClassObj;
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
return;
}
LOGD("call init"); LOGD("call init");
auto entryInit = env->GetStaticMethodID(entryPointClass, "init", "(Ljava/lang/String;ZZ)V"); auto entryInit = env->GetStaticMethodID(entryPointClass, "init", "(Ljava/lang/String;ZZ)V");
auto jsonStr = env->NewStringUTF(json.dump().c_str()); auto jsonStr = env->NewStringUTF(json.dump().c_str());
env->CallStaticVoidMethod(entryPointClass, entryInit, jsonStr, spoofProvider, env->CallStaticVoidMethod(entryPointClass, entryInit, jsonStr, spoofProvider,
spoofSignature); spoofSignature);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
}
env->DeleteLocalRef(entryClassName);
env->DeleteLocalRef(entryClassObj);
env->DeleteLocalRef(jsonStr);
env->DeleteLocalRef(dexCl);
env->DeleteLocalRef(buffer);
env->DeleteLocalRef(dexClClass);
env->DeleteLocalRef(clClass);
LOGD("jni memory free");
} }
void UpdateBuildFields() { void UpdateBuildFields() {