How to Get ByteArray of Classes in ASM

694 Views Asked by At

I am trying to implement method call application with CHA,XTA,RTA .For this purpose i use ASM.What should be bytecode variable below?How can i traverse all classes of Java project.

ClassReader cr = new ClassReader(bytecode);
ClassNode cn = new ClassNode();
cr.accept(cn, ClassReader.SKIP_DEBUG);

  List methods = cn.methods;
  for (int i = 0; i < methods.size(); ++i) {
       MethodNode method = (MethodNode) methods.get(i);
       if (method.instructions.size() > 0) {..}
  }
1

There are 1 best solutions below

0
On

Each class is in its own file. You traverse classes, in the same manner as you traverse files. e.g.

 public static void traverse(File dir) {
     for(File file: dir.listFiles()) {
         if (file.isDirectory())
             traverse(file);
         else
             processWithASM(file);
     }
 }

If the classes are in a JAR or ZIP file, you need to read that file.