Skip to content

Commit

Permalink
[Xposed] No longer change the object size of TypedArray
Browse files Browse the repository at this point in the history
The XTypedArray class has no more additional fields on Java side now,
so this hack is obsolete. Instead, verify that this claim is actually
correct.
  • Loading branch information
rovo89 committed Oct 15, 2017
1 parent f2a7379 commit b00d990
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
22 changes: 12 additions & 10 deletions libxposed_art.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@ void logExceptionStackTrace() {
#endif
}

/** Lay the foundations for XposedBridge.setObjectClassNative() */
void prepareSubclassReplacement(JNIEnv* env, jclass clazz) {
// clazz is supposed to replace its superclass, so make sure enough memory is allocated
ScopedObjectAccess soa(env);
mirror::Class* sub = soa.Decode<mirror::Class*>(clazz);
mirror::Class* super = sub->GetSuperClass();
super->SetObjectSize(sub->GetObjectSize());
}


////////////////////////////////////////////////////////////
// JNI methods
////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -128,6 +118,18 @@ void XposedBridge_setObjectClassNative(JNIEnv* env, jclass, jobject javaObj, jcl
return;
}
mirror::Object* obj = soa.Decode<mirror::Object*>(javaObj);
mirror::Class* currentClass = obj->GetClass();
if (clazz->GetObjectSize() != currentClass->GetObjectSize()) {
std::string msg = StringPrintf("Different object sizes: %s (%d) vs. %s (%d)",
PrettyClass(clazz).c_str(), clazz->GetObjectSize(),
PrettyClass(currentClass).c_str(), currentClass->GetObjectSize());
#if PLATFORM_SDK_VERSION >= 23
ThrowIllegalArgumentException(msg.c_str());
#else
ThrowIllegalArgumentException(nullptr, msg.c_str());
#endif
return;
}
obj->SetClass(clazz);
}

Expand Down
9 changes: 0 additions & 9 deletions libxposed_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,6 @@ void onVmCreatedCommon(JNIEnv* env) {
return;
}

jclass classXTypedArray = env->FindClass(CLASS_XTYPED_ARRAY);
if (classXTypedArray == NULL) {
ALOGE("Error while loading XTypedArray class '%s':", CLASS_XTYPED_ARRAY);
logExceptionStackTrace();
env->ExceptionClear();
return;
}
prepareSubclassReplacement(env, classXTypedArray);

if (!onVmCreated(env)) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion libxposed_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace xposed {
#define CLASS_XPOSED_BRIDGE "de/robv/android/xposed/XposedBridge"
#define CLASS_XRESOURCES "android/content/res/XResources"
#define CLASS_MIUI_RESOURCES "android/content/res/MiuiResources"
#define CLASS_XTYPED_ARRAY "android/content/res/XResources$XTypedArray"
#define CLASS_ZYGOTE_SERVICE "de/robv/android/xposed/services/ZygoteService"
#define CLASS_FILE_RESULT "de/robv/android/xposed/services/FileResult"

Expand Down
9 changes: 0 additions & 9 deletions libxposed_dalvik.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace xposed {
////////////////////////////////////////////////////////////

bool initMemberOffsets(JNIEnv* env);
void prepareSubclassReplacement(jclass clazz);
void hookedMethodCallback(const u4* args, JValue* pResult, const Method* method, ::Thread* self);
void XposedBridge_invokeOriginalMethodNative(const u4* args, JValue* pResult, const Method* method, ::Thread* self);

Expand Down Expand Up @@ -129,14 +128,6 @@ inline void setObjectArrayElement(const ArrayObject* obj, int index, Object* val
dvmWriteBarrierArray(obj, index, index + 1);
}

/** Lay the foundations for XposedBridge.setObjectClassNative() */
void prepareSubclassReplacement(JNIEnv*, jclass clazz) {
// clazz is supposed to replace its superclass, so make sure enough memory is allocated
ClassObject* sub = (ClassObject*) dvmDecodeIndirectRef(dvmThreadSelf(), clazz);
ClassObject* super = sub->super;
super->objectSize = sub->objectSize;
}

/** Wrapper used by the common part of the library. */
void logExceptionStackTrace() {
dvmLogExceptionStackTrace();
Expand Down

0 comments on commit b00d990

Please sign in to comment.