private void printTypeLists() throws IOException { if (tableOfContents.typeLists.off == -1) { System.out.println("No type lists"); return; } DexBuffer.Section in = dexBuffer.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(" " + dexBuffer.typeNames().get((int) in.readShort())); } if (size % 2 == 1) { in.readShort(); // retain alignment } System.out.println(); } }
private void readMap(DexBuffer.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 Code readCode() { int registersSize = readUnsignedShort(); int insSize = readUnsignedShort(); int outsSize = readUnsignedShort(); int triesSize = readUnsignedShort(); int debugInfoOffset = readInt(); int instructionsSize = readInt(); short[] instructions = readShortArray(instructionsSize); Code.Try[] tries = new Code.Try[triesSize]; Code.CatchHandler[] catchHandlers = new Code.CatchHandler[0]; if (triesSize > 0) { if (instructions.length % 2 == 1) { readShort(); // padding } for (int i = 0; i < triesSize; i++) { int startAddress = readInt(); int instructionCount = readUnsignedShort(); int handlerOffset = readUnsignedShort(); tries[i] = new Code.Try(startAddress, instructionCount, handlerOffset); } int catchHandlersSize = readUleb128(); catchHandlers = new Code.CatchHandler[catchHandlersSize]; for (int i = 0; i < catchHandlersSize; i++) { catchHandlers[i] = readCatchHandler(); } } return new Code(registersSize, insSize, outsSize, debugInfoOffset, instructions, tries, catchHandlers); }
public int readUnsignedShort() { return readShort() & 0xffff; }
public short[] readShortArray(int length) { short[] result = new short[length]; for (int i = 0; i < length; i++) { result[i] = readShort(); } return result; }
public TypeList readTypeList() { int size = readInt(); short[] types = new short[size]; for (int i = 0; i < size; i++) { types[i] = readShort(); } alignToFourBytes(); return new TypeList(DexBuffer.this, types); }