是否可以转储由 java ASM 检测的字节码?
Is it possible to dump the bytecode instrumented by java ASM?
我正在学习 Java ASM,方法是在方法中插入一些简单的指令,例如 println
。是否可以转储动态检测的字节码以便我检查正确性?
您可以使用 TraceClassVisitor 来实现此目的:
StringWriter sw = new StringWriter();
ClassVisitor tracer = new TraceClassVisitor(writer,new PrintWriter(sw));
ClassVisitor visitor = new YourClassVisitor(tracer, className);
ClassVisitor checker = new CheckClassAdapter(visitor, true);
cr.accept(checker, ClassReader.EXPAND_FRAMES);
System.out.println(sw.toString());
我正在学习 Java ASM,方法是在方法中插入一些简单的指令,例如 println
。是否可以转储动态检测的字节码以便我检查正确性?
您可以使用 TraceClassVisitor 来实现此目的:
StringWriter sw = new StringWriter();
ClassVisitor tracer = new TraceClassVisitor(writer,new PrintWriter(sw));
ClassVisitor visitor = new YourClassVisitor(tracer, className);
ClassVisitor checker = new CheckClassAdapter(visitor, true);
cr.accept(checker, ClassReader.EXPAND_FRAMES);
System.out.println(sw.toString());