Hey all, I am trying to use the ASM bytecode Tree Api to do static analysis for a class. I guess I have a pretty basic question. In a method say foobar(), I have a list of instructions within foobar (InsnList which has a List). Now I want to check if at instruction number 10, whether a function "barfoo(String args)" is being invoked.
Also seperatly, I need to verify whether a particular instruction is a conditional.
Thanks and Regards, SJ
Note: I can already read a class and reach the particular method I am interested in and iterate through each intruction of that method.
Solved (see: Greg's comments):
AbstractInsnNode s = ... if(s.getType()==AbstractInsnNode.METHOD_INSN){ MethodInsnNode methodInvocationNode = (MethodInsnNode) s; if(methodInvocationNode.name.equals("barfoo")) { return true; } }
getType()on your instruction node, and if the type isMETHOD_INSNthen you can cast to aMethodInsnNode. From there, look at.nameto see the method name.