MCPcopy Create free account
hub / github.com/cinit/TMoe / Reflex

Class Reflex

app/src/main/java/cc/ioctl/tmoe/util/Reflex.java:20–1230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18import de.robv.android.xposed.XposedBridge;
19
20public class Reflex {
21 private Reflex() {
22 throw new AssertionError("no instance for you!");
23 }
24
25 public static Object getStaticObjectOrNull(Class<?> clazz, String name, Class<?> type) {
26 try {
27 return getStaticObject(clazz, name, type);
28 } catch (NoSuchFieldException e) {
29 return null;
30 }
31 }
32
33 public static Object getStaticObjectOrNull(Class<?> clazz, String name) {
34 return getStaticObjectOrNull(clazz, name, null);
35 }
36
37 public static Object getStaticObject(Class<?> clazz, String name) throws NoSuchFieldException {
38 return getStaticObject(clazz, name, null);
39 }
40
41 public static Object getStaticObject(Class<?> clazz, String name, Class<?> type) throws NoSuchFieldException {
42 Field f = findField(clazz, type, name);
43 f.setAccessible(true);
44 try {
45 return f.get(null);
46 } catch (IllegalAccessException e) {
47 // should not happen
48 throw new AssertionError(e);
49 }
50 }
51
52 public static Object invokeVirtualAny(Object obj, Object... argsTypesAndReturnType)
53 throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IllegalArgumentException {
54 Class clazz = obj.getClass();
55 int argc = argsTypesAndReturnType.length / 2;
56 Class[] argt = new Class[argc];
57 Object[] argv = new Object[argc];
58 Class returnType = null;
59 if (argc * 2 + 1 == argsTypesAndReturnType.length) {
60 returnType = (Class) argsTypesAndReturnType[argsTypesAndReturnType.length - 1];
61 }
62 int i, ii;
63 Method[] m;
64 Method method = null;
65 Class[] _argt;
66 for (i = 0; i < argc; i++) {
67 argt[i] = (Class) argsTypesAndReturnType[argc + i];
68 argv[i] = argsTypesAndReturnType[i];
69 }
70 loop_main:
71 do {
72 m = clazz.getDeclaredMethods();
73 loop:
74 for (i = 0; i < m.length; i++) {
75 _argt = m[i].getParameterTypes();
76 if (_argt.length == argt.length) {
77 for (ii = 0; ii < argt.length; ii++) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected