This commit is contained in:
LoveSy 2020-12-23 18:50:48 +08:00 committed by 双草酸酯
parent de2f65d17b
commit 27f1abfb3c
3 changed files with 33 additions and 10 deletions

View File

@ -35,10 +35,13 @@ namespace art {
} }
CREATE_HOOK_STUB_ENTRIES(void, FixupStaticTrampolines, void *thiz, void *clazz_ptr) { CREATE_HOOK_STUB_ENTRIES(void, FixupStaticTrampolines, void *thiz, void *clazz_ptr) {
bool should_intercept = edxp::IsClassPending(clazz_ptr);
FixupStaticTrampolinesBackup(thiz, clazz_ptr); FixupStaticTrampolinesBackup(thiz, clazz_ptr);
art::mirror::Class mirror_class(clazz_ptr);
auto class_def = mirror_class.GetClassDef();
bool should_intercept = class_def && edxp::IsClassPending(class_def);
if (UNLIKELY(should_intercept)) { if (UNLIKELY(should_intercept)) {
LOGD("Pending hook for %p (%s)", clazz_ptr, art::mirror::Class(clazz_ptr).GetDescriptor(nullptr)); LOGD("Pending hook for %p (%s)", clazz_ptr,
art::mirror::Class(clazz_ptr).GetDescriptor().c_str());
edxp::Context::GetInstance()->CallOnPostFixupStaticTrampolines(clazz_ptr); edxp::Context::GetInstance()->CallOnPostFixupStaticTrampolines(clazz_ptr);
} }
} }

View File

@ -43,6 +43,12 @@ namespace art {
return IsInSamePackageBackup(thiz, that); return IsInSamePackageBackup(thiz, that);
} }
CREATE_FUNC_SYMBOL_ENTRY(void*, GetClassDef, void* thiz) {
if (LIKELY(GetClassDefSym))
return GetClassDefSym(thiz);
return nullptr;
}
public: public:
Class(void *thiz) : HookedObject(thiz) {} Class(void *thiz) : HookedObject(thiz) {}
@ -51,6 +57,8 @@ namespace art {
RETRIEVE_FUNC_SYMBOL(GetDescriptor, "_ZN3art6mirror5Class13GetDescriptorEPNSt3__112" RETRIEVE_FUNC_SYMBOL(GetDescriptor, "_ZN3art6mirror5Class13GetDescriptorEPNSt3__112"
"basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE"); "basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE");
RETRIEVE_FUNC_SYMBOL(GetClassDef, "_ZN3art6mirror5Class11GetClassDefEv");
// RETRIEVE_FIELD_SYMBOL(mutator_lock_, "_ZN3art5Locks13mutator_lock_E"); // RETRIEVE_FIELD_SYMBOL(mutator_lock_, "_ZN3art5Locks13mutator_lock_E");
// LOGE("mutator_lock_: %p", mutator_lock_); // LOGE("mutator_lock_: %p", mutator_lock_);
@ -64,15 +72,21 @@ namespace art {
const char *GetDescriptor(std::string *storage) { const char *GetDescriptor(std::string *storage) {
if (thiz_ && GetDescriptorSym) { if (thiz_ && GetDescriptorSym) {
if (storage == nullptr) { return GetDescriptor(thiz_, storage);
std::string str;
return GetDescriptor(thiz_, &str);
} else {
return GetDescriptor(thiz_, storage);
}
} }
return ""; return "";
} }
std::string GetDescriptor() {
std::string storage;
return GetDescriptor(&storage);
}
void *GetClassDef() {
if(thiz_ && GetClassDefSym)
return GetClassDef(thiz_);
return nullptr;
}
}; };
} // namespace mirror } // namespace mirror

View File

@ -22,8 +22,14 @@ namespace edxp {
static void PendingHooks_recordPendingMethodNative(JNI_START, jlong thread, jclass class_ref) { static void PendingHooks_recordPendingMethodNative(JNI_START, jlong thread, jclass class_ref) {
art::Thread current_thread(reinterpret_cast<void *>(thread)); art::Thread current_thread(reinterpret_cast<void *>(thread));
auto *class_ptr = current_thread.DecodeJObject(class_ref); auto *class_ptr = current_thread.DecodeJObject(class_ref);
LOGD("record pending: %p (%s)", class_ptr, art::mirror::Class(class_ptr).GetDescriptor(nullptr)); art::mirror::Class mirror_class(class_ptr);
pending_classes_.insert(class_ptr); if (auto def = mirror_class.GetClassDef(); LIKELY(def)) {
LOGD("record pending: %p (%s)", class_ptr, mirror_class.GetDescriptor().c_str());
pending_classes_.insert(def);
} else {
LOGW("fail to record pending for : %p (%s)", class_ptr,
mirror_class.GetDescriptor().c_str());
}
} }
static JNINativeMethod gMethods[] = { static JNINativeMethod gMethods[] = {