Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to decompile jar implementations

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the ways of decompiling jar implementation". In daily operation, I believe that many people have doubts about the way of decompiling jar implementation. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "decompilation jar implementation ways". Next, please follow the editor to study!

Tool preparation

The same large version of jdk

Idea

Fernflower.jar

Javassist.jar

Jd-gui

There are three ways 1. Decompile with fernflower before compiling

Modify the .jar to be decompiled to .zip

Java-jar fernflower.jar classes.zip zzCode/

You can get a jar file that is all java, decompress it with compression software and import it into idea.

two。 Use javassist to dynamically modify classimport javassist.ClassPool;import javassist.CtClass;import javassist.CtMethod;import java.util.Map;import javassist.NotFoundException;public class main {public static void main (String [] args) throws Exception {try {ClassPool pool = ClassPool.getDefault (); / / specify the path pool.insertClassPath ("C:\\ rike.jar") where the class is located / / specify the introduced package, which is not needed here, so comment out / / pool.importPackage ("dialog.DialogUtils"); / / pool.importPackage ("common.ListenerUtils"); / / pool.importPackage ("java.util.Map"); / / specify the full class name of class to be modified CtClass cc = pool.get ("aggressor.dialogs.WindowsExecutableDialog") / / set the parameters required by the method to be modified. If there are no parameters, you can not set CtClass [] param = new CtClass [5]; param [0] = pool.get ("java.util.Map"); param [1] = pool.get ("dialog.DialogUtils"); param [2] = pool.get ("common.ListenerUtils") / / specify the class method CtMethod m = cc.getDeclaredMethod ("dialogAction") to be modified; / / if you need to modify the parameters, use the following / / CtMethod m = cc.getDeclaredMethod ("dialogAction", param); / / insert the new code to the front / / m.insertBefore ("{if (true) class;}") / / reset the method body m.setBody ("{System.out.println (\" hi class1\ ");}"); / / Save to the file, and the file will be kept under the project cc.writeFile ();} catch (Exception e) {e.printStackTrace ();}

A class file is generated, which can be copied directly to the jar package

Note that in the setBody package, use $0 for this $1 for the first parameter $2 for the second parameter

3. Modify the code by introducing the original jar package (recommended)

When I was testing, I used this method because the jar file was more complex and there were a lot of errors reported in the previous method.

Create a folder under the corresponding directory of the class file you want to modify, for example, in idea, under the src folder of the project

Modify the code inside, and then use the shortcut key ctrl+alt+shift+s in idea to introduce the complete jar package

Just introduce it at the plus sign.

Create a new generation jar

Click build

Just generate it.

Or modify the generated class file directly in the jar package

There is a generated class file under the out\ production\ folder of the project. Drag it directly to the original jar to modify it.

At this point, the study of "what are the ways to decompile jar implementations" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report