2

Does anybody know if any tool/library exists able to assemble output of ASM Textifier into a classfile?

So, I have the following code:

final ClassReader classReader = new ClassReader(bytes);
final StringWriter writer = new StringWriter();
final PrintWriter printWriter = new PrintWriter(writer);
try {
  classReader.accept(new TraceClassVisitor(null, new Textifier(), printWriter), 0);
}
finally {
  printWriter.close();
}
String asmOutput = writer.toString();

Now I wish to assemble asmOutput back to class file. Does anybody implemented such handy thing or no?

Looks like that the only solution is to use JasminifierClassAdapter.java from ASM examples. But Jasmin itself is almost dead and outdated, so this solution is quiet imperfect.

Pavel S.
  • 1,267
  • 14
  • 19
  • 1
    Sounds like an [XY problem](http://meta.stackexchange.com/a/66378/166789). There are several ways to analyze a class and regenerate it from there, potentially with transformations. Using the textifier output as intermediate representation makes little sense, if any. – Holger Jul 05 '16 at 11:00
  • 1
    Nope. I need exactly what I said. I need editable textual representation of a classfile. And I need to be able to reassemble it back into classfile. Krakatau can do that, but it's a python-based tool, it doesn't work for me. Jasper+Jasmin are nice but outdated and tight-coupled and need a lot of refactorings. – Pavel S. Jul 05 '16 at 11:50
  • Well, you didn’t say exactly that you need an “editable textual representation of a classfile”, that’s the point. You asked for a way to parse the specific output of `Textifier`, which is not suitable for that task. – Holger Jul 05 '16 at 13:20
  • There is [support for an XML representation](http://asm.ow2.org/asm50/javadoc/user/?org/objectweb/asm/xml/package-summary.html) which can be safely converted back and forth. Also [`ASMifier`](http://asm.ow2.org/asm50/javadoc/user/?org/objectweb/asm/util/ASMifier.html) produces an output that intrinsically supports to be edited and can used to create a class file again. There are other ways too, but of course, only the developer knowing the actual purpose can pick the most suitable one, that’s one reason why question only asking for software are considered off-topic on [so]. – Holger Jul 05 '16 at 13:27
  • Oh, thanks for hint regarding XML representation. For now I've solved my problem with Jasmin, but it should be lot more convenient to deal with XML representation (but it's still need to be converted into something "human editable" ans vice versa, XML itself is not a good option). – Pavel S. Jul 05 '16 at 14:27

0 Answers0