howso57
howso57

Reputation: 31

Java ASM Visiting a method multiple times

I am working through many classes and transforming them. There are some classes that I do not have enough information for when I first visit them, and as such I need to revisit them. Since I do not know at the time of the first pass if I need to revisit, I copy the complete class with the first pass of modifications.

What I want to know is if it is possible to revisit a method and overwrite the method in the ClassWriter

byte[] b...
ClassReader cr = new ClassReader(b);
ClassWriter cw = new ClassWriter(read,0);
ClassAdapter ca = new ClassAdapter(cw);//First pass
cr.accept(ca,0);
ClassAdapter ca2 = new ClassAdapter(cw);//Second Pass
cr.accept(ca2,0);

The result of this code will give me verification errors due to duplicate field&method declarations.

Upvotes: 3

Views: 447

Answers (1)

someguy
someguy

Reputation: 7334

You would have to initialise a new ClassReader using the new bytecode read from cw.toByteArray(). From there, you would repeat the other steps (new ClassWriter, new ClassAdapter etc.)

Upvotes: 2

Related Questions