|
1 | 1 | package com.weishu.binder_hook.app;
|
2 | 2 |
|
3 |
| -import android.os.IBinder; |
4 |
| -import android.os.IInterface; |
5 |
| -import android.util.Log; |
6 |
| - |
7 | 3 | import java.lang.reflect.InvocationHandler;
|
8 | 4 | import java.lang.reflect.Method;
|
9 | 5 | import java.lang.reflect.Proxy;
|
10 | 6 |
|
| 7 | +import android.os.IBinder; |
| 8 | +import android.util.Log; |
| 9 | + |
11 | 10 | /**
|
12 | 11 | * 由于ServiceManager里面的sCache里面存储的 IBinder类型基本上都是BinderProxy
|
13 | 12 | * 因此, ServiceManager的使用者调用getService之后不会直接使用这个map
|
@@ -66,7 +65,14 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
|
66 | 65 |
|
67 | 66 | // asInterface 的时候会检测是否是特定类型的接口然后进行强制转换
|
68 | 67 | // 因此这里的动态代理生成的类型信息的类型必须是正确的
|
69 |
| - new Class[] { IBinder.class, IInterface.class, this.iinterface }, |
| 68 | + |
| 69 | + // 这里面Hook的是一个BinderProxy对象(Binder代理) (代理Binder的queryLocalInterface正常情况下是返回null) |
| 70 | + // 因此, 正常情况下 在asInterface里面会由于BinderProxy的queryLocalInterface返回null导致系统创建一个匿名的代理对象, 这样我们就无法控制了 |
| 71 | + // 所以我们要伪造一个对象, 瞒过这个if检测, 使得系统把这个queryLocalInterface返回的对象透传给asInterface的返回值; |
| 72 | + // 检测有两个要求, 其一: 非空, 其二, IXXInterface类型。 |
| 73 | + // 所以, 其实返回的对象不需要是Binder对象, 我们把它当作普通的对象Hook掉就ok(拦截这个对象里面对于IXXInterface相关方法的调用) |
| 74 | + |
| 75 | + new Class[] { this.iinterface }, |
70 | 76 | new BinderHookHandler(base, stub));
|
71 | 77 | }
|
72 | 78 |
|
|
0 commit comments