printing - How can I print parameters's values of different methods with java asm? -
so want print parameters's values of different methods.
for example if method is
void print(string string,int number) { system.out.println(number +" " + string); }
i want able like
void print(string string,int number) { mylogger.log(methodname,string,number); system.out.println(number +" " + string); }
so pass parameters of class own logger can print them out. don't know how transfer bytecode (asm).
so far have managed print method's name code: (classdata class contains methods in classes should hook into)
public class mytransformer implements classfiletransformer { @override public byte[] transform(classloader classloader, string s, class<?> aclass, protectiondomain protectiondomain, byte[] bytes) throws illegalclassformatexception { for(classdata classdata : myagent.classes) { string classname = classdata.classname; if (classname.equals(s)) { classreader cr=new classreader(bytes); classnode cn=new classnode(); cr.accept(cn,classreader.expand_frames); (object o : cn.methods.toarray()) { methodnode m = (methodnode) o; for(string method : classdata.methods) { if(method.equals(m.name)) { insnlist beginlist=new insnlist(); beginlist.add(new ldcinsnnode(m.name)); beginlist.add(new methodinsnnode(opcodes.invokestatic, "agent/security/logger", "println", "(ljava/lang/string;)v")); iterator<abstractinsnnode> insnnodes=m.instructions.iterator(); while(insnnodes.hasnext()){ insnnodes.next(); } m.instructions.insert(beginlist); } } } classwriter cw=new classwriter(classwriter.compute_frames | classwriter.compute_maxs); cn.accept(cw); dataoutputstream dout= null; try { dout = new dataoutputstream(new fileoutputstream(new file(new random().nextint(255)+".class"))); dout.write(cw.tobytearray()); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return cw.tobytearray(); } } return new byte[0]; }}
i have tried print parameters values many different ways adding instructions after printing method name haven't had luck far. there pretty little information in web subject , topics managed find didn't have complete answer parts of question filled.
Comments
Post a Comment