提交 c4a462d6 编写于 作者: S Skylot

core: update dx to version 14, allow to decompile java 8 classes (new...

core: update dx to version 14, allow to decompile java 8 classes (new instructions not implemented yet)
上级 7fe46fb6
...@@ -20,6 +20,7 @@ idea/ ...@@ -20,6 +20,7 @@ idea/
.gradle/ .gradle/
gradle.properties gradle.properties
jadx-output/
*-tmp/ *-tmp/
*.dex *.dex
......
...@@ -3,7 +3,7 @@ ext.jadxClasspath = 'clsp-data/android-5.1.jar' ...@@ -3,7 +3,7 @@ ext.jadxClasspath = 'clsp-data/android-5.1.jar'
dependencies { dependencies {
runtime files(jadxClasspath) runtime files(jadxClasspath)
compile files('lib/dx-1.13.jar') compile files('lib/dx-1.14.jar')
compile 'commons-io:commons-io:2.6' compile 'commons-io:commons-io:2.6'
compile 'org.ow2.asm:asm:5.0.3' compile 'org.ow2.asm:asm:5.0.3'
compile 'com.intellij:annotations:12.0' compile 'com.intellij:annotations:12.0'
......
...@@ -565,7 +565,7 @@ public class InsnDecoder { ...@@ -565,7 +565,7 @@ public class InsnDecoder {
InsnArg.reg(insn, 0, ArgType.UNKNOWN_OBJECT)); InsnArg.reg(insn, 0, ArgType.UNKNOWN_OBJECT));
} }
throw new DecodeException("Unknown instruction: " + OpcodeInfo.getName(insn.getOpcode())); throw new DecodeException("Unknown instruction: '" + OpcodeInfo.getName(insn.getOpcode()) + "'");
} }
private InsnNode decodeSwitch(DecodedInstruction insn, int offset, boolean packed) { private InsnNode decodeSwitch(DecodedInstruction insn, int offset, boolean packed) {
......
...@@ -113,7 +113,7 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode { ...@@ -113,7 +113,7 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode {
load(); load();
noCode = false; noCode = false;
} }
throw new DecodeException(this, "Load method exception", e); throw new DecodeException(this, "Load method exception: " + e.getMessage(), e);
} }
} }
......
...@@ -146,19 +146,20 @@ public class InputFile { ...@@ -146,19 +146,20 @@ public class InputFile {
} }
private static Dex loadFromJar(File jarFile) throws DecodeException { private static Dex loadFromJar(File jarFile) throws DecodeException {
JavaToDex j2d = new JavaToDex();
try { try {
LOG.info("converting to dex: {} ...", jarFile.getName()); LOG.info("converting to dex: {} ...", jarFile.getName());
JavaToDex j2d = new JavaToDex();
byte[] ba = j2d.convert(jarFile.getAbsolutePath()); byte[] ba = j2d.convert(jarFile.getAbsolutePath());
if (ba.length == 0) { if (ba.length == 0) {
throw new JadxException(j2d.isError() ? j2d.getDxErrors() : "Empty dx output"); throw new JadxException("Empty dx output");
}
if (j2d.isError()) {
LOG.warn("dx message: {}", j2d.getDxErrors());
} }
return new Dex(ba); return new Dex(ba);
} catch (Throwable e) { } catch (Throwable e) {
throw new DecodeException("java class to dex conversion error:\n " + e.getMessage(), e); throw new DecodeException("java class to dex conversion error:\n " + e.getMessage(), e);
} finally {
if (j2d.isError()) {
LOG.warn("dx message: {}", j2d.getDxErrors());
}
} }
} }
......
package jadx.core.utils.files; package jadx.core.utils.files;
import jadx.core.utils.exceptions.JadxException;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import com.android.dx.command.dexer.DxContext; import com.android.dx.command.dexer.DxContext;
import com.android.dx.command.dexer.Main; import com.android.dx.command.dexer.Main;
import com.android.dx.command.dexer.Main.Arguments; import com.android.dx.command.dexer.Main.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static jadx.core.utils.files.FileUtils.close; import jadx.core.utils.exceptions.JadxException;
public class JavaToDex { public class JavaToDex {
private static final Logger LOG = LoggerFactory.getLogger(JavaToDex.class);
private static final String CHARSET_NAME = "UTF-8"; private static final String CHARSET_NAME = "UTF-8";
public static class DxArgs extends Arguments { public static class DxArgs extends Arguments {
public DxArgs(String dexFile, String[] input) { public DxArgs(DxContext context, String dexFile, String[] input) {
super(context);
outName = dexFile; outName = dexFile;
fileNames = input; fileNames = input;
jarOutput = false; jarOutput = false;
...@@ -25,28 +27,26 @@ public class JavaToDex { ...@@ -25,28 +27,26 @@ public class JavaToDex {
coreLibrary = true; coreLibrary = true;
debug = true; debug = true;
warnings = true;
minSdkVersion = 28;
} }
} }
private String dxErrors; private String dxErrors;
public byte[] convert(String javaFile) throws JadxException { public byte[] convert(String javaFile) throws JadxException {
ByteArrayOutputStream out = new ByteArrayOutputStream(); try (ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream errOut = new ByteArrayOutputStream(); ByteArrayOutputStream errOut = new ByteArrayOutputStream()) {
try {
DxContext context = new DxContext(out, errOut); DxContext context = new DxContext(out, errOut);
DxArgs args = new DxArgs("-", new String[]{javaFile}); DxArgs args = new DxArgs(context, "-", new String[]{javaFile});
int result = (new Main(context)).runDx(args); int result = (new Main(context)).runDx(args);
dxErrors = errOut.toString(CHARSET_NAME);
if (result != 0) { if (result != 0) {
throw new JadxException("Java to dex conversion error, code: " + result); throw new JadxException("Java to dex conversion error, code: " + result);
} }
dxErrors = errOut.toString(CHARSET_NAME);
return out.toByteArray(); return out.toByteArray();
} catch (Exception e) { } catch (Exception e) {
throw new JadxException("dx exception: " + e.getMessage(), e); throw new JadxException("dx exception: " + e.getMessage(), e);
} finally {
close(out);
close(errOut);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册