Пример #1
0
bool xposedOnVmCreated(JNIEnv* env, const char* className) {
    if (!keepLoadingXposed)
        return false;
        
    startClassName = className;

    xposedInitMemberOffsets();

    // disable some access checks
    patchReturnTrue((void*) &dvmCheckClassAccess);
    patchReturnTrue((void*) &dvmCheckFieldAccess);
    patchReturnTrue((void*) &dvmInSamePackage);
    if (access(XPOSED_DIR "do_not_hook_dvmCheckMethodAccess", F_OK) != 0)
        patchReturnTrue((void*) &dvmCheckMethodAccess);

    xposedClass = env->FindClass(XPOSED_CLASS);
    xposedClass = reinterpret_cast<jclass>(env->NewGlobalRef(xposedClass));
    
    if (xposedClass == NULL) {
        ALOGE("Error while loading Xposed class '%s':\n", XPOSED_CLASS);
        dvmLogExceptionStackTrace();
        env->ExceptionClear();
        return false;
    }
    
    ALOGI("Found Xposed class '%s', now initializing\n", XPOSED_CLASS);
    register_de_robv_android_xposed_XposedBridge(env);
    register_android_content_res_XResources(env);
    return true;
}
Пример #2
0
static jboolean de_robv_android_xposed_XposedBridge_initNative(JNIEnv* env,
		jclass clazz) {
	if (!keepLoadingXposed) {
		ALOGE("Not initializing Xposed because of previous errors\n");
		return false;
	}

	::Thread* self = dvmThreadSelf();

	xposedHandleHookedMethod =
			(Method*) env->GetStaticMethodID(xposedClass, "handleHookedMethod",
					"(Ljava/lang/reflect/Member;ILjava/lang/Object;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;");
	if (xposedHandleHookedMethod == NULL) {
		ALOGE(
				"ERROR: could not find method %s.handleHookedMethod(Member, int, Object, Object, Object[])\n",
				XPOSED_CLASS);
		dvmLogExceptionStackTrace();
		env->ExceptionClear();
		keepLoadingXposed = false;
		return false;
	}

	Method* xposedInvokeOriginalMethodNative =
			(Method*) env->GetStaticMethodID(xposedClass,
					"invokeOriginalMethodNative",
					"(Ljava/lang/reflect/Member;I[Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;");
	if (xposedInvokeOriginalMethodNative == NULL) {
		ALOGE(
				"ERROR: could not find method %s.invokeOriginalMethodNative(Member, int, Class[], Class, Object, Object[])\n",
				XPOSED_CLASS);
		dvmLogExceptionStackTrace();
		env->ExceptionClear();
		keepLoadingXposed = false;
		return false;
	}
	dvmSetNativeFunc(xposedInvokeOriginalMethodNative,
			de_robv_android_xposed_XposedBridge_invokeOriginalMethodNative,
			NULL);

	objectArrayClass = dvmFindArrayClass("[Ljava/lang/Object;", NULL);
	if (objectArrayClass == NULL) {
		ALOGE("Error while loading Object[] class");
		dvmLogExceptionStackTrace();
		env->ExceptionClear();
		keepLoadingXposed = false;
		return false;
	}

	//It's not found here?
	xresourcesClass = env->FindClass(XRESOURCES_CLASS);
	xresourcesClass = reinterpret_cast<jclass>(env->NewGlobalRef(
			xresourcesClass));
	if (xresourcesClass == NULL) {
		ALOGE("Error while loading XResources class '%s':\n", XRESOURCES_CLASS);
		dvmLogExceptionStackTrace();
		env->ExceptionClear();
		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");
	if (xresourcesTranslateResId == NULL) {
		ALOGE(
				"ERROR: could not find method %s.translateResId(int, Resources, Resources)\n",
				XRESOURCES_CLASS);
		dvmLogExceptionStackTrace();
		env->ExceptionClear();
		keepLoadingXposed = false;
		return false;
	}

	xresourcesTranslateAttrId = env->GetStaticMethodID(xresourcesClass,
			"translateAttrId",
			"(Ljava/lang/String;Landroid/content/res/XResources;)I");
	if (xresourcesTranslateAttrId == NULL) {
		ALOGE(
				"ERROR: could not find method %s.findAttrId(String, Resources, Resources)\n",
				XRESOURCES_CLASS);
		dvmLogExceptionStackTrace();
		env->ExceptionClear();
		keepLoadingXposed = false;
		return false;
	}

	return true;
}