|
4 | 4 | import android.content.ComponentName; |
5 | 5 | import android.util.Log; |
6 | 6 |
|
7 | | -import com.lody.virtual.client.core.VirtualCore; |
8 | 7 | import com.lody.virtual.client.hook.base.BinderInvocationProxy; |
9 | | -import com.lody.virtual.client.hook.base.MethodProxy; |
10 | | -import com.lody.virtual.client.hook.utils.MethodParameterUtils; |
| 8 | +import com.lody.virtual.client.hook.base.ReplaceLastPkgMethodProxy; |
11 | 9 | import com.lody.virtual.helper.utils.ArrayUtils; |
12 | 10 |
|
13 | 11 | import java.lang.reflect.Field; |
@@ -48,63 +46,35 @@ public void inject() throws Throwable { |
48 | 46 | Log.e(TAG, "AutoFillManagerStub inject error.", tr); |
49 | 47 | return; |
50 | 48 | } |
51 | | - addMethodProxy(new MethodProxy() { |
52 | | - @Override |
53 | | - public String getMethodName() { |
54 | | - return "startSession"; |
55 | | - } |
56 | | - @Override |
57 | | - public boolean beforeCall(Object who, Method method, Object... args) { |
58 | | - if (args == null) { |
59 | | - return super.beforeCall(who, method, args); |
60 | | - } |
61 | | - int length = args.length; |
62 | | - if (length == 0) { |
63 | | - return super.beforeCall(who, method, args); |
64 | | - } |
65 | | - |
66 | | - int lastIndex = length - 1; |
67 | | - Object lastParam = args[lastIndex]; |
68 | | - if (lastParam instanceof String) { |
69 | | - MethodParameterUtils.replaceLastAppPkg(args); |
70 | | - } else if (lastParam instanceof ComponentName){ |
71 | | - ComponentName lastComponent = (ComponentName) lastParam; |
72 | | - ComponentName newComponent = new ComponentName(VirtualCore.get().getHostPkg(), |
73 | | - lastComponent.getClassName()); |
74 | | - args[lastIndex] = newComponent; |
75 | | - } |
76 | | - return super.beforeCall(who, method, args); |
77 | | - } |
78 | | - }); |
79 | 49 |
|
80 | | - addMethodProxy(new MethodProxy() { |
81 | | - @Override |
82 | | - public String getMethodName() { |
83 | | - return "updateOrRestartSession"; |
84 | | - } |
85 | | - @Override |
86 | | - public boolean beforeCall(Object who, Method method, Object... args) { |
87 | | - MethodParameterUtils.replaceLastAppPkg(args); |
88 | | - int index = ArrayUtils.indexOfLast(args, ComponentName.class); |
89 | | - if (index > 0) { |
90 | | - ComponentName origComponent = (ComponentName) args[index]; |
91 | | - ComponentName newComponent = new ComponentName(getHostPkg(), origComponent.getClassName()); |
92 | | - args[index] = newComponent; |
93 | | - } |
94 | | - return super.beforeCall(who, method, args); |
95 | | - } |
96 | | - }); |
97 | | - addMethodProxy(new MethodProxy() { |
98 | | - @Override |
99 | | - public String getMethodName() { |
100 | | - return "isServiceEnabled"; |
101 | | - } |
102 | | - @Override |
103 | | - public boolean beforeCall(Object who, Method method, Object... args) { |
104 | | - MethodParameterUtils.replaceLastAppPkg(args); |
105 | | - return super.beforeCall(who, method, args); |
| 50 | + addMethodProxy(new ReplacePkgAndComponentProxy("startSession")); |
| 51 | + addMethodProxy(new ReplacePkgAndComponentProxy("updateOrRestartSession")); |
| 52 | + addMethodProxy(new ReplaceLastPkgMethodProxy("isServiceEnabled")); |
| 53 | + } |
| 54 | + |
| 55 | + static class ReplacePkgAndComponentProxy extends ReplaceLastPkgMethodProxy { |
| 56 | + |
| 57 | + ReplacePkgAndComponentProxy(String name) { |
| 58 | + super(name); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public boolean beforeCall(Object who, Method method, Object... args) { |
| 63 | + replaceLastAppComponent(args, getHostPkg()); |
| 64 | + return super.beforeCall(who, method, args); |
| 65 | + } |
| 66 | + |
| 67 | + static ComponentName replaceLastAppComponent(Object[] args, String hostPkg) { |
| 68 | + int index = ArrayUtils.indexOfLast(args, ComponentName.class); |
| 69 | + if (index != -1) { |
| 70 | + ComponentName orig = (ComponentName) args[index]; |
| 71 | + ComponentName newComponent = new ComponentName(hostPkg, orig.getClassName()); |
| 72 | + args[index] = newComponent; |
| 73 | + return newComponent; |
106 | 74 | } |
107 | | - }); |
| 75 | + return null; |
| 76 | + } |
108 | 77 | } |
109 | 78 |
|
| 79 | + |
110 | 80 | } |
0 commit comments