Class ReflectionHelper
java.lang.Object
ghidra.app.util.bin.format.golang.structmapping.ReflectionHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassignField(Field field, Object obj, Object value) Write a value to a field in a java class.static <T> TcallCtor(Constructor<T> ctor, Object... params) static <T> ObjectcallGetter(Method getterMethod, T obj) static <T,R> R callGetter(Method getterMethod, T obj, Class<R> expectedType) static <T> voidcallSetter(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 MethodfindGetter(Class<?> structClass, String getterName) static MethodfindSetter(String fieldName, String setterNameOverride, Class<?> structClass, Class<?> valueClass) static <T extends Annotation>
List<T> getAnnotations(Class<?> targetClass, Class<T> annotationClass, List<T> result) static DataTypegetArrayOutputDataType(Object array_value, Class<?> fieldType, int length, Signedness signedness, DataTypeMapper dataTypeMapper) Return Ghidra data type representing an array of primitive values.static MethodgetCommentMethod(Class<?> clazz, String commentGetterName, String defaultGetterName) static <T> Constructor<T> static Signednessstatic <R> RgetFieldValue(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 DataTypegetPrimitiveOutputDataType(Class<?> fieldType, int length, Signedness signedness, DataTypeMapper dataTypeMapper) static intgetPrimitiveSizeof(Class<?> fieldType) static Class<?> getPrimitiveWrapper(Class<?> primitiveType) static booleanhasStructureMapping(Class<?> clazz) static voidinvokeMethods(List<Method> methods, Object obj, Object... params) static booleanisPrimitiveType(Class<?> clazz) static MethodrequireGetter(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- reflectionFieldobj- 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-SignednessenumdataTypeMapper- program level structure mapping context- Returns:
- Ghdira
ArrayDataTyperepresenting 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
-