Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 authored and kotori2 committed Dec 23, 2020
1 parent de2f65d commit 27f1abf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ namespace art {
}

CREATE_HOOK_STUB_ENTRIES(void, FixupStaticTrampolines, void *thiz, void *clazz_ptr) {
bool should_intercept = edxp::IsClassPending(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)) {
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);
}
}
Expand Down
26 changes: 20 additions & 6 deletions edxp-core/src/main/cpp/main/include/art/runtime/mirror/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ namespace art {
return IsInSamePackageBackup(thiz, that);
}

CREATE_FUNC_SYMBOL_ENTRY(void*, GetClassDef, void* thiz) {
if (LIKELY(GetClassDefSym))
return GetClassDefSym(thiz);
return nullptr;
}

public:
Class(void *thiz) : HookedObject(thiz) {}

Expand All @@ -51,6 +57,8 @@ namespace art {
RETRIEVE_FUNC_SYMBOL(GetDescriptor, "_ZN3art6mirror5Class13GetDescriptorEPNSt3__112"
"basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE");

RETRIEVE_FUNC_SYMBOL(GetClassDef, "_ZN3art6mirror5Class11GetClassDefEv");

// RETRIEVE_FIELD_SYMBOL(mutator_lock_, "_ZN3art5Locks13mutator_lock_E");
// LOGE("mutator_lock_: %p", mutator_lock_);

Expand All @@ -64,15 +72,21 @@ namespace art {

const char *GetDescriptor(std::string *storage) {
if (thiz_ && GetDescriptorSym) {
if (storage == nullptr) {
std::string str;
return GetDescriptor(thiz_, &str);
} else {
return GetDescriptor(thiz_, storage);
}
return GetDescriptor(thiz_, storage);
}
return "";
}

std::string GetDescriptor() {
std::string storage;
return GetDescriptor(&storage);
}

void *GetClassDef() {
if(thiz_ && GetClassDefSym)
return GetClassDef(thiz_);
return nullptr;
}
};

} // namespace mirror
Expand Down
10 changes: 8 additions & 2 deletions edxp-core/src/main/cpp/main/src/jni/edxp_pending_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ namespace edxp {
static void PendingHooks_recordPendingMethodNative(JNI_START, jlong thread, jclass class_ref) {
art::Thread current_thread(reinterpret_cast<void *>(thread));
auto *class_ptr = current_thread.DecodeJObject(class_ref);
LOGD("record pending: %p (%s)", class_ptr, art::mirror::Class(class_ptr).GetDescriptor(nullptr));
pending_classes_.insert(class_ptr);
art::mirror::Class mirror_class(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[] = {
Expand Down

0 comments on commit 27f1abf

Please sign in to comment.