Skip to content

Commit

Permalink
v43: Register native methods more safely
Browse files Browse the repository at this point in the history
The previously used function calls abort() if some methods cannot
be found. We just want to stop loading Xposed in this case to avoid
bootloops.
  • Loading branch information
rovo89 committed Nov 7, 2013
1 parent 4ea334d commit 43d0ade
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions xposed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ bool xposedOnVmCreated(JNIEnv* env, const char* className) {
}

ALOGI("Found Xposed class '%s', now initializing\n", XPOSED_CLASS);
register_de_robv_android_xposed_XposedBridge(env);
register_android_content_res_XResources(env);
if (register_de_robv_android_xposed_XposedBridge(env) != JNI_OK) {
ALOGE("Could not register natives for '%s'\n", XPOSED_CLASS);
return false;
}
return true;
}

Expand Down Expand Up @@ -388,6 +390,10 @@ static jboolean de_robv_android_xposed_XposedBridge_initNative(JNIEnv* env, jcla
keepLoadingXposed = false;
return false;
}
if (register_android_content_res_XResources(env) != JNI_OK) {
ALOGE("Could not register natives for '%s'\n", XRESOURCES_CLASS);
return false;
}

xresourcesTranslateResId = env->GetStaticMethodID(xresourcesClass, "translateResId",
"(ILandroid/content/res/XResources;Landroid/content/res/Resources;)I");
Expand Down Expand Up @@ -544,22 +550,22 @@ static jobject de_robv_android_xposed_XposedBridge_getStartClassName(JNIEnv* env
}

static const JNINativeMethod xposedMethods[] = {
{"getStartClassName", "()Ljava/lang/String;", (void*)de_robv_android_xposed_XposedBridge_getStartClassName},
{"initNative", "()Z", (void*)de_robv_android_xposed_XposedBridge_initNative},
{"hookMethodNative", "(Ljava/lang/Class;I)V", (void*)de_robv_android_xposed_XposedBridge_hookMethodNative},
{"invokeOriginalMethodNative", "(Ljava/lang/reflect/Member;[Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", (void*)de_robv_android_xposed_XposedBridge_invokeOriginalMethodNative},
{"getStartClassName", "()Ljava/lang/String;", (void*)de_robv_android_xposed_XposedBridge_getStartClassName},
};

static const JNINativeMethod xresourcesMethods[] = {
{"rewriteXmlReferencesNative", "(ILandroid/content/res/XResources;Landroid/content/res/Resources;)V", (void*)android_content_res_XResources_rewriteXmlReferencesNative},
};

static int register_de_robv_android_xposed_XposedBridge(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, XPOSED_CLASS, xposedMethods, NELEM(xposedMethods));
return env->RegisterNatives(xposedClass, xposedMethods, NELEM(xposedMethods));
}

static int register_android_content_res_XResources(JNIEnv* env) {
return AndroidRuntime::registerNativeMethods(env, XRESOURCES_CLASS, xresourcesMethods, NELEM(xresourcesMethods));
return env->RegisterNatives(xresourcesClass, xresourcesMethods, NELEM(xresourcesMethods));
}

}
Expand Down
2 changes: 1 addition & 1 deletion xposed.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace android {
#define XPOSED_CLASS_DOTS "de.robv.android.xposed.XposedBridge"
#define XRESOURCES_CLASS "android/content/res/XResources"
#define MIUI_RESOURCES_CLASS "android/content/res/MiuiResources"
#define XPOSED_VERSION "42"
#define XPOSED_VERSION "43"

#ifndef ALOGD
#define ALOGD LOGD
Expand Down

0 comments on commit 43d0ade

Please sign in to comment.