core: update dx to version 14, allow to decompile java 8 classes (new instructions not implemented yet)
This commit is contained in:
@@ -20,6 +20,7 @@ idea/
|
||||
.gradle/
|
||||
gradle.properties
|
||||
|
||||
jadx-output/
|
||||
*-tmp/
|
||||
|
||||
*.dex
|
||||
|
||||
@@ -3,7 +3,7 @@ ext.jadxClasspath = 'clsp-data/android-5.1.jar'
|
||||
dependencies {
|
||||
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 'org.ow2.asm:asm:5.0.3'
|
||||
compile 'com.intellij:annotations:12.0'
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -565,7 +565,7 @@ public class InsnDecoder {
|
||||
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) {
|
||||
|
||||
@@ -113,7 +113,7 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode {
|
||||
load();
|
||||
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 {
|
||||
}
|
||||
|
||||
private static Dex loadFromJar(File jarFile) throws DecodeException {
|
||||
JavaToDex j2d = new JavaToDex();
|
||||
try {
|
||||
LOG.info("converting to dex: {} ...", jarFile.getName());
|
||||
JavaToDex j2d = new JavaToDex();
|
||||
byte[] ba = j2d.convert(jarFile.getAbsolutePath());
|
||||
if (ba.length == 0) {
|
||||
throw new JadxException(j2d.isError() ? j2d.getDxErrors() : "Empty dx output");
|
||||
}
|
||||
if (j2d.isError()) {
|
||||
LOG.warn("dx message: {}", j2d.getDxErrors());
|
||||
throw new JadxException("Empty dx output");
|
||||
}
|
||||
return new Dex(ba);
|
||||
} catch (Throwable e) {
|
||||
throw new DecodeException("java class to dex conversion error:\n " + e.getMessage(), e);
|
||||
} finally {
|
||||
if (j2d.isError()) {
|
||||
LOG.warn("dx message: {}", j2d.getDxErrors());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package jadx.core.utils.files;
|
||||
|
||||
import jadx.core.utils.exceptions.JadxException;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import com.android.dx.command.dexer.DxContext;
|
||||
import com.android.dx.command.dexer.Main;
|
||||
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 {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JavaToDex.class);
|
||||
private static final String CHARSET_NAME = "UTF-8";
|
||||
|
||||
public static class DxArgs extends Arguments {
|
||||
public DxArgs(String dexFile, String[] input) {
|
||||
public DxArgs(DxContext context, String dexFile, String[] input) {
|
||||
super(context);
|
||||
outName = dexFile;
|
||||
fileNames = input;
|
||||
jarOutput = false;
|
||||
@@ -25,28 +27,26 @@ public class JavaToDex {
|
||||
coreLibrary = true;
|
||||
|
||||
debug = true;
|
||||
warnings = true;
|
||||
minSdkVersion = 28;
|
||||
}
|
||||
}
|
||||
|
||||
private String dxErrors;
|
||||
|
||||
public byte[] convert(String javaFile) throws JadxException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream errOut = new ByteArrayOutputStream();
|
||||
try {
|
||||
try (ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream errOut = new ByteArrayOutputStream()) {
|
||||
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);
|
||||
dxErrors = errOut.toString(CHARSET_NAME);
|
||||
if (result != 0) {
|
||||
throw new JadxException("Java to dex conversion error, code: " + result);
|
||||
}
|
||||
dxErrors = errOut.toString(CHARSET_NAME);
|
||||
return out.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new JadxException("dx exception: " + e.getMessage(), e);
|
||||
} finally {
|
||||
close(out);
|
||||
close(errOut);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user