I want to modify a specific library with ASM for log or modify content.
Simply I create an example at above two method for example.
I want to convert realMethod to iWantAsLikeThis method with ASM.
Usually add like INVOKESTATIC asmTest/Testt.logGet (Ljava/net/URL;)Ljava/net/URL;
code enough but sometimes it is not enough as at bottom I highlight with ______ and there is like DUP
and POP
and maybe another things for different codes.
So what can I do for generic wrapping to modify classes of specific libraries.
Note: I don't want to modify constructer (<init>
) method, I want to modify usages of its.
public class Testt {
public void realMethod() throws Exception {
URL u1 = new URL("http://1.1.1.1");
URL u2 = new URL("http://2.2.2.2");
System.out.println(u1);
}
public void iWantAsLikeThis() throws Exception {
URL u1 = logGet(new URL("http://1.1.1.1"));
URL u2 = logGet(new URL("http://2.2.2.2"));
System.out.println(u1);
}
public static URL logGet(URL u) {
System.out.println(u.getHost());
return u;
}
/**
* NEW java/net/URL
* DUP
* LDC "http://1.1.1.1"
* INVOKESPECIAL java/net/URL.<init> (Ljava/lang/String;)V
* _________INVOKESTATIC asmTest/Testt.logGet (Ljava/net/URL;)Ljava/net/URL;
* ASTORE 1
* NEW java/net/URL
* _________DUP
* LDC "http://2.2.2.2"
* INVOKESPECIAL java/net/URL.<init> (Ljava/lang/String;)V
* _________INVOKESTATIC asmTest/Testt.logGet (Ljava/net/URL;)Ljava/net/URL;
* _________POP
* GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
* ALOAD 1
* INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/Object;)V
* RETURN
* MAXSTACK = 3
* MAXLOCALS = 2
*/
}