public void parse(int offset) throws DecodeException { Section section = dex.openSection(offset); // TODO read as unsigned int int classAnnotationsOffset = section.readInt(); int fieldsCount = section.readInt(); int annotatedMethodsCount = section.readInt(); int annotatedParametersCount = section.readInt(); if (classAnnotationsOffset != 0) { cls.addAttr(readAnnotationSet(classAnnotationsOffset)); } for (int i = 0; i < fieldsCount; i++) { FieldNode f = cls.searchFieldById(section.readInt()); f.addAttr(readAnnotationSet(section.readInt())); } for (int i = 0; i < annotatedMethodsCount; i++) { MethodNode m = cls.searchMethodById(section.readInt()); m.addAttr(readAnnotationSet(section.readInt())); } for (int i = 0; i < annotatedParametersCount; i++) { MethodNode mth = cls.searchMethodById(section.readInt()); // read annotation ref list Section ss = dex.openSection(section.readInt()); int size = ss.readInt(); MethodParameters params = new MethodParameters(size); for (int j = 0; j < size; j++) { params.getParamList().add(readAnnotationSet(ss.readInt())); } mth.addAttr(params); } }
public void process() throws DecodeException { int addr = 0; int line = section.readUleb128(); int paramsCount = section.readUleb128(); List<RegisterArg> mthArgs = mth.getArguments(false); for (int i = 0; i < paramsCount; i++) { int id = section.readUleb128() - 1; if (id != DexNode.NO_INDEX) { String name = dex.getString(id); int c = section.readByte() & 0xFF; while (c != DBG_END_SEQUENCE) { switch (c) { case DBG_ADVANCE_PC: { int addrInc = section.readUleb128(); addr = addrChange(addr, addrInc, line); setLine(addr, line); line += section.readSleb128(); break; int regNum = section.readUleb128(); int nameId = section.readUleb128() - 1; int type = section.readUleb128() - 1; LocalVar var = new LocalVar(dex, regNum, nameId, type, DexNode.NO_INDEX); startVar(var, addr, line); int regNum = section.readUleb128(); int nameId = section.readUleb128() - 1;
private void transformDebugInfoItem(Dex.Section in, IndexMap indexMap) { contentsOut.debugInfos.size++; int lineStart = in.readUleb128(); debugInfoOut.writeUleb128(lineStart); int parametersSize = in.readUleb128(); debugInfoOut.writeUleb128(parametersSize); int parameterName = in.readUleb128p1(); debugInfoOut.writeUleb128p1(indexMap.adjustString(parameterName)); int opcode = in.readByte(); debugInfoOut.writeByte(opcode); addrDiff = in.readUleb128(); debugInfoOut.writeUleb128(addrDiff); break; lineDiff = in.readSleb128(); debugInfoOut.writeSleb128(lineDiff); break; registerNum = in.readUleb128(); debugInfoOut.writeUleb128(registerNum); nameIndex = in.readUleb128p1(); debugInfoOut.writeUleb128p1(indexMap.adjustString(nameIndex)); typeIndex = in.readUleb128p1(); debugInfoOut.writeUleb128p1(indexMap.adjustType(typeIndex)); if (opcode == DBG_START_LOCAL_EXTENDED) { sigIndex = in.readUleb128p1();
private void transformDebugInfoItem(Dex.Section in, IndexMap indexMap) { contentsOut.debugInfos.size++; int lineStart = in.readUleb128(); debugInfoOut.writeUleb128(lineStart); int parametersSize = in.readUleb128(); debugInfoOut.writeUleb128(parametersSize); int parameterName = in.readUleb128p1(); debugInfoOut.writeUleb128p1(indexMap.adjustString(parameterName)); int opcode = in.readByte(); debugInfoOut.writeByte(opcode); addrDiff = in.readUleb128(); debugInfoOut.writeUleb128(addrDiff); break; lineDiff = in.readSleb128(); debugInfoOut.writeSleb128(lineDiff); break; registerNum = in.readUleb128(); debugInfoOut.writeUleb128(registerNum); nameIndex = in.readUleb128p1(); debugInfoOut.writeUleb128p1(indexMap.adjustString(nameIndex)); typeIndex = in.readUleb128p1(); debugInfoOut.writeUleb128p1(indexMap.adjustType(typeIndex)); if (opcode == DBG_START_LOCAL_EXTENDED) { sigIndex = in.readUleb128p1();
private void transformDebugInfoItem(Dex.Section in, IndexMap indexMap) { contentsOut.debugInfos.size++; int lineStart = in.readUleb128(); debugInfoOut.writeUleb128(lineStart); int parametersSize = in.readUleb128(); debugInfoOut.writeUleb128(parametersSize); int parameterName = in.readUleb128p1(); debugInfoOut.writeUleb128p1(indexMap.adjustString(parameterName)); int opcode = in.readByte(); debugInfoOut.writeByte(opcode); addrDiff = in.readUleb128(); debugInfoOut.writeUleb128(addrDiff); break; lineDiff = in.readSleb128(); debugInfoOut.writeSleb128(lineDiff); break; registerNum = in.readUleb128(); debugInfoOut.writeUleb128(registerNum); nameIndex = in.readUleb128p1(); debugInfoOut.writeUleb128p1(indexMap.adjustString(nameIndex)); typeIndex = in.readUleb128p1(); debugInfoOut.writeUleb128p1(indexMap.adjustType(typeIndex)); if (opcode == DBG_START_LOCAL_EXTENDED) { sigIndex = in.readUleb128p1();
private Code readCode() { int registersSize = readUnsignedShort(); int insSize = readUnsignedShort(); int outsSize = readUnsignedShort(); int triesSize = readUnsignedShort(); int debugInfoOffset = readInt(); int instructionsSize = readInt(); short[] instructions = readShortArray(instructionsSize); Try[] tries; CatchHandler[] catchHandlers; if (triesSize > 0) { if (instructions.length % 2 == 1) { readShort(); // padding } /* * We can't read the tries until we've read the catch handlers. * Unfortunately they're in the opposite order in the dex file * so we need to read them out-of-order. */ Section triesSection = open(data.position()); skip(triesSize * SizeOf.TRY_ITEM); catchHandlers = readCatchHandlers(); tries = triesSection.readTries(triesSize, catchHandlers); } else { tries = new Try[0]; catchHandlers = new CatchHandler[0]; } return new Code(registersSize, insSize, outsSize, debugInfoOffset, instructions, tries, catchHandlers); }
private Code readCode() { int registersSize = readUnsignedShort(); int insSize = readUnsignedShort(); int outsSize = readUnsignedShort(); int triesSize = readUnsignedShort(); int debugInfoOffset = readInt(); int instructionsSize = readInt(); short[] instructions = readShortArray(instructionsSize); Try[] tries; CatchHandler[] catchHandlers; if (triesSize > 0) { if (instructions.length % 2 == 1) { readShort(); // padding } /* * We can't read the tries until we've read the catch handlers. * Unfortunately they're in the opposite order in the dex file * so we need to read them out-of-order. */ Section triesSection = open(data.position()); skip(triesSize * SizeOf.TRY_ITEM); catchHandlers = readCatchHandlers(); tries = triesSection.readTries(triesSize, catchHandlers); } else { tries = new Try[0]; catchHandlers = new CatchHandler[0]; } return new Code(registersSize, insSize, outsSize, debugInfoOffset, instructions, tries, catchHandlers); }
private Code readCode() { int registersSize = readUnsignedShort(); int insSize = readUnsignedShort(); int outsSize = readUnsignedShort(); int triesSize = readUnsignedShort(); int debugInfoOffset = readInt(); int instructionsSize = readInt(); short[] instructions = readShortArray(instructionsSize); Try[] tries; CatchHandler[] catchHandlers; if (triesSize > 0) { if (instructions.length % 2 == 1) { readShort(); // padding } /* * We can't read the tries until we've read the catch handlers. * Unfortunately they're in the opposite order in the dex file * so we need to read them out-of-order. */ Section triesSection = open(data.position()); skip(triesSize * SizeOf.TRY_ITEM); catchHandlers = readCatchHandlers(); tries = triesSection.readTries(triesSize, catchHandlers); } else { tries = new Try[0]; catchHandlers = new CatchHandler[0]; } return new Code(registersSize, insSize, outsSize, debugInfoOffset, instructions, tries, catchHandlers); }
private void readMap(Dex.Section in) throws IOException { int mapSize = in.readInt(); Section previous = null; for (int i = 0; i < mapSize; i++) { short type = in.readShort(); in.readShort(); // unused Section section = getSection(type); int size = in.readInt(); int offset = in.readInt(); if ((section.size != 0 && section.size != size) || (section.off != -1 && section.off != offset)) { throw new DexException("Unexpected map value for 0x" + Integer.toHexString(type)); } section.size = size; section.off = offset; if (previous != null && previous.off > section.off) { throw new DexException("Map is unsorted at " + previous + ", " + section); } previous = section; } Arrays.sort(sections); }
private void readMap(Dex.Section in) throws IOException { int mapSize = in.readInt(); Section previous = null; for (int i = 0; i < mapSize; i++) { short type = in.readShort(); in.readShort(); // unused Section section = getSection(type); int size = in.readInt(); int offset = in.readInt(); if ((section.size != 0 && section.size != size) || (section.off != -1 && section.off != offset)) { throw new DexException("Unexpected map value for 0x" + Integer.toHexString(type)); } section.size = size; section.off = offset; if (previous != null && previous.off > section.off) { throw new DexException("Map is unsorted at " + previous + ", " + section); } previous = section; } Arrays.sort(sections); }
private void readMap(Dex.Section in) throws IOException { int mapSize = in.readInt(); Section previous = null; for (int i = 0; i < mapSize; i++) { short type = in.readShort(); in.readShort(); // unused Section section = getSection(type); int size = in.readInt(); int offset = in.readInt(); if ((section.size != 0 && section.size != size) || (section.off != -1 && section.off != offset)) { throw new DexException("Unexpected map value for 0x" + Integer.toHexString(type)); } section.size = size; section.off = offset; if (previous != null && previous.off > section.off) { throw new DexException("Map is unsorted at " + previous + ", " + section); } previous = section; } Arrays.sort(sections); }
public String readString() { int offset = readInt(); int savedPosition = data.position(); int savedLimit = data.limit(); data.position(offset); data.limit(data.capacity()); try { int expectedLength = readUleb128(); String result = Mutf8.decode(this, new char[expectedLength]); if (result.length() != expectedLength) { throw new DexException("Declared length " + expectedLength + " doesn't match decoded length of " + result.length()); } return result; } catch (UTFDataFormatException e) { throw new DexException(e); } finally { data.position(savedPosition); data.limit(savedLimit); } }
private void printTypeLists() throws IOException { if (tableOfContents.typeLists.off == -1) { System.out.println("No type lists"); return; } Dex.Section in = dex.open(tableOfContents.typeLists.off); for (int i = 0; i < tableOfContents.typeLists.size; i++) { int size = in.readInt(); System.out.print("Type list i=" + i + ", size=" + size + ", elements="); for (int t = 0; t < size; t++) { System.out.print(" " + dex.typeNames().get((int) in.readShort())); } if (size % 2 == 1) { in.readShort(); // retain alignment } System.out.println(); } }
private void printTypeLists() throws IOException { if (tableOfContents.typeLists.off == -1) { System.out.println("No type lists"); return; } Dex.Section in = dex.open(tableOfContents.typeLists.off); for (int i = 0; i < tableOfContents.typeLists.size; i++) { int size = in.readInt(); System.out.print("Type list i=" + i + ", size=" + size + ", elements="); for (int t = 0; t < size; t++) { System.out.print(" " + dex.typeNames().get((int) in.readShort())); } if (size % 2 == 1) { in.readShort(); // retain alignment } System.out.println(); } }
private void printTypeLists() throws IOException { if (tableOfContents.typeLists.off == -1) { System.out.println("No type lists"); return; } Dex.Section in = dex.open(tableOfContents.typeLists.off); for (int i = 0; i < tableOfContents.typeLists.size; i++) { int size = in.readInt(); System.out.print("Type list i=" + i + ", size=" + size + ", elements="); for (int t = 0; t < size; t++) { System.out.print(" " + dex.typeNames().get((int) in.readShort())); } if (size % 2 == 1) { in.readShort(); // retain alignment } System.out.println(); } }
public int readUnsignedShort() { return readShort() & 0xffff; }
@Override MethodId read(Dex.Section in, IndexMap indexMap, int index) { return indexMap.adjust(in.readMethodId()); }
@Override ProtoId read(Dex.Section in, IndexMap indexMap, int index) { return indexMap.adjust(in.readProtoId()); }
@Override String read(Dex.Section in, IndexMap indexMap, int index) { return in.readString(); }
public int readUnsignedShort() { return readShort() & 0xffff; }