如何在.class文件中更改方法,而无需重新编译 [英] How to change methods in .class file without recompiling

查看:143
本文介绍了如何在.class文件中更改方法,而无需重新编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更改现有的已编译的 .class 文件。实际上,我甚至有它的来源,但我不能只是改变和重新编译它,因为许多依赖,我没有。

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.

所以我需要改变2种方法。两者都有无效返回类型。第一个只包含两行,即调用同一类的另一个方法,即

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();

}

我需要更改方法 ca sp,它只调用一个()方法。

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.

我该如何做?

推荐答案

如果您没有所需的依赖项,您希望如何使用 ?我强烈建议你用你的时间能够正常编译,而不是试图只是改变二进制。从长远来看,这可能是一个更好的赌注。

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.

这篇关于如何在.class文件中更改方法,而无需重新编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