javabashjava-bytecode-asmash

How do I use ASMifier on inner classes?


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?


Solution

  • 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.