From c5240e718e148f491a165342038ad7238ac73897 Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Tue, 9 Apr 2024 11:59:14 +0200 Subject: [PATCH] Use computeFrames option in dex2jar This yields more accurate outputs and circumvents bugs --- .../club/bytecodeviewer/util/Dex2Jar.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/Dex2Jar.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/Dex2Jar.java index 7632b088..a6f6b9ff 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/Dex2Jar.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/Dex2Jar.java @@ -1,11 +1,13 @@ package the.bytecode.club.bytecodeviewer.util; +import com.googlecode.d2j.DexException; +import com.googlecode.d2j.Method; import com.googlecode.d2j.dex.Dex2jar; import com.googlecode.d2j.dex.DexExceptionHandler; -import com.googlecode.d2j.Method; import com.googlecode.d2j.node.DexMethodNode; -import org.objectweb.asm.MethodVisitor; +import com.googlecode.dex2jar.tools.Jar2Dex; import java.io.File; +import org.objectweb.asm.MethodVisitor; import the.bytecode.club.bytecodeviewer.BytecodeViewer; /*************************************************************************** @@ -43,17 +45,19 @@ public class Dex2Jar { public static synchronized void dex2Jar(File input, File output) { try { Dex2jar d2Jar = Dex2jar.from(input) - .withExceptionHandler(new DexExceptionHandler() { - public void handleFileException(Exception e) { - e.printStackTrace(); - } - - public void handleMethodTranslateException(Method method, DexMethodNode methodNode, MethodVisitor mv, Exception e) { - e.printStackTrace(); - } - }); + .computeFrames(true) + .withExceptionHandler(new DexExceptionHandler() { + public void handleFileException(Exception e) { + e.printStackTrace(); + } + + public void handleMethodTranslateException(Method method, DexMethodNode methodNode, + MethodVisitor mv, Exception e) { + e.printStackTrace(); + } + }); d2Jar.to(output.toPath()); - } catch (com.googlecode.d2j.DexException e) { + } catch (DexException e) { e.printStackTrace(); } catch (Exception e) { BytecodeViewer.handleException(e); @@ -72,7 +76,8 @@ public class Dex2Jar { public static synchronized void saveAsDex(File input, File output, boolean delete) { try { - com.googlecode.dex2jar.tools.Jar2Dex.main(input.getAbsolutePath(), + Jar2Dex.main(input.getAbsolutePath(), + "-f", "-o", output.getAbsolutePath(), "-s", BytecodeViewer.viewer.getMinSdkVersion() + ""); if (delete) @@ -81,4 +86,5 @@ public class Dex2Jar { BytecodeViewer.handleException(e); } } + }