import org.apache.bcel.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.generic.*;
public class BCELExample {
public static void main(String[] args) {
JavaClass jclass = Repository.lookupClass("com.example.MyClass");
ConstantPoolGen cpgen = new ConstantPoolGen(jclass.getConstantPool());
Method[] methods = jclass.getMethods();
for (Method method : methods) {
InstructionList ilist = new InstructionList(method.getCode().getCode());
InstructionFactory factory = new InstructionFactory(cpgen);
ilist.dispose();
ilist.append(factory.createPrintln("Hello, BCEL!"));
method.getCode().setCode(ilist.getByteCode());
System.out.println(method.getCode().toString());
}
jclass.dump("modified_class.class");
}
}