CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/exploits/CVE-2015-8103/payloads/util/Reflections.java
Views: 11789
1
package ysoserial.payloads.util;
2
3
import java.lang.reflect.Constructor;
4
import java.lang.reflect.Field;
5
6
public class Reflections {
7
8
public static Field getField(final Class<?> clazz, final String fieldName) throws Exception {
9
Field field = clazz.getDeclaredField(fieldName);
10
if (field == null && clazz.getSuperclass() != null) {
11
field = getField(clazz.getSuperclass(), fieldName);
12
}
13
field.setAccessible(true);
14
return field;
15
}
16
17
public static void setFieldValue(final Object obj, final String fieldName, final Object value) throws Exception {
18
final Field field = getField(obj.getClass(), fieldName);
19
field.set(obj, value);
20
}
21
22
public static Object getFieldValue(final Object obj, final String fieldName) throws Exception {
23
final Field field = getField(obj.getClass(), fieldName);
24
return field.get(obj);
25
}
26
27
public static Constructor<?> getFirstCtor(final String name) throws Exception {
28
final Constructor<?> ctor = Class.forName(name).getDeclaredConstructors()[0];
29
ctor.setAccessible(true);
30
return ctor;
31
}
32
33
}
34
35