content: package com.summersec.attack.deser.util;
  
  import com.nqzero.permit.Permit;
  import java.lang.reflect.AccessibleObject;
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Field;
  import java.lang.reflect.InvocationTargetException;
  import sun.reflect.ReflectionFactory;
  
  
  
  
  public class Reflections {
  
      public static void setAccessible(AccessibleObject member) {
          Permit.setAccessible(member);
      }
  
      public static Field getField(Class<?> clazz, String fieldName) {
          Field field = null;
          try {
              field = clazz.getDeclaredField(fieldName);
              setAccessible(field);
          }
          catch (NoSuchFieldException ex) {
              if (clazz.getSuperclass() != null) {
                  field = getField(clazz.getSuperclass(), fieldName);
              }
          }
          return field;
      }
  
      public static void setFieldValue(Object obj, String fieldName, Object value) throws Exception {
          Field field = getField(obj.getClass(), fieldName);
          field.set(obj, value);
      }
  
      public static Object getFieldValue(Object obj, String fieldName) throws Exception {
          Field field = getField(obj.getClass(), fieldName);
          return field.get(obj);
      }
  
      public static Constructor<?> getFirstCtor(String name) throws Exception {
          Constructor<?> ctor = Class.forName(name).getDeclaredConstructors()[0];
          setAccessible(ctor);
          return ctor;
      }
  
      public static Object newInstance(String className, Object... args) throws Exception {
          return getFirstCtor(className).newInstance(args);
      }
  
  
      public static <T> T createWithoutConstructor(Class<T> classToInstantiate) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
          return createWithConstructor(classToInstantiate, (Class<? super T>) Object.class, new Class[0], new Object[0]);
      }
  
  
  
      public static <T> T createWithConstructor(Class<T> classToInstantiate, Class<? super T> constructorClass, Class<?>[] consArgTypes, Object[] consArgs) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
          Constructor<? super T> objCons = constructorClass.getDeclaredConstructor(consArgTypes);
          setAccessible(objCons);
          Constructor<?> sc = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(classToInstantiate, objCons);
          setAccessible(sc);
          return (T)sc.newInstance(consArgs);
      }
  }
  
  
  
  