java 需要帮助反编译jar文件,编辑a类,并保存为jar文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17956922/
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-11-01 19:43:00  来源:igfitidea点击:

Need assistance to decompile a jar file, edit the a class, and save as jar file

javareverse-engineeringexecutable-jardecompiler

提问by user2635337

I have a jar file, and I need to edit a particular class and save it back into the jar file. I tried different decompilers, but I'm not able to save back to the jar.

我有一个 jar 文件,我需要编辑一个特定的类并将其保存回 jar 文件。我尝试了不同的反编译器,但无法保存回 jar。

I tried Eclipse along with JADCLIPSE to decompile. By using that, I can see the decompiled class file, but I'm unable to edit it. Could anyone please help me to resolve this?

我尝试使用 Eclipse 和 JADCLIPSE 进行反编译。通过使用它,我可以看到反编译的类文件,但我无法编辑它。有人可以帮我解决这个问题吗?

回答by Robadob

I use JD-GUIto decompile .jar's, this has an option to export all the decompiled classes. If the .jar you are decompiling has not been obfuscated etc this source should be re-compilable (otherwise you will need to go about it by bytecode editing).

我使用JD-GUI来反编译 .jar,这有一个选项可以导出所有反编译的类。如果您正在反编译的 .jar 没有被混淆等,那么这个源应该是可重新编译的(否则您将需要通过字节码编辑来进行)。

Once you have extracted the classes, you need to ensure when you compile you compile with the -CPparameter pointing at .;MyJar.jarso that dependencies within the .jar can be found at compile.

提取类后,您需要确保在编译时使用-CP指向的参数进行编译,.;MyJar.jar以便在编译时可以找到 .jar 中的依赖项。

After you have recompiled and have your new .class file/s, open the .jar with 7zand replace the old .class file/s with your new one. You can do this step with the command line jar tool but 7z makes it easier. Again if the jar was obfuscated and class files have identical names with only case sensitive differences you may need to use Linux to reinsert the .class file. (probably possible on Windows, but I've never looked into it too deeply).

重新编译并拥有新的 .class 文件后,用7z打开 .jar并用新的 .class 文件替换旧的 .class 文件。您可以使用命令行 jar 工具执行此步骤,但 7z 使其更容易。同样,如果 jar 被混淆并且类文件具有相同的名称,只有区分大小写的差异,您可能需要使用 Linux 重新插入 .class 文件。(可能在 Windows 上可行,但我从未深入研究过)。



I previously decompiled this Java program to add a commandline interface, you can probably find the link in the comments;

我之前反编译了这个Java程序,添加了命令行界面,大概可以在注释中找到链接;

http://ninjacave.com/jarsplice

http://ninjacave.com/jarsplice

回答by saurav

then there are lot of free utilities available like WinZip , 7-ZIP you can use them.

然后有很多免费实用程序可用,例如 WinZip 、 7-ZIP 您可以使用它们。

Before opening jar file just change the extension of jar to zip file and then extract that particular class file that you want to edit , then decompile it using any decompiler ,make the changes , compile it back and then finally put it back in the zip file.

在打开 jar 文件之前,只需将 jar 的扩展名更改为 zip 文件,然后提取要编辑的特定类文件,然后使用任何反编译器对其进行反编译,进行更改,重新编译,最后将其放回 zip 文件中。 .

Hope it helps.

希望能帮助到你。

Thanks

谢谢