您可以使用 ASM 库来获取类的详细字节码。示例代码如下。
public class AAA extends ClassLoader{
public static void main(){
String resource = caller.replace('.', '/')+".class";
InputStream is = getResourceAsStream(resource);
ClassReader cr = new ClassReader(is);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassVisitor visitor = new BCMerge(Opcodes.ASM5, cw, callee);
cr.accept(visitor, 0);
}
}
class BCMerge extends ClassVisitor{
public MethodVisitor visitMethod(int access, String name, String desc,String signature, String[] exceptions) {
System.out.println(name);
if (cv != null) {
return new MyMethodVisit(cv.visitMethod(access, name, desc, signature, exceptions));
}
return null;
}
}
public class MyMethodVisit extends MethodVisitor{
@Override
public void visitMethodInsn(int opcode, String owner, String name,
String desc, boolean itf) {
System.out.println("opcode:" + opcode + " owner:" + owner + " name:"+ name + " desc:" + desc);
return super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}