Meaningless Drivel is fun!
The moose likes Java in General and the fly likes modify method in byte code using ASM. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "modify method in byte code using ASM." Watch "modify method in byte code using ASM." New topic
Author

modify method in byte code using ASM.

jing hu
Ranch Hand

Joined: Jun 30, 2009
Posts: 63
For the class Test

Now I have the Test.class and have no source code.
I want to modify method f() like below.
add " int j = 10;" before " inti = 10;"


using ASM how to implement this.
Thank you very much.
Ashok Suthar
Ranch Hand

Joined: Apr 05, 2007
Posts: 30
Hi,

Extend the test Class and override its methods which you want to modify... If that fulfils your purpose.

I am not sure what you are trying to do here.


SCJP 5 (98%)...SCWCD On
jing hu
Ranch Hand

Joined: Jun 30, 2009
Posts: 63
I don't want to recompile this .class. recompiling the class may be hard work.
int my thread , the Test is just only a sample.
So I want to do some modification in the .class file. That is my main purpose.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44048
    
  33
ASM? That's hardly a beginner's topic. I shall try moving this to "advanced."
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: modify method in byte code using ASM.
 
It's not a secret anymore!