Esempio n. 1
0
  /**
   * check whether a class should not be considered for transformation
   *
   * @param clazz the class to check
   * @return true if clazz should not be considered for transformation otherwise false
   */
  protected boolean isSkipClass(Class<?> clazz) {
    if (!inst.isModifiableClass(clazz)) {
      return true;
    }

    // we can safely skip array classes, interfaces and primitive classes

    if (clazz.isArray()) {
      return true;
    }

    if (clazz.isInterface()) {
      return true;
    }

    if (clazz.isPrimitive()) {
      return true;
    }

    String name = clazz.getName();

    if (isBytemanClass(name) || !isTransformable(name)) {
      return true;
    }

    return false;
  }
Esempio n. 2
0
 /**
  * use the supplied bytes to define a class and try creating an instance via the empty
  * constructor printing details of any errors which occur
  *
  * @param classname
  * @param protectionDomain
  * @param bytes
  * @return the bytes if all goes well otherwise null
  */
 public byte[] verify(String classname, ProtectionDomain protectionDomain, byte[] bytes) {
   try {
     Class clazz = super.defineClass(classname, bytes, 0, bytes.length, protectionDomain);
     clazz.newInstance();
   } catch (Throwable th) {
     System.out.println("Transformer:verifyTransformedBytes " + th);
     return null;
   }
   return bytes;
 }
Esempio n. 3
0
  private boolean isTransformed(Class clazz, String name, boolean isInterface) {
    if (isBytemanClass(name) || !isTransformable(name)) {
      return false;
    }

    boolean found = false;
    List<RuleScript> scripts;
    if (isInterface) {
      scripts = scriptRepository.scriptsForInterfaceName(name);
    } else {
      scripts = scriptRepository.scriptsForClassName(name);
    }
    if (scripts != null) {
      for (RuleScript script : scripts) {
        if (!script.hasTransform(clazz)) {
          found = true;
          if (isVerbose()) {
            System.out.println("Retransforming loaded bootstrap class " + clazz.getName());
          }
          break;
        }
      }
    }

    return found;
  }