日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Java反編譯工具的使用與對比分析

[[400055]]

本文轉(zhuǎn)載自微信公眾號「未讀代碼」,作者達西呀。轉(zhuǎn)載本文請聯(lián)系未讀代碼公眾號。

為大柴旦等地區(qū)用戶提供了全套網(wǎng)頁設計制作服務,及大柴旦網(wǎng)站建設行業(yè)解決方案。主營業(yè)務為網(wǎng)站設計、成都網(wǎng)站設計、大柴旦網(wǎng)站設計,以傳統(tǒng)方式定制建設網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

前言

Java 反編譯,一聽可能覺得高深莫測,其實反編譯并不是什么特別高級的操作,Java 對于 Class 字節(jié)碼文件的生成有著嚴格的要求,如果你非常熟悉 Java 虛擬機規(guī)范,了解 Class 字節(jié)碼文件中一些字節(jié)的作用,那么理解反編譯的原理并不是什么問題。甚至像下面這樣的 Class 文件你都能看懂一二。

一般在逆向研究和代碼分析中,反編譯用到的比較多。不過在日常開發(fā)中,有時候只是簡單的看一下所用依賴類的反編譯,也是十分重要的。

恰好最近工作中也需要用到 Java 反編譯,所以這篇文章介紹目前常見的的幾種 Java 反編譯工具的使用,在文章的最后也會通過編譯速度、語法支持以及代碼可讀性三個維度,對它們進行測試,分析幾款工具的優(yōu)缺點。

Procyon

Github 鏈接:https://github.com/mstrobel/procyon

Procyon 不僅僅是反編譯工具,它其實是專注于 Java 代碼的生成和分析的一整套的 Java 元編程工具。主要包括下面幾個部分:

  • Core Framework
  • Reflection Framework
  • Expressions Framework
  • Compiler Toolset (Experimental)
  • Java Decompiler (Experimental)

可以看到反編譯只是 Procyon 的其中一個模塊,Procyon 原來托管于 bitbucket,后來遷移到了 GitHub,根據(jù) GitHub 的提交記錄來看,也有將近兩年沒有更新了。不過也有依賴 Procyon 的其他的開源反編譯工具如** decompiler-procyon**,更新頻率還是很高的,下面也會選擇這個工具進行反編譯測試。

使用 Procyon

 
 
 
 
  1.  
  2.  
  3.     org.jboss.windup.decompiler 
  4.     decompiler-procyon 
  5.     5.1.4.Final 
  6.  

 

