Class ReflectionHelper
java.lang.Object
ghidra.app.util.bin.format.golang.structmapping.ReflectionHelper
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
assignField
(Field field, Object obj, Object value) Write a value to a field in a java class.static <T> T
callCtor
(Constructor<T> ctor, Object... params) static <T> Object
callGetter
(Method getterMethod, T obj) static <T,
R> R callGetter
(Method getterMethod, T obj, Class<R> expectedType) static <T> void
callSetter
(Object obj, Method setterMethod, T value) static <T,
CTX> T createInstance
(Class<T> targetClass, CTX optionalContext) Creates an instance of the specified target class, using an optional context parameter to the constructor.static Method
findGetter
(Class<?> structClass, String getterName) static Method
findSetter
(String fieldName, String setterNameOverride, Class<?> structClass, Class<?> valueClass) static <T extends Annotation>
List<T> getAnnotations
(Class<?> targetClass, Class<T> annotationClass, List<T> result) static DataType
getArrayOutputDataType
(Object array_value, Class<?> fieldType, int length, Signedness signedness, DataTypeMapper dataTypeMapper) Return Ghidra data type representing an array of primitive values.static Method
getCommentMethod
(Class<?> clazz, String commentGetterName, String defaultGetterName) static <T> Constructor
<T> static Signedness
static <R> R
getFieldValue
(Object obj, Field field, Class<R> expectedType) getMarkedMethods
(Class<?> targetClass, Class<? extends Annotation> annotationClass, List<Method> methods, boolean includeParentClasses, Class<?>... paramClasses) Returns a list of methods that have been marked with a specific annotation.static DataType
getPrimitiveOutputDataType
(Class<?> fieldType, int length, Signedness signedness, DataTypeMapper dataTypeMapper) static int
getPrimitiveSizeof
(Class<?> fieldType) static Class
<?> getPrimitiveWrapper
(Class<?> primitiveType) static boolean
hasStructureMapping
(Class<?> clazz) static void
invokeMethods
(List<Method> methods, Object obj, Object... params) static boolean
isPrimitiveType
(Class<?> clazz) static Method
requireGetter
(Class<?> clazz, String getterName)
-
Constructor Details
-
ReflectionHelper
public ReflectionHelper()
-
-
Method Details
-
isPrimitiveType
-
getPrimitiveWrapper
-
assignField
Write a value to a field in a java class.- Parameters:
field
- reflectionField
obj
- java instance that contains the fieldvalue
- value to write- Throws:
IOException
- if error accessing field or converting value
-
getArrayOutputDataType
public static DataType getArrayOutputDataType(Object array_value, Class<?> fieldType, int length, Signedness signedness, DataTypeMapper dataTypeMapper) Return Ghidra data type representing an array of primitive values.- Parameters:
array_value
- java array objectfieldType
- class representing the java array typelength
- length of an element of the array, or -1signedness
-Signedness
enumdataTypeMapper
- program level structure mapping context- Returns:
- Ghdira
ArrayDataType
representing the specified java array type
-
getPrimitiveOutputDataType
public static DataType getPrimitiveOutputDataType(Class<?> fieldType, int length, Signedness signedness, DataTypeMapper dataTypeMapper) -
getPrimitiveSizeof
-
hasStructureMapping
-
getDataTypeSignedness
-
getCommentMethod
-
requireGetter
-
findGetter
-
findSetter
-
getCtor
-
invokeMethods
public static void invokeMethods(List<Method> methods, Object obj, Object... params) throws IOException - Throws:
IOException
-
createInstance
public static <T,CTX> T createInstance(Class<T> targetClass, CTX optionalContext) throws IllegalArgumentException Creates an instance of the specified target class, using an optional context parameter to the constructor.- Type Parameters:
T
- type of the class to be createdCTX
- type of the context to be passed to the constructor- Parameters:
targetClass
- class to be createdoptionalContext
- anything, or null- Returns:
- new instance of type T
- Throws:
IllegalArgumentException
- if error creating instance
-
callCtor
- Throws:
IllegalArgumentException
-
callGetter
- Throws:
IOException
-
callGetter
public static <T,R> R callGetter(Method getterMethod, T obj, Class<R> expectedType) throws IOException - Throws:
IOException
-
callSetter
- Throws:
IOException
-
getMarkedMethods
public static List<Method> getMarkedMethods(Class<?> targetClass, Class<? extends Annotation> annotationClass, List<Method> methods, boolean includeParentClasses, Class<?>... paramClasses) Returns a list of methods that have been marked with a specific annotation.- Parameters:
targetClass
- class to queryannotationClass
- annotation to search formethods
- list to accumulate results into, or null to allocate new list. Also returned as the result of this functionincludeParentClasses
- boolean flag, if true recurse into parent classes firstparamClasses
- list of parameters that the tagged methods should declare. Methods will be skipped if they don't match- Returns:
- list of found methods that match the annotation and param list
-
getAnnotations
public static <T extends Annotation> List<T> getAnnotations(Class<?> targetClass, Class<T> annotationClass, List<T> result) -
getFieldValue
public static <R> R getFieldValue(Object obj, Field field, Class<R> expectedType) throws IOException - Throws:
IOException
-