Home > OS >  How do I use ASMifier on inner classes?
How do I use ASMifier on inner classes?

Time:12-15

I am trying to get an ASMified version of an inner class in java. My command looks something like this java -classpath "asm-all-3.3.1.jar:myjar.jar" org.objectweb.asm.util.ASMifierClassVisitor path/to/my/class$inner.class But it seems to only return the ASMified version of the outer class, what am I doing wrong here?

CodePudding user response:

You get to the problem when you try

echo path/to/my/outer$inner.class

which will print

path/to/my/outer.class

Your shell interprets $inner as as variable reference and since you likely have no such variable defined in your environment, it will substitute it with an empty text, which in this case leads to the path and name of the outer class.

Which demonstrates why silently doing the wrong thing is worse than failing with an error message (or exception).

When you prepend the dollar sign with a backslash, i.e. path/to/my/outer\$inner.class, it will be interpreted as a literal $ and work. Or lead to other errors, as the other answer mentions, your ASM version is really old and may have problems parsing newer class files.

CodePudding user response:

How about using an ASM version more recent than from 2008, maybe one which can also handle classes more recent than Java 6? I am suggesting these:

I quickly tried something like this (Git Bash on Windows 10):

java -cp "asm-9.2.jar;asm-util-9.2.jar" org.objectweb.asm.util.ASMifier MyClass\$MyInnerClass.class

In Cmd.exe it would be:

java -cp asm-9.2.jar;asm-util-9.2.jar org.objectweb.asm.util.ASMifier MyClass$MyInnerClass.class

Both variants work nicely.

  • Related