• jar文件 反编译(IDEA环境)


    说明

    想要对一些 jar 文件进行反编译,由于现在 IDEA 使用的人比较多,比较方便的方法是,可以使用 IDEA 中的插件进行反编译。

    IDEA 插件

    可以使用 IDEA 中的 "Java Bytecode Decompiler",该插件一般都内置了,可以直接使用。找到该插件的位置。

    • Java Bytecode Decompiler 位置:D:\DevTools\JetBrains\IntelliJ IDEA 2021.1\plugins\java-decompiler\lib\java-decompiler.jar

    • 要反编译的jar包位置:F:\javadecom\helloworld.jar

    打开控制台,进入到要反编译的 jar 包的目录中,反编译命令:

    java -cp "D:/DevTools/JetBrains/IntelliJ IDEA 2021.1/plugins/java-decompiler/lib/java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -dgs=true F:/javadecom/helloworld.jar data

    说明

    • org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler:是插件的启动类。

    • data:是在要反编译的 jar 包路径下的一个文件夹,需要提前创建好,反编译后的结果会放在该文件夹中。

    执行命令,此时出现一个错误,如下图所示:

    错误详细信息:

    1. F:\javadecom>java -cp "D:/DevTools/JetBrains/IntelliJ IDEA 2021.1/plugins/java-decompiler/lib/java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -dgs=true F:/javadecom/helloworld.jar data
    2. Error: A JNI error has occurred, please check your installation and try again
    3. Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    4. at java.lang.ClassLoader.defineClass1(Native Method)
    5. at java.lang.ClassLoader.defineClass(Unknown Source)
    6. at java.security.SecureClassLoader.defineClass(Unknown Source)
    7. at java.net.URLClassLoader.defineClass(Unknown Source)
    8. at java.net.URLClassLoader.access$100(Unknown Source)
    9. at java.net.URLClassLoader$1.run(Unknown Source)
    10. at java.net.URLClassLoader$1.run(Unknown Source)
    11. at java.security.AccessController.doPrivileged(Native Method)
    12. at java.net.URLClassLoader.findClass(Unknown Source)
    13. at java.lang.ClassLoader.loadClass(Unknown Source)
    14. at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    15. at java.lang.ClassLoader.loadClass(Unknown Source)
    16. at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

    意思是 JDK11 编译的代码,无法使用 JDK8 反编译。

    此时需要下载一个 JDK11,下载好后,可以指定使用 JDK11 进行反编译。

    • JDK11 位置:D:\DevTools\Java\jdk-11.0.12\bin\java.exe

    指定使用 JDK11 反编译命令:

    D:/DevTools/Java/jdk-11.0.12/bin/java.exe -cp "D:/DevTools/JetBrains/IntelliJ IDEA 2021.1/plugins/java-decompiler/lib/java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -dgs=true F:/javadecom/helloworld.jar data
    

    反编译完成后,会在 data 目录中生成 jar 反编译的文件。

    将该文件解压出来,就是反编译的代码。

  • 相关阅读:
    Docker ------compose概述与简单编排部署
    vue2和vue3浏览器兼容性对比
    WMS仓库管理系统库位功能
    Java与React轻松导出Excel/PDF数据
    MiniConda、CUDA、CUDnn以及pytorch环境的配置以及坑
    超详细的顺序表(附源码)
    【MyBatis笔记08】Mybatis中常用的一些操作
    DM8数据守护集群安装部署_手动切换
    操作系统底层知识总结(面试)
    关于vue中关于eslint报错的问题
  • 原文地址:https://blog.csdn.net/xsq123/article/details/125996990