Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get method signature with ObjectWeb ASM?

Purpose: Obtain the public method signature(return value,parameter,method name) from java bytecode files.

I am using the ObjectWeb ASM framework.

Problem: I scanned through the API specification of ASM and tried several examples, but I still have no idea about how to get the signature. The MethodNode class has a signature field, but the value is null.

like image 764
Fiary Avatar asked May 25 '11 00:05

Fiary


1 Answers

You can try something like this:

ClassReader cr = new ClassReader(is);
cr.accept(new EmptyVisitor() {
  public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if((Opcodes.ACC_PUBLIC & access)>0) {
      System.err.println("method name: " + name);
      System.err.println("return type: " + Type.getReturnType(desc));
      System.err.println("argument types: " + Arrays.toString(Type.getArgumentTypes(desc)));
    }
    return super.visitMethod(access, name, desc, signature, exceptions);
  }
}, 0);
like image 57
Eugene Kuleshov Avatar answered Sep 29 '22 16:09

Eugene Kuleshov