Skip to content

Instantly share code, notes, and snippets.

@vvb2060
Created April 11, 2022 16:50
Show Gist options
  • Save vvb2060/f2099b7a09247546c36e2a398c266d68 to your computer and use it in GitHub Desktop.
Save vvb2060/f2099b7a09247546c36e2a398c266d68 to your computer and use it in GitHub Desktop.
`JNI_OnLoad` called by system
jint JNI_OnLoad(JavaVM *jvm, void *) {
JNIEnv *env;
jclass clazz;
if (jvm->GetEnv((void **) &env, JNI_VERSION_1_6) != JNI_OK) {
return JNI_ERR;
}
jclass vm = env->FindClass("dalvik/system/VMRuntime");
jclass string = env->FindClass("java/lang/String");
jmethodID set = env->GetMethodID(vm, "setHiddenApiExemptions", "([Ljava/lang/String;)V");
jmethodID get = env->GetStaticMethodID(vm, "getRuntime", "()Ldalvik/system/VMRuntime;");
jstring empty = env->NewStringUTF("");
jarray array = env->NewObjectArray(1, string, empty);
jobject runtime = env->CallStaticObjectMethod(vm, get);
env->CallVoidMethod(runtime, set, array);
return JNI_VERSION_1_6;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment