0

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) {..}
  }
cyo
  • 193
  • 2
  • 4
  • 17
  • Q: What exactly are you trying to do? Interface Java and assembler (is that what you mean by "asm")? If so, you need to look at JNI: http://docs.oracle.com/javase/7/docs/technotes/guides/jni/ – FoggyDay Dec 29 '13 at 08:38
  • Asm Java bytecode manipulation and analysis framework.http://asm.ow2.org/asm40/javadoc/user/index.html.I am trying to implement method call graph of a Java project using some method call graph construction algoritjm like XTA,CHA.. – cyo Dec 29 '13 at 09:10

1 Answers1

1

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130