java 编辑/修改已编译类文件的最简单方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10445791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 01:04:29  来源:igfitidea点击:

Easiest way to edit/modify compiled class file

javadecompiling

提问by Stackie Overflower

My main problem is that i have some class files from a game where i wan't to edit/modify parts of it

我的主要问题是我有一些来自游戏的类文件,我不想编辑/修改其中的某些部分

What would be the easiest way to achieve this ?

实现这一目标的最简单方法是什么?

Decompiling the whole code and recompiling is not an option unless you have some decompiler that doesn't cause errors in the source code, as i do not wish to spend time fixing them.

除非您有一些不会导致源代码错误的反编译器,否则反编译整个代码并重新编译不是一种选择,因为我不想花时间修复它们。

Best regards

最好的祝福

回答by Kartoch

A solution could be the use of bytecode manipulators like ASMor BCEL. They both provide an API to load a class file, change part of it and save it. ASM has the advantage to be able to do this during runtime.

一个解决方案可能是使用字节码操纵器,如ASMBCEL。它们都提供了一个 API 来加载类文件、更改其中的一部分并保存它。ASM 的优势在于能够在运行时执行此操作。

回答by Antimony

You can also use the Krakatau disassembler/assemblerI wrote. The disassembler turns a class file into a human readable (well readable if you understand bytecode anyway) format, which you can then edit and reassemble. This is useful if you want to view and edit the classfiles by hand, where writing a bunch of library calls and then compiling and running a program just to use ASM or BCEL is rather unwieldy.

您也可以使用我编写的Krakatau 反汇编器/汇编器。反汇编器将类文件转换为人类可读的(如果您理解字节码,则可读)格式,然后您可以对其进行编辑和重新组装。如果您想手动查看和编辑类文件,这很有用,在这种情况下,编写一堆库调用然后编译和运行程序只是为了使用 ASM 或 BCEL 是相当笨拙的。

Krakatau also has a decompiler specifically designed to handle obfuscated classes, so it may be able to produce valid source code even when no other decompiler can. Of course if the class is obfuscated, the generated source will probably still be unreadable.

Krakatau 还有一个专门设计用于处理混淆类的反编译器,因此即使其他反编译器无法生成有效的源代码,它也可以生成有效的源代码。当然,如果类被混淆,生成的源代码可能仍然无法读取。