Category Archives: bcel

Dealing with "If" condition for java code using Apache- Byte Code Engineering Library(BCEL)

How to insert an instrumented code inside an "if" statement of a java code using Apache BCEL ?

============== Code =============

public class sample {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    int i = 10;
    System.out.println("From sample.java");
    System.out.println("i : "+i);


    if(i == 10){
        System.out.println("Hello Again" );
        System.out.println("print i : "+i );    
    }       
}

}

So, here i want to insert the instrumented code within if condition.

How parsing classfile in java?

how can i parse class file in java ,,in this code,i parse current classfile calles bcel, but if i want to parse other classfile in other package for example (netbeans/src/filename.class),what should i do ?how can parse any class file by it's path? this code can apply only on the same (current class file),but i want a way to parse any class file by it's path ,can i do this and how??

   package bcel;

   public class bcel {

   public static void main(String[] args) throws IOException  {

   ClassParser parser=new 

   ClassParser(bcel.class.getResourceAsStream("/bcel/bcel.class"), "bcel.class");
  JavaClass javaClass=parser.parse(); }}