Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

java - How to change methods in .class file without recompiling

I need to change existing compiled .class file. Actually I have even sources of it, but I cannot just change and recompile it because of many dependencies that I don't have.

So I need to change 2 methods. Both them have void return type. The first contains just 2 lines that are calls of another methods of the same class, i.e.

public void a() {
    System.out.println("a");
}

public void b() {
    System.out.println("b");
}

public void ca() {
    a();
    b();

}

And I need to change method ca sp that it calls only a() method.

The second method that I need to change contains some logic, but I want to clear it at all, i.e. to have method with empty body that does nothing.

How can I do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you don't have the required dependencies, how are you expecting to use this code? I would strongly recommend that you devote your time to being able to compile this normally, instead of trying to just change the binary. It's likely to be a better bet in the long run.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...