Skip to content

Commit 3f17ea4

Browse files
author
tiann
committed
修复动态代理里面的作业说明.
1 parent 67fecb9 commit 3f17ea4

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

classloader-hook/src/main/java/com/weishu/upf/hook_classloader/MainActivity.java

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.weishu.upf.hook_classloader;
22

33
import java.io.File;
4+
import java.lang.reflect.InvocationTargetException;
5+
import java.lang.reflect.Method;
46

57
import android.app.Activity;
6-
import android.content.ComponentName;
78
import android.content.Context;
8-
import android.content.Intent;
9+
import android.net.Uri;
910
import android.os.Bundle;
1011
import android.util.Log;
1112
import android.view.View;
@@ -44,22 +45,52 @@ protected void onCreate(Bundle savedInstanceState) {
4445
@Override
4546
public void onClick(View v) {
4647
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);
5662
} catch (Throwable e) {
5763
e.printStackTrace();
5864
}
5965
}
6066
});
6167
}
6268

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+
6394
@Override
6495
protected void attachBaseContext(Context newBase) {
6596
super.attachBaseContext(newBase);

0 commit comments

Comments
 (0)