java - ASM to search for a String in .class file -
hi want search particular string in /java/lang/string.class file using asm. got know following method that
@override public string readutf8(int index, char[] buf) { string value = super.readutf8(index, buf); constantpoolstrings.add(value); return value; }
but not sure how use .i posting code, can please tell me how can achived in this.
public class democlassreader { public static void main(string[] args) throws ioexception { classvisitor v= new classvisitor(opcodes.asm4) { @override public void visit(int version, int access, string name, string signature, string supername, string[] interfaces) { system.out.println(" class: "+name); super.visit(version, access, name, signature, supername, interfaces); } } ; inputstream in=string.class.getresourceasstream("/java/lang/string.class"); classreader classreader=new classreader(in); classreader.accept(v, 0); }
for capturing string literals can implement following methodvisitor:
classreader classreader = new classreader(in); classreader.accept(new classvisitor(opcodes.v1_7) { public visitmethod(int access, string name, string desc, string signature, string[] exceptions) { return new methodvisitor(opcodes.v1_7) { public void visitldcinsn(object cst) { if(cst instanceof string) { // capture string } } }; } }, 0);
see visitldcinsn(..) in javadoc.
Comments
Post a Comment