Reputation: 18123
For my bytecode analysis project, I am using ASM library to manipulate bytecodes. At bytecode level this method declaration in source code:
void m(int i, String s)
is represented as a String:
(ILjava/lang/String;)[I
|__ Parameters |__ Return type
here I am using string manipulation techniques to extract parameters out of that String. I need to get output like this in another String array: (So that I can convert byte code representation to corresponding Java representation):
{I,Ljava/lang/String;}
for this I have tried following regex to extract all the matches which Start with L
and end with ;
(to get Strings which are in the form of Ljava/lang/String;, others I can manage):
/\L([^L;]+)\;/
But it is not returning me any matches. My question is:
Bytecode representations --> Java code representations
?Upvotes: 0
Views: 419
Reputation: 8156
You can read method desc
using org.objectweb.asm.Type
String desc = "(ILjava/lang/String;)[I";
// params
for(Type type : Type.getArgumentTypes(desc)){
System.out.println(type.getClassName());
}
//return type
System.out.println(Type.getReturnType(desc).getClassName());
output
int
java.lang.String
int[]
Upvotes: 4
Reputation: 6167
As for the regexp, this should do the trick (the parameter type is in the first capture group afterwards, the whole match does match the L and the ;, too)
/L([^;]+);/
And here is one that should match the return type (if the string ends after the return type... if you have omitted something, tell me):
/\)\[(.+)$/
Upvotes: 1