Search in sources :

Example 41 with ClassReader

use of org.objectweb.asm.ClassReader in project spring-loaded by spring-projects.

the class SpringPlugin method bytesWithInstanceCreationCaptured.

/**
	 * Modify the supplied bytes such that constructors are intercepted and will invoke the specified class/method so
	 * that the instances can be tracked.
	 *
	 * @return modified bytes for the class
	 */
private byte[] bytesWithInstanceCreationCaptured(byte[] bytes, String classToCall, String methodToCall) {
    ClassReader cr = new ClassReader(bytes);
    ClassVisitingConstructorAppender ca = new ClassVisitingConstructorAppender(classToCall, methodToCall);
    cr.accept(ca, 0);
    byte[] newbytes = ca.getBytes();
    return newbytes;
}
Also used : ClassReader(org.objectweb.asm.ClassReader)

Example 42 with ClassReader

use of org.objectweb.asm.ClassReader in project spring-loaded by spring-projects.

the class EmptyCtor method invoke.

/**
	 * Empty the constructors with the specified descriptors.
	 * 
	 * @param bytesIn input class as bytes
	 * @param descriptors descriptors of interest (e.g. "()V")
	 * @return modified class as byte array
	 */
public static byte[] invoke(byte[] bytesIn, String... descriptors) {
    ClassReader cr = new ClassReader(bytesIn);
    EmptyCtor ca = new EmptyCtor(descriptors);
    cr.accept(ca, 0);
    byte[] newbytes = ca.getBytes();
    return newbytes;
}
Also used : ClassReader(org.objectweb.asm.ClassReader)

Example 43 with ClassReader

use of org.objectweb.asm.ClassReader in project spring-loaded by spring-projects.

the class ClassPrinter method print.

public static void print(byte[] bytes, boolean includeBytecode) {
    ClassReader reader = new ClassReader(bytes);
    reader.accept(new ClassPrinter(System.out, includeBytecode ? INCLUDE_BYTECODE : 0), 0);
}
Also used : ClassReader(org.objectweb.asm.ClassReader)

Example 44 with ClassReader

use of org.objectweb.asm.ClassReader in project spring-loaded by spring-projects.

the class ClassPrinter method print.

public static void print(byte[] bytes, int includeFlags) {
    ClassReader reader = new ClassReader(bytes);
    reader.accept(new ClassPrinter(System.out, includeFlags), 0);
}
Also used : ClassReader(org.objectweb.asm.ClassReader)

Example 45 with ClassReader

use of org.objectweb.asm.ClassReader in project spring-loaded by spring-projects.

the class ClassPrinter method print.

public static void print(PrintStream printStream, byte[] bytes, boolean includeBytecode) {
    ClassReader reader = new ClassReader(bytes);
    reader.accept(new ClassPrinter(printStream, includeBytecode ? INCLUDE_BYTECODE : 0), 0);
}
Also used : ClassReader(org.objectweb.asm.ClassReader)

Aggregations

ClassReader (org.objectweb.asm.ClassReader)450 ClassWriter (org.objectweb.asm.ClassWriter)188 Test (org.junit.Test)134 IOException (java.io.IOException)78 InputStream (java.io.InputStream)76 TreeMap (java.util.TreeMap)59 ClassNode (org.objectweb.asm.tree.ClassNode)58 ClassVisitor (org.objectweb.asm.ClassVisitor)54 SemanticVersioningClassVisitor (org.apache.aries.versioning.utils.SemanticVersioningClassVisitor)53 HashSet (java.util.HashSet)39 ZipEntry (java.util.zip.ZipEntry)34 BinaryCompatibilityStatus (org.apache.aries.versioning.utils.BinaryCompatibilityStatus)32 ZipFile (java.util.zip.ZipFile)29 InvocationTargetException (java.lang.reflect.InvocationTargetException)26 Method (java.lang.reflect.Method)26 OuterClass (com.android.tools.layoutlib.create.dataclass.OuterClass)23 InnerClass (com.android.tools.layoutlib.create.dataclass.OuterClass.InnerClass)23 PrintWriter (java.io.PrintWriter)23 MethodVisitor (org.objectweb.asm.MethodVisitor)23 MethodNode (org.objectweb.asm.tree.MethodNode)21