How to know if the method is static using java instrumentation and ASM -
i using java instrumentation , asm manipulate java byte code. how can know if function static?
i tried using modifier.isstatic cant run inside instrumentation. can know using asm functions?
i need in order function arguments. if function not static, object sits in index 0 @ stack
i suggest looking @ localvariablenodes of methodnode in question. if first variable in list calling "methodnodename".localvariables instance of class methodnode belongs methodnode not static, , vice versa.
to parameters of method use this
string raw = arrays.tostring(type.getargumenttypes("methodnodename".desc)); int numparams = (arrays.aslist(raw.split(",[ ]*"))).size(); this return number of params in method. since first variables put localvariable list params simple matter of extracting first [1,numparams] variables params.
for example given
public void methodname(int arg0, int arg1){ ....} the first 3 variables in local variable list starting index 0 ("object of type method belongs to", "object of type int", "object of type int", ....)
where as
public static void methodname(int arg0, int arg1){ ....} would yield ("object of type int", "object of type int", ...)
please note making assumption method in question doesn't take first parameter object of class method belongs.
cheers
edit:
as alternative solution can check see if localvariablenodes.get(0).equals("this") true; if true method non static , vice versa. if method not have localvariables method static
Comments
Post a Comment