Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class transformer in JAVA ASM - can it be generated?

I'd like to start using Java ASM to transform classes in my project - to add one String argument to some methods and send log with this argument.

On asm website I've read

If you want to implement a class transformer, write two Java source files (before and after transformation) and use the compare view of the plugin in ASMifier mode to compare the equivalent ASM code.

But I find using Java ASM extremely hard. Is there any tool which can generate class transformer? It would be very useful!

like image 207
alicjasalamon Avatar asked Oct 27 '25 05:10

alicjasalamon


2 Answers

Have a look at the ASMifier class. This can be used to generate the code to create the byte code. http://asm.ow2.org/doc/tutorial.html

You might find other tools such as Javassist or BCEL easier for simple tasks.

like image 73
Peter Lawrey Avatar answered Oct 29 '25 20:10

Peter Lawrey


If you are using Eclipse, you should install Bytecode Outline - it calls ASMifier (mentioned by Peter Lawry in another answer) and provides a view that can inspect every class or method.

EDIT (copied from my comment below)
To get to the transformer you need, follow theses steps: write an example method, copy the code to create it (which you get by clicking the Icon with "ASM" on it), change its sources to what you want it to be after transformation, copy its output, put them in a diff program (I like and recommend Diffuse). See what changed in the ASM code, apply it in your ASM transformer.

like image 31
Arne Avatar answered Oct 29 '25 18:10

Arne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!