Commit 14f6d2f3 authored by Bjoern Kerler's avatar Bjoern Kerler

Add support for dx 1.8 library

parent 4e4b4975
ext.jadxClasspath = 'clsp-data/android-4.3.jar' ext.jadxClasspath = 'clsp-data/android-4.3.jar'
dependencies { dependencies {
compile 'com.google.android.tools:dx:1.7' compile files('lib/dx-1.8.jar')
runtime files(jadxClasspath) runtime files(jadxClasspath)
} }
...@@ -3,7 +3,7 @@ package jadx.core.dex.info; ...@@ -3,7 +3,7 @@ package jadx.core.dex.info;
import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.nodes.DexNode; import jadx.core.dex.nodes.DexNode;
import com.android.dx.io.FieldId; import com.android.dex.FieldId;
public class FieldInfo { public class FieldInfo {
......
...@@ -7,8 +7,8 @@ import jadx.core.utils.Utils; ...@@ -7,8 +7,8 @@ import jadx.core.utils.Utils;
import java.util.List; import java.util.List;
import com.android.dx.io.MethodId; import com.android.dex.MethodId;
import com.android.dx.io.ProtoId; import com.android.dex.ProtoId;
public final class MethodInfo { public final class MethodInfo {
......
...@@ -14,7 +14,7 @@ import jadx.core.utils.exceptions.DecodeException; ...@@ -14,7 +14,7 @@ import jadx.core.utils.exceptions.DecodeException;
import java.io.EOFException; import java.io.EOFException;
import com.android.dx.io.Code; import com.android.dex.Code;
import com.android.dx.io.OpcodeInfo; import com.android.dx.io.OpcodeInfo;
import com.android.dx.io.Opcodes; import com.android.dx.io.Opcodes;
import com.android.dx.io.instructions.DecodedInstruction; import com.android.dx.io.instructions.DecodedInstruction;
......
...@@ -31,10 +31,10 @@ import java.util.Map; ...@@ -31,10 +31,10 @@ import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.android.dx.io.ClassData; import com.android.dex.ClassData;
import com.android.dx.io.ClassData.Field; import com.android.dex.ClassData.Field;
import com.android.dx.io.ClassData.Method; import com.android.dex.ClassData.Method;
import com.android.dx.io.ClassDef; import com.android.dex.ClassDef;
public class ClassNode extends LineAttrNode implements ILoadable { public class ClassNode extends LineAttrNode implements ILoadable {
private static final Logger LOG = LoggerFactory.getLogger(ClassNode.class); private static final Logger LOG = LoggerFactory.getLogger(ClassNode.class);
......
...@@ -13,23 +13,23 @@ import java.util.HashMap; ...@@ -13,23 +13,23 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.android.dx.io.ClassData; import com.android.dex.ClassData;
import com.android.dx.io.ClassData.Method; import com.android.dex.ClassData.Method;
import com.android.dx.io.ClassDef; import com.android.dex.ClassDef;
import com.android.dx.io.Code; import com.android.dex.Code;
import com.android.dx.io.DexBuffer; import com.android.dex.Dex;
import com.android.dx.io.DexBuffer.Section; import com.android.dex.FieldId;
import com.android.dx.io.FieldId; import com.android.dex.MethodId;
import com.android.dx.io.MethodId; import com.android.dex.ProtoId;
import com.android.dx.io.ProtoId; import com.android.dex.TypeList;
import com.android.dx.merge.TypeList; import com.android.dex.TableOfContents;
public class DexNode { public class DexNode {
public static final int NO_INDEX = -1; public static final int NO_INDEX = -1;
private final RootNode root; private final RootNode root;
private final DexBuffer dexBuf; private final Dex dexBuf;
private final List<ClassNode> classes = new ArrayList<ClassNode>(); private final List<ClassNode> classes = new ArrayList<ClassNode>();
private final String[] strings; private final String[] strings;
...@@ -116,7 +116,7 @@ public class DexNode { ...@@ -116,7 +116,7 @@ public class DexNode {
return dexBuf.readCode(mth); return dexBuf.readCode(mth);
} }
public Section openSection(int offset) { public Dex.Section openSection(int offset) {
return dexBuf.open(offset); return dexBuf.open(offset);
} }
......
...@@ -6,7 +6,7 @@ import jadx.core.dex.info.AccessInfo.AFType; ...@@ -6,7 +6,7 @@ import jadx.core.dex.info.AccessInfo.AFType;
import jadx.core.dex.info.FieldInfo; import jadx.core.dex.info.FieldInfo;
import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.instructions.args.ArgType;
import com.android.dx.io.ClassData.Field; import com.android.dex.ClassData.Field;
public class FieldNode extends LineAttrNode { public class FieldNode extends LineAttrNode {
......
...@@ -35,10 +35,10 @@ import java.util.Set; ...@@ -35,10 +35,10 @@ import java.util.Set;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.android.dx.io.ClassData.Method; import com.android.dex.ClassData.Method;
import com.android.dx.io.Code; import com.android.dex.Code;
import com.android.dx.io.Code.CatchHandler; import com.android.dex.Code.CatchHandler;
import com.android.dx.io.Code.Try; import com.android.dex.Code.Try;
public class MethodNode extends LineAttrNode implements ILoadable { public class MethodNode extends LineAttrNode implements ILoadable {
private static final Logger LOG = LoggerFactory.getLogger(MethodNode.class); private static final Logger LOG = LoggerFactory.getLogger(MethodNode.class);
...@@ -248,7 +248,7 @@ public class MethodNode extends LineAttrNode implements ILoadable { ...@@ -248,7 +248,7 @@ public class MethodNode extends LineAttrNode implements ILoadable {
// but in maven repository still old version // but in maven repository still old version
Set<Integer> handlerSet = new HashSet<Integer>(tries.length); Set<Integer> handlerSet = new HashSet<Integer>(tries.length);
for (Try aTry : tries) { for (Try aTry : tries) {
handlerSet.add(aTry.getHandlerOffset()); handlerSet.add(aTry.getCatchHandlerIndex());
} }
List<Integer> handlerList = new ArrayList<Integer>(catchBlocks.length); List<Integer> handlerList = new ArrayList<Integer>(catchBlocks.length);
handlerList.addAll(handlerSet); handlerList.addAll(handlerSet);
...@@ -306,7 +306,7 @@ public class MethodNode extends LineAttrNode implements ILoadable { ...@@ -306,7 +306,7 @@ public class MethodNode extends LineAttrNode implements ILoadable {
// attach TRY_ENTER, TRY_LEAVE attributes to instructions // attach TRY_ENTER, TRY_LEAVE attributes to instructions
for (Try aTry : tries) { for (Try aTry : tries) {
int catchNum = handlerList.indexOf(aTry.getHandlerOffset()); int catchNum = handlerList.indexOf(aTry.getCatchHandlerIndex());
TryCatchBlock block = catches.get(catchNum); TryCatchBlock block = catches.get(catchNum);
int offset = aTry.getStartAddress(); int offset = aTry.getStartAddress();
int end = offset + aTry.getInstructionCount() - 1; int end = offset + aTry.getInstructionCount() - 1;
......
...@@ -16,7 +16,7 @@ import java.util.LinkedHashMap; ...@@ -16,7 +16,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.android.dx.io.DexBuffer.Section; import com.android.dex.Dex;
public class AnnotationsParser { public class AnnotationsParser {
...@@ -35,7 +35,7 @@ public class AnnotationsParser { ...@@ -35,7 +35,7 @@ public class AnnotationsParser {
} }
public void parse(int offset) throws DecodeException { public void parse(int offset) throws DecodeException {
Section section = dex.openSection(offset); Dex.Section section = dex.openSection(offset);
// TODO read as unsigned int // TODO read as unsigned int
int classAnnotationsOffset = section.readInt(); int classAnnotationsOffset = section.readInt();
...@@ -60,7 +60,7 @@ public class AnnotationsParser { ...@@ -60,7 +60,7 @@ public class AnnotationsParser {
for (int i = 0; i < annotatedParametersCount; i++) { for (int i = 0; i < annotatedParametersCount; i++) {
MethodNode mth = cls.searchMethodById(section.readInt()); MethodNode mth = cls.searchMethodById(section.readInt());
// read annotation ref list // read annotation ref list
Section ss = dex.openSection(section.readInt()); Dex.Section ss = dex.openSection(section.readInt());
int size = ss.readInt(); int size = ss.readInt();
MethodParameters params = new MethodParameters(size); MethodParameters params = new MethodParameters(size);
for (int j = 0; j < size; j++) { for (int j = 0; j < size; j++) {
...@@ -71,18 +71,18 @@ public class AnnotationsParser { ...@@ -71,18 +71,18 @@ public class AnnotationsParser {
} }
private AnnotationsList readAnnotationSet(int offset) throws DecodeException { private AnnotationsList readAnnotationSet(int offset) throws DecodeException {
Section section = dex.openSection(offset); Dex.Section section = dex.openSection(offset);
int size = section.readInt(); int size = section.readInt();
List<Annotation> list = new ArrayList<Annotation>(size); List<Annotation> list = new ArrayList<Annotation>(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Section anSection = dex.openSection(section.readInt()); Dex.Section anSection = dex.openSection(section.readInt());
Annotation a = readAnnotation(dex, anSection, true); Annotation a = readAnnotation(dex, anSection, true);
list.add(a); list.add(a);
} }
return new AnnotationsList(list); return new AnnotationsList(list);
} }
public static Annotation readAnnotation(DexNode dex, Section s, boolean readVisibility) throws DecodeException { public static Annotation readAnnotation(DexNode dex, Dex.Section s, boolean readVisibility) throws DecodeException {
EncValueParser parser = new EncValueParser(dex, s); EncValueParser parser = new EncValueParser(dex, s);
Visibility visibility = null; Visibility visibility = null;
if (readVisibility) { if (readVisibility) {
......
...@@ -10,7 +10,7 @@ import jadx.core.utils.exceptions.DecodeException; ...@@ -10,7 +10,7 @@ import jadx.core.utils.exceptions.DecodeException;
import java.util.List; import java.util.List;
import com.android.dx.io.DexBuffer.Section; import com.android.dex.Dex;
public class DebugInfoParser { public class DebugInfoParser {
...@@ -33,7 +33,7 @@ public class DebugInfoParser { ...@@ -33,7 +33,7 @@ public class DebugInfoParser {
private static final int DBG_LINE_RANGE = 15; private static final int DBG_LINE_RANGE = 15;
private final MethodNode mth; private final MethodNode mth;
private final Section section; private final Dex.Section section;
private final DexNode dex; private final DexNode dex;
private final LocalVar[] locals; private final LocalVar[] locals;
......
...@@ -8,16 +8,38 @@ import jadx.core.utils.exceptions.DecodeException; ...@@ -8,16 +8,38 @@ import jadx.core.utils.exceptions.DecodeException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.android.dx.io.DexBuffer.Section; import com.android.dex.Dex;
import com.android.dx.io.EncodedValueReader; import com.android.dex.EncodedValue;
import com.android.dx.util.Leb128Utils; import com.android.dex.EncodedValueReader;
import com.android.dex.Leb128;
public class EncValueParser extends EncodedValueReader { import com.android.dex.util.ByteInput;
public class EncValueParser {
public static final int ENCODED_BYTE = 0x00;
public static final int ENCODED_SHORT = 0x02;
public static final int ENCODED_CHAR = 0x03;
public static final int ENCODED_INT = 0x04;
public static final int ENCODED_LONG = 0x06;
public static final int ENCODED_FLOAT = 0x10;
public static final int ENCODED_DOUBLE = 0x11;
public static final int ENCODED_STRING = 0x17;
public static final int ENCODED_TYPE = 0x18;
public static final int ENCODED_FIELD = 0x19;
public static final int ENCODED_ENUM = 0x1b;
public static final int ENCODED_METHOD = 0x1a;
public static final int ENCODED_ARRAY = 0x1c;
public static final int ENCODED_ANNOTATION = 0x1d;
public static final int ENCODED_NULL = 0x1e;
public static final int ENCODED_BOOLEAN = 0x1f;
protected final Dex.Section in;
private final DexNode dex; private final DexNode dex;
public EncValueParser(DexNode dex, Section in) { public EncValueParser(DexNode dex, Dex.Section in) {
super(in); //super(in);
this.in = in;
this.dex = dex; this.dex = dex;
} }
...@@ -64,7 +86,7 @@ public class EncValueParser extends EncodedValueReader { ...@@ -64,7 +86,7 @@ public class EncValueParser extends EncodedValueReader {
return FieldInfo.fromDex(dex, parseUnsignedInt(size)); return FieldInfo.fromDex(dex, parseUnsignedInt(size));
case ENCODED_ARRAY: case ENCODED_ARRAY:
int count = Leb128Utils.readUnsignedLeb128(in); int count = Leb128.readUnsignedLeb128(in);
List<Object> values = new ArrayList<Object>(count); List<Object> values = new ArrayList<Object>(count);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
values.add(parseValue()); values.add(parseValue());
...@@ -72,7 +94,7 @@ public class EncValueParser extends EncodedValueReader { ...@@ -72,7 +94,7 @@ public class EncValueParser extends EncodedValueReader {
return values; return values;
case ENCODED_ANNOTATION: case ENCODED_ANNOTATION:
return AnnotationsParser.readAnnotation(dex, (Section) in, false); return AnnotationsParser.readAnnotation(dex, (Dex.Section) in, false);
} }
throw new DecodeException("Unknown encoded value type: 0x" + Integer.toHexString(type)); throw new DecodeException("Unknown encoded value type: 0x" + Integer.toHexString(type));
} }
......
...@@ -6,17 +6,17 @@ import jadx.core.utils.exceptions.DecodeException; ...@@ -6,17 +6,17 @@ import jadx.core.utils.exceptions.DecodeException;
import java.util.List; import java.util.List;
import com.android.dx.io.DexBuffer.Section; import com.android.dex.Dex;
import com.android.dx.util.Leb128Utils; import com.android.dex.Leb128;
public class StaticValuesParser extends EncValueParser { public class StaticValuesParser extends EncValueParser {
public StaticValuesParser(DexNode dex, Section in) { public StaticValuesParser(DexNode dex, Dex.Section in) {
super(dex, in); super(dex, in);
} }
public int processFields(List<FieldNode> fields) throws DecodeException { public int processFields(List<FieldNode> fields) throws DecodeException {
int count = Leb128Utils.readUnsignedLeb128(in); int count = Leb128.readUnsignedLeb128(in);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
Object value = parseValue(); Object value = parseValue();
fields.get(i).getAttributes().add(new FieldValueAttr(value)); fields.get(i).getAttributes().add(new FieldValueAttr(value));
......
...@@ -13,13 +13,13 @@ import java.util.zip.ZipFile; ...@@ -13,13 +13,13 @@ import java.util.zip.ZipFile;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.android.dx.io.DexBuffer; import com.android.dex.Dex;
public class InputFile { public class InputFile {
private static final Logger LOG = LoggerFactory.getLogger(InputFile.class); private static final Logger LOG = LoggerFactory.getLogger(InputFile.class);
private final File file; private final File file;
private final DexBuffer dexBuf; private final Dex dexBuf;
public InputFile(File file) throws IOException, DecodeException { public InputFile(File file) throws IOException, DecodeException {
this.file = file; this.file = file;
...@@ -29,9 +29,9 @@ public class InputFile { ...@@ -29,9 +29,9 @@ public class InputFile {
String fileName = file.getName(); String fileName = file.getName();
if (fileName.endsWith(".dex")) { if (fileName.endsWith(".dex")) {
this.dexBuf = new DexBuffer(file); this.dexBuf = new Dex(file);
} else if (fileName.endsWith(".apk")) { } else if (fileName.endsWith(".apk")) {
this.dexBuf = new DexBuffer(openDexFromApk(file)); this.dexBuf = new Dex(openDexFromApk(file));
} else if (fileName.endsWith(".class") || fileName.endsWith(".jar")) { } else if (fileName.endsWith(".class") || fileName.endsWith(".jar")) {
try { try {
LOG.info("converting to dex: {} ...", fileName); LOG.info("converting to dex: {} ...", fileName);
...@@ -43,7 +43,7 @@ public class InputFile { ...@@ -43,7 +43,7 @@ public class InputFile {
} else if (j2d.isError()) { } else if (j2d.isError()) {
LOG.warn("dx message: " + j2d.getDxErrors()); LOG.warn("dx message: " + j2d.getDxErrors());
} }
this.dexBuf = new DexBuffer(ba); this.dexBuf = new Dex(ba);
} catch (Throwable e) { } catch (Throwable e) {
throw new DecodeException( throw new DecodeException(
"java class to dex conversion error:\n " + e.getMessage(), e); "java class to dex conversion error:\n " + e.getMessage(), e);
...@@ -76,7 +76,7 @@ public class InputFile { ...@@ -76,7 +76,7 @@ public class InputFile {
return file; return file;
} }
public DexBuffer getDexBuffer() { public Dex getDexBuffer() {
return dexBuf; return dexBuf;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment