LSPosed / LSPlant

A hook framework for Android Runtime (ART)
https://lsposed.org/LSPlant/
GNU Lesser General Public License v3.0
888 stars 219 forks source link

ArtMethod变更导致Hook无效问题 #104

Closed yujack008 closed 3 months ago

yujack008 commented 3 months ago

今天发现了一个hook无效问题: 1.DoHook函数时候打印的ArtMethod对象指针为0x7717685df8,AccessFlag值为0x1a000001 2.我在源码的ArtMethod::Invoke函数里面打印对应函数的ArtMethod对象指针为0x7662d4d6c0,AccessFlag值为0x18080001

log如下:

hook时候打印的log
08-08 18:12:45.996  8768  8768 V LSPlant : lsplant.cc:582#bool lsplant::(anonymous namespace)::DoHook(ArtMethod *, ArtMethod *, ArtMethod *): Hooking: target = void com.bbbbbb.mm.plugin.appbrand.jsapi.p.proceed()(0x7717685df8), hook = void cn.aaaaaa.zjh.AopSandbox.proceed(java.lang.Object)(0x77171e5128), backup = void cn.aaaaaa.zjh.AopSandbox.backup(java.lang.Object)(0x77171e5100)
08-08 18:12:45.996  8768  8768 V LSPlant : lsplant.cc:563#void *lsplant::(anonymous namespace)::GenerateTrampolineFor(art::ArtMethod *): trampoline: count = 1, address = 77a2135000, target = 77a2135018
08-08 18:12:45.996  8768  8768 V LSPlant : lsplant.cc:589#bool lsplant::(anonymous namespace)::DoHook(ArtMethod *, ArtMethod *, ArtMethod *): Generated trampoline 0x77a2135018
08-08 18:12:45.996  8768  8768 V LSPlant : lsplant.cc:605#bool lsplant::(anonymous namespace)::DoHook(ArtMethod *, ArtMethod *, ArtMethod *): Done hook: target(0x7717685df8:0x1a000001) -> 0x77a2135018; backup(0x77171e5100:0x1a000002) -> 0x771fb5b410; hook(0x77171e5128:0x12080009) -> 0x771fb5b410
08-08 18:12:45.996  8768  8768 V LSPlant : lsplant.cc:786#jobject lsplant::Hook(JNIEnv *, jobject, jobject, jobject): Hook End Ok

ArtMethod::Invoke函数打印的log
08-08 18:12:50.999  8566  9087 I nt.mm:appbrand: invoking 'void com.bbbbbb.mm.plugin.appbrand.jsapi.p.proceed()'AccessFlag:0x18080001,self:0x7662d4d6c0
08-08 18:12:50.999  8566  9087 I nt.mm:appbrand: Invoking 'void com.bbbbbb.mm.plugin.appbrand.jsapi.p.proceed()' quick code=0x76a9c6b9b0 static=0
08-08 18:12:50.999  8566  9087 I nt.mm:appbrand: Returned 'void com.bbbbbb.mm.plugin.appbrand.jsapi.p.proceed()' quick code=0x76a9c6b9b0

通过观察发现hook函数的ArtMethod对象指针变了,是不是class重新加载了,导致hook无效了?,有什么好的建议解决这个问题嘛?非常感谢。

yujincheng08 commented 3 months ago

artmethod 地址不会变。是你弄了两个 classloader。