您可以使用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);
}
}