寫一個簡單的反編譯測試。

 
 
 
 
  1. package com.wdbyte.decompiler; 
  2.  
  3. import java.io.IOException; 
  4. import java.nio.file.Path; 
  5. import java.nio.file.Paths; 
  6. import java.util.Iterator; 
  7. import java.util.List; 
  8.  
  9. import org.jboss.windup.decompiler.api.DecompilationFailure; 
  10. import org.jboss.windup.decompiler.api.DecompilationListener; 
  11. import org.jboss.windup.decompiler.api.DecompilationResult; 
  12. import org.jboss.windup.decompiler.api.Decompiler; 
  13. import org.jboss.windup.decompiler.procyon.ProcyonDecompiler; 
  14.  
  15. /** 
  16.  * Procyon 反編譯測試 
  17.  * 
  18.  *  @author https://github.com/niumoo 
  19.  * @date 2021/05/15 
  20.  */ 
  21. public class ProcyonTest { 
  22.     public static void main(String[] args) throws IOException { 
  23.         Long time = procyon("decompiler.jar", "procyon_output_jar"); 
  24.         System.out.println(String.format("decompiler time: %dms", time)); 
  25.     } 
  26.     public static Long procyon(String source,String targetPath) throws IOException { 
  27.         long start = System.currentTimeMillis(); 
  28.         Path outDir = Paths.get(targetPath); 
  29.         Path archive = Paths.get(source); 
  30.         Decompiler dec = new ProcyonDecompiler(); 
  31.         DecompilationResult res = dec.decompileArchive(archive, outDir, new DecompilationListener() { 
  32.             public void decompilationProcessComplete() { 
  33.                 System.out.println("decompilationProcessComplete"); 
  34.             } 
  35.             public void decompilationFailed(List inputPath, String message) { 
  36.                 System.out.println("decompilationFailed"); 
  37.             } 
  38.             public void fileDecompiled(List inputPath, String outputPath) { 
  39.             } 
  40.             public boolean isCancelled() { 
  41.                 return false; 
  42.             } 
  43.         }); 
  44.  
  45.         if (!res.getFailures().isEmpty()) { 
  46.             StringBuilder sb = new StringBuilder(); 
  47.             sb.append("Failed decompilation of " + res.getFailures().size() + " classes: "); 
  48.             Iterator failureIterator = res.getFailures().iterator(); 
  49.             while (failureIterator.hasNext()) { 
  50.                 DecompilationFailure dex = (DecompilationFailure)failureIterator.next(); 
  51.                 sb.append(System.lineSeparator() + "    ").append(dex.getMessage()); 
  52.             } 
  53.             System.out.println(sb.toString()); 
  54.         } 
  55.         System.out.println("Compilation results: " + res.getDecompiledFiles().size() + " succeeded, " + res.getFailures().size() + " failed."); 
  56.         dec.close(); 
  57.         Long end = System.currentTimeMillis(); 
  58.         return end - start; 
  59.     } 

Procyon 在反編譯時會實時輸出反編譯文件數(shù)量的進度情況,最后還會統(tǒng)計反編譯成功和失敗的 Class 文件數(shù)量。

 
 
 
 
  1. .... 
  2. 五月 15, 2021 10:58:28 下午 org.jboss.windup.decompiler.procyon.ProcyonDecompiler$3 call 
  3. 信息: Decompiling 650 / 783 
  4. 五月 15, 2021 10:58:30 下午 org.jboss.windup.decompiler.procyon.ProcyonDecompiler$3 call 
  5. 信息: Decompiling 700 / 783 
  6. 五月 15, 2021 10:58:37 下午 org.jboss.windup.decompiler.procyon.ProcyonDecompiler$3 call 
  7. 信息: Decompiling 750 / 783 
  8. decompilationProcessComplete 
  9. Compilation results: 783 succeeded, 0 failed. 
  10. decompiler time: 40599ms 

Procyon GUI

對于 Procyon 反編譯來說,在 GitHub 上也有基于此實現(xiàn)的開源 GUI 界面,感興趣的可以下載嘗試。

Github 地址:https://github.com/deathmarine/Luyten

CFR

GitHub 地址:https://github.com/leibnitz27/cfr

CFR 官方網(wǎng)站:http://www.benf.org/other/cfr/(可能需要FQ)

Maven 倉庫:https://mvnrepository.com/artifact/org.benf/cfr

CFR(Class File Reader) 可以支持 Java 9、Java 12、Java 14 以及其他的最新版 Java 代碼的反編譯工作。而且 CFR 本身的代碼是由 Java 6 編寫,所以基本可以使用 CFR 在任何版本的 Java 程序中。值得一提的是,使用 CFR 甚至可以將使用其他語言編寫的的 JVM 類文件反編譯回 Java 文件。

CFR 命令行使用

使用 CFR 反編譯時,你可以下載已經(jīng)發(fā)布的 JAR 包,進行命令行反編譯,也可以使用 Maven 引入的方式,在代碼中使用。下面先說命令行運行的方式。

直接在 GitHub Tags 下載已發(fā)布的最新版 JAR. 可以直接運行查看幫助。

 
 
 
 
  1. # 查看幫助 
  2. java -jar cfr-0.151.jar --help 

如果只是反編譯某個 class.

 
 
 
 
  1. # 反編譯 class 文件,結(jié)果輸出到控制臺 
  2. java -jar cfr-0.151.jar WindupClasspathTypeLoader.class 
  3. # 反編譯 class 文件,結(jié)果輸出到 out 文件夾 
  4. java -jar cfr-0.151.jar WindupClasspathTypeLoader.class --outputpath ./out 

反編譯某個 JAR.

 
 
 
 
  1. # 反編譯 jar 文件,結(jié)果輸出到 output_jar 文件夾 
  2.   Desktop java -jar cfr-0.151.jar decompiler.jar --outputdir ./output_jar 
  3. Processing decompiler.jar (use silent to silence) 
  4. Processing com.strobel.assembler.metadata.ArrayTypeLoader 
  5. Processing com.strobel.assembler.metadata.ParameterDefinition 
  6. Processing com.strobel.assembler.metadata.MethodHandle 
  7. Processing com.strobel.assembler.metadata.signatures.FloatSignature 

反編譯結(jié)果會按照 class 的包路徑寫入到指定文件夾中。

CFR 代碼中使用

添加依賴這里不提。

 
 
 
 
  1.  
  2.  
  3.     org.benf 
  4.     cfr 
  5.     0.151 
  6.  

 

實際上我在官方網(wǎng)站和 GitHub 上都沒有看到具體的單元測試示例。不過沒有關(guān)系,既然能在命令行運行,那么直接在 IDEA 中查看反編譯后的 Main 方法入口,看下命令行是怎么執(zhí)行的,就可以寫出自己的單元測試了。

 
 
 
 
  1. package com.wdbyte.decompiler; 
  2.  
  3. import java.io.IOException; 
  4. import java.util.ArrayList; 
  5. import java.util.HashMap; 
  6. import java.util.List; 
  7.  
  8. import org.benf.cfr.reader.api.CfrDriver; 
  9. import org.benf.cfr.reader.util.getopt.OptionsImpl; 
  10.  
  11. /** 
  12.  * CFR Test 
  13.  * 
  14.  * @author https://github.com/niumoo 
  15.  * @date 2021/05/15 
  16.  */ 
  17. public class CFRTest { 
  18.     public static void main(String[] args) throws IOException { 
  19.         Long time = cfr("decompiler.jar", "./cfr_output_jar"); 
  20.         System.out.println(String.format("decompiler time: %dms", time)); 
  21.         // decompiler time: 11655ms 
  22.     } 
  23.     public static Long cfr(String source, String targetPath) throws IOException { 
  24.         Long start = System.currentTimeMillis(); 
  25.         // source jar 
  26.         List files = new ArrayList<>(); 
  27.         files.add(source); 
  28.         // target dir 
  29.         HashMap outputMap = new HashMap<>(); 
  30.         outputMap.put("outputdir", targetPath); 
  31.  
  32.         OptionsImpl options = new OptionsImpl(outputMap); 
  33.         CfrDriver cfrDriver = new CfrDriver.Builder().withBuiltOptions(options).build(); 
  34.         cfrDriver.analyse(files); 
  35.         Long end = System.currentTimeMillis(); 
  36.         return (end - start); 
  37.     } 

JD-Core

GiHub 地址:https://github.com/java-decompiler/jd-core

JD-core 官方網(wǎng)址:https://java-decompiler.github.io/

JD-core 是一個的獨立的 Java 庫,可以用于 Java 的反編譯,支持從 Java 1 至 Java 12 的字節(jié)碼反編譯,包括 Lambda 表達式、方式引用、默認方法等。知名的 JD-GUI 和 Eclipse 無縫集成反編譯引擎就是 JD-core。JD-core 提供了一些反編譯的核心功能,也提供了單獨的 Class 反編譯方法,但是如果你想在自己的代碼中去直接反編譯整個 JAR 包,還是需要一些改造的,如果是代碼中有匿名函數(shù),Lambda 等,雖然可以直接反編譯,不過也需要額外考慮。

使用 JD-core

 
 
 
 
  1.  
  2.          
  3.             org.jd 
  4.             jd-core 
  5.             1.1.3 
  6.          

 

為了可以反編譯整個 JAR 包,使用的代碼我做了一些簡單改造,以便于最后一部分的對比測試,但是這個示例中沒有考慮內(nèi)部類,Lambda 等會編譯出多個 Class 文件的情況,所以不能直接使用在生產(chǎn)中。

 
 
 
 
  1. package com.wdbyte.decompiler; 
  2.  
  3. import java.io.File; 
  4. import java.io.IOException; 
  5. import java.io.InputStream; 
  6. import java.nio.file.Files; 
  7. import java.nio.file.Path; 
  8. import java.nio.file.Paths; 
  9. import java.util.Enumeration; 
  10. import java.util.HashMap; 
  11. import java.util.jar.JarFile; 
  12. import java.util.zip.ZipEntry; 
  13. import java.util.zip.ZipFile; 
  14.  
  15. import org.apache.commons.io.IOUtils; 
  16. import org.apache.commons.lang3.StringUtils; 
  17. import org.jd.core.v1.ClassFileToJavaSourceDecompiler; 
  18. import org.jd.core.v1.api.loader.Loader; 
  19. import org.jd.core.v1.api.printer.Printer; 
  20.  
  21. /** 
  22.  * @author https://github.com/niumoo 
  23.  * @date 2021/05/15 
  24.  */ 
  25. public class JDCoreTest { 
  26.  
  27.     public static void main(String[] args) throws Exception { 
  28.         JDCoreDecompiler jdCoreDecompiler = new JDCoreDecompiler(); 
  29.         Long time = jdCoreDecompiler.decompiler("decompiler.jar","jd_output_jar"); 
  30.         System.out.println(String.format("decompiler time: %dms", time)); 
  31.     } 
  32.  
  33.  
  34. class JDCoreDecompiler{ 
  35.  
  36.     private ClassFileToJavaSourceDecompiler decompiler = new ClassFileToJavaSourceDecompiler(); 
  37.     // 存放字節(jié)碼 
  38.     private HashMap classByteMap = new HashMap<>(); 
  39.  
  40.     /** 
  41.      * 注意:沒有考慮一個 Java 類編譯出多個 Class 文件的情況。 
  42.      *  
  43.      * @param source 
  44.      * @param target 
  45.      * @return 
  46.      * @throws Exception 
  47.      */ 
  48.     public Long decompiler(String source,String target) throws Exception { 
  49.         long start = System.currentTimeMillis(); 
  50.         // 解壓 
  51.         archive(source); 
  52.         for (String className : classByteMap.keySet()) { 
  53.             String path = StringUtils.substringBeforeLast(className, "/"); 
  54.             String name = StringUtils.substringAfterLast(className, "/"); 
  55.             if (StringUtils.contains(name, "$")) { 
  56.                 name = StringUtils.substringAfterLast(name, "$"); 
  57.             } 
  58.             name = StringUtils.replace(name, ".class", ".java"); 
  59.             decompiler.decompile(loader, printer, className); 
  60.             String context = printer.toString(); 
  61.             Path targetPath = Paths.get(target + "/" + path + "/" + name); 
  62.             if (!Files.exists(Paths.get(target + "/" + path))) { 
  63.                 Files.createDirectories(Paths.get(target + "/" + path)); 
  64.             } 
  65.             Files.deleteIfExists(targetPath); 
  66.             Files.createFile(targetPath); 
  67.             Files.write(targetPath, context.getBytes()); 
  68.         } 
  69.         return System.currentTimeMillis() - start; 
  70.     } 
  71.     private void archive(String path) throws IOException { 
  72.         try (ZipFile archive = new JarFile(new File(path))) { 
  73.             Enumeration entries = archive.entries(); 
  74.             while (entries.hasMoreElements()) { 
  75.                 ZipEntry entry = entries.nextElement(); 
  76.                 if (!entry.isDirectory()) { 
  77.                     String name = entry.getName(); 
  78.                     if (name.endsWith(".class")) { 
  79.                         byte[] bytes = null; 
  80.                         try (InputStream stream = archive.getInputStream(entry)) { 
  81.                             bytes = IOUtils.toByteArray(stream); 
  82.                         } 
  83.                         classByteMap.put(name, bytes); 
  84.                     } 
  85.                 } 
  86.             } 
  87.         } 
  88.     } 
  89.  
  90.     private Loader loader = new Loader() { 
  91.         @Override 
  92.         public byte[] load(String internalName) { 
  93.             return classByteMap.get(internalName); 
  94.         } 
  95.         @Override 
  96.         public boolean canLoad(String internalName) { 
  97.             return classByteMap.containsKey(internalName); 
  98.         } 
  99.     }; 
  100.  
  101.     private Printer printer = new Printer() { 
  102.         protected static final String TAB = "  "; 
  103.         protected static final String NEWLINE = "\n"; 
  104.         protected int indentationCount = 0; 
  105.         protected StringBuilder sb = new StringBuilder(); 
  106.         @Override public String toString() { 
  107.             String toString = sb.toString(); 
  108.             sb = new StringBuilder(); 
  109.             return toString; 
  110.         } 
  111.         @Override public void start(int maxLineNumber, int majorVersion, int minorVersion) {} 
  112.         @Override public void end() {} 
  113.         @Override public void printText(String text) { sb.append(text); } 
  114.         @Override public void printNumericConstant(String constant) { sb.append(constant); } 
  115.         @Override public void printStringConstant(String constant, String ownerInternalName) { sb.append(constant); } 
  116.         @Override public void printKeyword(String keyword) { sb.append(keyword); } 
  117.         @Override public void printDeclaration(int type, String internalTypeName, String name, String descriptor) { sb.append(name); } 
  118.         @Override public void printReference(int type, String internalTypeName, String name, String descriptor, String ownerInternalName) { sb.append(name); } 
  119.         @Override public void indent() { this.indentationCount++; } 
  120.         @Override public void unindent() { this.indentationCount--; } 
  121.         @Override public void startLine(int lineNumber) { for (int i=0; i
  122.         @Override public void endLine() { sb.append(NEWLINE); } 
  123.         @Override public void extraLine(int count) { while (count-- > 0) sb.append(NEWLINE); } 
  124.         @Override public void startMarker(int type) {} 
  125.         @Override public void endMarker(int type) {} 
  126.     }; 

JD-GUI

GitHub 地址:https://github.com/java-decompiler/jd-gui

JD-core 也提供了官方的 GUI 界面,需要的也可以直接下載嘗試。

Jadx

GitHub 地址:https://github.com/skylot/jadx

Jadx 是一款可以反編譯 JAR、APK、DEX、AAR、AAB、ZIP 文件的反編譯工具,并且也配有 Jadx-gui 用于界面操作。Jadx 使用 Grade 進行依賴管理,可以自行克隆倉庫打包運行。

 
 
 
 
  1. git clone https://github.com/skylot/jadx.git 
  2. cd jadx 
  3. ./gradlew dist 
  4. # 查看幫助 
  5.  ./build/jadx/bin/jadx --help 
  6.   
  7. jadx - dex to java decompiler, version: dev 
  8.  
  9. usage: jadx [options]  (.apk, .dex, .jar, .class, .smali, .zip, .aar, .arsc, .aab) 
  10. options: 
  11.   -d, --output-dir                    - output directory 
  12.   -ds, --output-dir-src               - output directory for sources 
  13.   -dr, --output-dir-res               - output directory for resources 
  14.   -r, --no-res                        - do not decode resources 
  15.   -s, --no-src                        - do not decompile source code 
  16.   --single-class                      - decompile a single class 
  17.   --output-format                     - can be 'java' or 'json', default: java 
  18.   -e, --export-gradle                 - save as android gradle project 
  19.   -j, --threads-count                 - processing threads count, default: 6 
  20.   --show-bad-code                     - show inconsistent code (incorrectly decompiled) 
  21.   --no-imports                        - disable use of imports, always write entire package name 
  22.   --no-debug-info                     - disable debug info 
  23.   --add-debug-lines                   - add comments with debug line numbers if available 
  24.   --no-inline-anonymous               - disable anonymous classes inline 
  25.   --no-replace-consts                 - don't replace constant value with matching constant field 
  26.   --escape-unicode                    - escape non latin characters in strings (with \u) 
  27.   --respect-bytecode-access-modifiers - don't change original access modifiers 
  28.   --deobf                             - activate deobfuscation 
  29.   --deobf-min                         - min length of name, renamed if shorter, default: 3 
  30.   --deobf-max                         - max length of name, renamed if longer, default: 64 
  31.   --deobf-cfg-file                    - deobfuscation map file, default: same dir and name as input file with '.jobf' extension 
  32.   --deobf-rewrite-cfg                 - force to save deobfuscation map 
  33.   --deobf-use-sourcename              - use source file name as class name alias 
  34.   --deobf-parse-kotlin-metadata       - parse kotlin metadata to class and package names 
  35.   --rename-flags                      - what to rename, comma-separated, 'case' for system case sensitivity, 'valid' for java identifiers, 'printable' characters, 'none' or 'all' (default) 
  36.   --fs-case-sensitive                 - treat filesystem as case sensitive, false by default 
  37.   --cfg                               - save methods control flow graph to dot file 
  38.   --raw-cfg                           - save methods control flow graph (use raw instructions) 
  39.   -f, --fallback                      - make simple dump (using goto instead of 'if', 'for', etc) 
  40.   -v, --verbose                       - verbose output (set --log-level to DEBUG) 
  41.   -q, --quiet                         - turn off output (set --log-level to QUIET) 
  42.   --log-level                         - set log level, values: QUIET, PROGRESS, ERROR, WARN, INFO, DEBUG, default: PROGRESS 
  43.   --version                           - print jadx version 
  44.   -h, --help                          - print this help 
  45. Example: 
  46.   jadx -d out classes.dex 

根據(jù) HELP 信息,如果想要反編譯 decompiler.jar 到 out 文件夾。

 
 
 
 
  1. ./build/jadx/bin/jadx -d ./out ~/Desktop/decompiler.jar  
  2. INFO  - loading ... 
  3. INFO  - processing ... 
  4. INFO  - doneress: 1143 of 1217 (93%) 

Fernflower

GitHub 地址:https://github.com/fesh0r/fernflower

Fernflower 和 Jadx 一樣使用 Grade 進行依賴管理,可以自行克隆倉庫打包運行。

 
 
 
 
  1.   fernflower-master ./gradlew build 
  2.  
  3. BUILD SUCCESSFUL in 32s 
  4. 4 actionable tasks: 4 executed 
  5.  
  6.   fernflower-master java -jar build/libs/fernflower.jar 
  7. Usage: java -jar fernflower.jar [-
  8. Example: java -jar fernflower.jar -dgs=true c:\my\source\ c:\my.jar d:\decompiled\ 
  9.  
  10.   fernflower-master mkdir out 
  11.   fernflower-master java -jar build/libs/fernflower.jar ~/Desktop/decompiler.jar ./out 
  12. INFO:  Decompiling class com/strobel/assembler/metadata/ArrayTypeLoader 
  13. INFO:  ... done 
  14. INFO:  Decompiling class com/strobel/assembler/metadata/ParameterDefinition 
  15. INFO:  ... done 
  16. INFO:  Decompiling class com/strobel/assembler/metadata/MethodHandle 
  17. ... 
  18.  
  19.   fernflower-master ll out 
  20. total 1288 
  21. -rw-r--r--  1 darcy  staff   595K  5 16 17:47 decompiler.jar 
  22.   fernflower-master 

Fernflower 在反編譯 JAR 包時,默認反編譯的結(jié)果也是一個 JAR 包。Jad

反編譯速度

到這里已經(jīng)介紹了五款 Java 反編譯工具了,那么在日常開發(fā)中我們應該使用哪一個呢?又或者在代碼分析時我們又該選擇哪一個呢?我想這兩種情況的不同,使用時的關(guān)注點也是不同的。如果是日常使用,讀讀代碼,我想應該是對可讀性要求更高些,如果是大量的代碼分析工作,那么可能反編譯的速度和語法的支持上要求更高些。為了能有一個簡單的參考數(shù)據(jù),我使用 JMH 微基準測試工具分別對這五款反編譯工具進行了簡單的測試,下面是一些測試結(jié)果。

測試環(huán)境

環(huán)境變量 描述
處理器 2.6 GHz 六核Intel Core i7
內(nèi)存 16 GB 2667 MHz DDR4
Java 版本 JDK 14.0.2
測試方式 JMH 基準測試。
待反編譯 JAR 1 procyon-compilertools-0.5.33.jar (1.5 MB)
待反編譯 JAR 2 python2java4common-1.0.0-20180706.084921-1.jar (42 MB)

反編譯 JAR 1:procyon-compilertools-0.5.33.jar (1.5 MB)

Benchmark Mode Cnt Score Units
cfr avgt 10 6548.642 ±  363.502 ms/op
fernflower avgt 10 12699.147 ± 1081.539 ms/op
jdcore avgt 10 5728.621 ±  310.645 ms/op
procyon avgt 10 26776.125 ± 2651.081 ms/op
jadx avgt 10 7059.354 ±  323.351 ms/op

JAR 2 這個包是比較大的,是拿很多代碼倉庫合并到一起的,同時還有很多 Python 轉(zhuǎn) Java 生成的代碼,理論上代碼的復雜度會更高。

Benchmark Cnt Score
Cfr 1 413838.826ms
fernflower 1 246819.168ms
jdcore 1 Error
procyon 1 487647.181ms
jadx 1 505600.231ms

語法支持和可讀性

如果反編譯后的代碼需要自己看的話,那么可讀性更好的代碼更占優(yōu)勢,下面我寫了一些代碼,主要是 Java 8 及以下的代碼語法和一些嵌套的流程控制,看看反編譯后的效果如何。

 
 
 
 
  1. package com.wdbyte.decompiler; 
  2.  
  3. import java.util.ArrayList; 
  4. import java.util.List; 
  5. import java.util.stream.IntStream; 
  6.  
  7. import org.benf.cfr.reader.util.functors.UnaryFunction; 
  8.  
  9. /** 
  10.  * @author https://www.wdbyte.com 
  11.  * @date 2021/05/16 
  12.  */ 
  13. public class HardCode  { 
  14.     public HardCode(A a, B b) { } 
  15.  
  16.     public static void test(int... args) { } 
  17.  
  18.     public 網(wǎng)站標題:Java反編譯工具的使用與對比分析
    分享鏈接:http://www.5511xx.com/article/cdcgoee.html