|
1 | 1 | package com.weishu.upf.hook_classloader;
|
2 | 2 |
|
3 | 3 | import java.io.File;
|
| 4 | +import java.lang.reflect.InvocationTargetException; |
| 5 | +import java.lang.reflect.Method; |
4 | 6 |
|
5 | 7 | import android.app.Activity;
|
6 |
| -import android.content.ComponentName; |
7 | 8 | import android.content.Context;
|
8 |
| -import android.content.Intent; |
| 9 | +import android.net.Uri; |
9 | 10 | import android.os.Bundle;
|
10 | 11 | import android.util.Log;
|
11 | 12 | import android.view.View;
|
@@ -44,22 +45,52 @@ protected void onCreate(Bundle savedInstanceState) {
|
44 | 45 | @Override
|
45 | 46 | public void onClick(View v) {
|
46 | 47 | try {
|
47 |
| - Intent t = new Intent(); |
48 |
| - if (HOOK_METHOD == PATCH_BASE_CLASS_LOADER) { |
49 |
| - t.setComponent(new ComponentName("com.weishu.upf.dynamic_proxy_hook.app2", |
50 |
| - "com.weishu.upf.dynamic_proxy_hook.app2.MainActivity")); |
51 |
| - } else { |
52 |
| - t.setComponent(new ComponentName("com.weishu.upf.ams_pms_hook.app", |
53 |
| - "com.weishu.upf.ams_pms_hook.app.MainActivity")); |
54 |
| - } |
55 |
| - startActivity(t); |
| 48 | + // Intent t = new Intent(); |
| 49 | + // if (HOOK_METHOD == PATCH_BASE_CLASS_LOADER) { |
| 50 | + // t.setComponent(new ComponentName("com.weishu.upf.dynamic_proxy_hook.app2", |
| 51 | + // "com.weishu.upf.dynamic_proxy_hook.app2.MainActivity")); |
| 52 | + // } else { |
| 53 | + // t.setComponent(new ComponentName("com.weishu.upf.ams_pms_hook.app", |
| 54 | + // "com.weishu.upf.ams_pms_hook.app.MainActivity")); |
| 55 | + // } |
| 56 | + // startActivity(t); |
| 57 | + |
| 58 | + Uri uri = Uri.fromFile(getFileStreamPath("test.apk")); |
| 59 | + boolean ret = (Boolean) invokeMethod(Class.forName("android.provider.DocumentsContract").newInstance(), "isDocumentUri", new Class[] { Context.class, Uri.class }, |
| 60 | + new Object[] { getApplicationContext(), uri }); |
| 61 | + Log.d(TAG, "ret" + ret); |
56 | 62 | } catch (Throwable e) {
|
57 | 63 | e.printStackTrace();
|
58 | 64 | }
|
59 | 65 | }
|
60 | 66 | });
|
61 | 67 | }
|
62 | 68 |
|
| 69 | + private static Method getDeclaredMethod(Object object, String name, Class<?>[] types) { |
| 70 | + for (Class<?> superClass = object.getClass(); superClass != Object.class; superClass.getSuperclass()) { |
| 71 | + try { |
| 72 | + return superClass.getDeclaredMethod(name, types); |
| 73 | + } catch (NoSuchMethodException e) { |
| 74 | + |
| 75 | + } |
| 76 | + } |
| 77 | + return null; |
| 78 | + } |
| 79 | + |
| 80 | + private static Object invokeMethod(Object obj, String methodName, Class<?>[] argTypes, Object[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
| 81 | + Method method = getDeclaredMethod(obj, methodName, argTypes); |
| 82 | + if (method == null) { |
| 83 | + throw new IllegalAccessException("could not found method:" + methodName); |
| 84 | + } |
| 85 | + method.setAccessible(true); |
| 86 | + try { |
| 87 | + return method.invoke(obj, args); |
| 88 | + } catch (IllegalAccessException e) { |
| 89 | + |
| 90 | + } |
| 91 | + return null; |
| 92 | + } |
| 93 | + |
63 | 94 | @Override
|
64 | 95 | protected void attachBaseContext(Context newBase) {
|
65 | 96 | super.attachBaseContext(newBase);
|
|
0 commit comments