Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
[Xposed] Debugger fixes
Browse files Browse the repository at this point in the history
Debuggers need to know about all methods in a class. For methods hooked with
Xposed, both the hooked (proxy-like) and the original method have to be returned.

Also, the hooked method isn't directly attached to a code item anymore, which
would otherwise be used to calculate offsets into the method code.

Fixes #1.
  • Loading branch information
rovo89 committed Jun 12, 2015
1 parent 70db322 commit 5be00d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion runtime/debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1605,10 +1605,32 @@ JDWP::JdwpError Dbg::OutputDeclaredMethods(JDWP::RefTypeId class_id, bool with_g
size_t direct_method_count = c->NumDirectMethods();
size_t virtual_method_count = c->NumVirtualMethods();

expandBufAdd4BE(pReply, direct_method_count + virtual_method_count);
size_t xposed_method_count = 0;
for (size_t i = 0; i < direct_method_count + virtual_method_count; ++i) {
mirror::ArtMethod* m = (i < direct_method_count) ? c->GetDirectMethod(i) : c->GetVirtualMethod(i - direct_method_count);
if (UNLIKELY(m->IsXposedHookedMethod())) {
++xposed_method_count;
}
}

expandBufAdd4BE(pReply, direct_method_count + virtual_method_count + xposed_method_count);

for (size_t i = 0; i < direct_method_count + virtual_method_count; ++i) {
mirror::ArtMethod* m = (i < direct_method_count) ? c->GetDirectMethod(i) : c->GetVirtualMethod(i - direct_method_count);

if (UNLIKELY(xposed_method_count > 0 && m->IsXposedHookedMethod())) {
expandBufAddMethodId(pReply, ToMethodId(m));
expandBufAddUtf8String(pReply, m->GetName());
expandBufAddUtf8String(pReply, m->GetSignature().ToString());
if (with_generic) {
static const char genericSignature[1] = "";
expandBufAddUtf8String(pReply, genericSignature);
}
expandBufAdd4BE(pReply, MangleAccessFlags(m->GetAccessFlags()));

m = m->GetXposedOriginalMethod();
}

expandBufAddMethodId(pReply, ToMethodId(m));
expandBufAddUtf8String(pReply, m->GetName());
expandBufAddUtf8String(pReply, m->GetSignature().ToString());
Expand Down
3 changes: 3 additions & 0 deletions runtime/mirror/art_method-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ inline const char* ArtMethod::GetName() {
}

inline const DexFile::CodeItem* ArtMethod::GetCodeItem() {
if (UNLIKELY(IsXposedHookedMethod())) {
return nullptr;
}
mirror::ArtMethod* method = GetInterfaceMethodIfProxy();
return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset());
}
Expand Down

0 comments on commit 5be00d0

Please sign in to comment.