import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.*;
import org.apache.bcel.util.InstructionFinder;
import org.apache.bcel.Repository;
import java.util.Iterator;
import java.io.IOException;
public class Changer {
Changer(JavaClass jc) {
//Go through all the methods
for (Method m : jc.getMethods())
//if its the main method
if (m.getName().equalsIgnoreCase("main")) {
//Lets get the version number
System.out.print("Found main\n");
change(new MethodGen(m, jc.getClassName(), new ConstantPoolGen(jc.getConstantPool())));
}
}
public void change(MethodGen mg){
//GEt the instruction list
InstructionList il = mg.getInstructionList();
String iPat = "invokestatic";
String pattern = "invokestatic[184](3) 765";
InstructionFinder finder = new InstructionFinder(il);
InstructionFactory factory = new InstructionFactory(mg.getConstantPool());
for (Iterator it = finder.search(iPat); it.hasNext();) {
InstructionHandle[] match = (InstructionHandle[]) it.next();
INVOKESTATIC invokestatic = (INVOKESTATIC) match[0].getInstruction();
System.out.println(invokestatic.toString());
//System.out.println(invokestatic.getReturnType().toString());
}
}
}