Skip to content

Commit

Permalink
v54: Add an internal method to clone object to subclasses
Browse files Browse the repository at this point in the history
See XposedBridge commit for details.
  • Loading branch information
rovo89 committed Apr 16, 2014
1 parent d10e7ee commit b1f01a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions xposed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,32 @@ static void de_robv_android_xposed_XposedBridge_dumpObjectNative(JNIEnv* env, jc
dvmDumpObject(obj);
}

static jobject de_robv_android_xposed_XposedBridge_cloneToSubclassNative(JNIEnv* env, jclass clazz, jobject objIndirect, jclass clzIndirect) {
Object* obj = (Object*) dvmDecodeIndirectRef(dvmThreadSelf(), objIndirect);
ClassObject* clz = (ClassObject*) dvmDecodeIndirectRef(dvmThreadSelf(), clzIndirect);

jobject copyIndirect = env->AllocObject(clzIndirect);
if (copyIndirect == NULL)
return NULL;

Object* copy = (Object*) dvmDecodeIndirectRef(dvmThreadSelf(), copyIndirect);
size_t size = obj->clazz->objectSize;
size_t offset = sizeof(Object);
memcpy((char*)copy + offset, (char*)obj + offset, size - offset);

if (IS_CLASS_FLAG_SET(clz, CLASS_ISFINALIZABLE))
dvmSetFinalizable(copy);

return copyIndirect;
}

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/reflect/Member;Ljava/lang/Class;ILjava/lang/Object;)V", (void*)de_robv_android_xposed_XposedBridge_hookMethodNative},
{"setObjectClassNative", "(Ljava/lang/Object;Ljava/lang/Class;)V", (void*)de_robv_android_xposed_XposedBridge_setObjectClassNative},
{"dumpObjectNative", "(Ljava/lang/Object;)V", (void*)de_robv_android_xposed_XposedBridge_dumpObjectNative},
{"cloneToSubclassNative", "(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;", (void*)de_robv_android_xposed_XposedBridge_cloneToSubclassNative},
};

static const JNINativeMethod xresourcesMethods[] = {
Expand Down
2 changes: 1 addition & 1 deletion xposed.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace android {
#define MIUI_RESOURCES_CLASS "android/content/res/MiuiResources"
#define XTYPEDARRAY_CLASS "android/content/res/XResources$XTypedArray"

#define XPOSED_VERSION "53"
#define XPOSED_VERSION "54"

#ifndef ALOGD
#define ALOGD LOGD
Expand Down

0 comments on commit b1f01a1

Please sign in to comment.