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(); } }
public String readString() { int offset = readInt(); int savedPosition = position; position = offset; 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 { position = savedPosition; } }
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); }
int classAnnotationsOffset = indexMap.adjustAnnotationSet(directoryIn.readInt()); annotationsDirectoryOut.writeInt(classAnnotationsOffset); int fieldsSize = directoryIn.readInt(); annotationsDirectoryOut.writeInt(fieldsSize); int methodsSize = directoryIn.readInt(); annotationsDirectoryOut.writeInt(methodsSize); int parameterListSize = directoryIn.readInt(); annotationsDirectoryOut.writeInt(parameterListSize); annotationsDirectoryOut.writeInt(indexMap.adjustField(directoryIn.readInt())); annotationsDirectoryOut.writeInt(indexMap.adjustAnnotationSet(directoryIn.readInt())); annotationsDirectoryOut.writeInt(indexMap.adjustMethod(directoryIn.readInt())); indexMap.adjustAnnotationSet(directoryIn.readInt())); annotationsDirectoryOut.writeInt(indexMap.adjustMethod(directoryIn.readInt())); DexBuffer.Section refListIn = in.open(directoryIn.readInt()); int parameterCount = refListIn.readInt(); annotationSetRefListOut.writeInt(parameterCount); for (int p = 0; p < parameterCount; p++) { annotationSetRefListOut.writeInt(indexMap.adjustAnnotationSet(refListIn.readInt()));
checksum = headerIn.readInt(); signature = headerIn.readByteArray(20); fileSize = headerIn.readInt(); int headerSize = headerIn.readInt(); if (headerSize != SizeOf.HEADER_ITEM) { throw new DexException("Unexpected header: 0x" + Integer.toHexString(headerSize)); int endianTag = headerIn.readInt(); if (endianTag != DexFormat.ENDIAN_TAG) { throw new DexException("Unexpected endian tag: 0x" + Integer.toHexString(endianTag)); linkSize = headerIn.readInt(); linkOff = headerIn.readInt(); mapList.off = headerIn.readInt(); if (mapList.off == 0) { throw new DexException("Cannot merge dex files that do not contain a map"); stringIds.size = headerIn.readInt(); stringIds.off = headerIn.readInt(); typeIds.size = headerIn.readInt(); typeIds.off = headerIn.readInt(); protoIds.size = headerIn.readInt(); protoIds.off = headerIn.readInt(); fieldIds.size = headerIn.readInt(); fieldIds.off = headerIn.readInt(); methodIds.size = headerIn.readInt(); methodIds.off = headerIn.readInt(); classDefs.size = headerIn.readInt(); classDefs.off = headerIn.readInt();
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 ClassDef readClassDef() { int offset = getPosition(); int type = readInt(); int accessFlags = readInt(); int supertype = readInt(); int interfacesOffset = readInt(); int sourceFileIndex = readInt(); int annotationsOffset = readInt(); int classDataOffset = readInt(); int staticValuesOffset = readInt(); return new ClassDef(DexBuffer.this, offset, type, accessFlags, supertype, interfacesOffset, sourceFileIndex, annotationsOffset, classDataOffset, staticValuesOffset); }
public MethodId readMethodId() { int declaringClassIndex = readUnsignedShort(); int protoIndex = readUnsignedShort(); int nameIndex = readInt(); return new MethodId(DexBuffer.this, declaringClassIndex, protoIndex, nameIndex); }
public FieldId readFieldId() { int declaringClassIndex = readUnsignedShort(); int typeIndex = readUnsignedShort(); int nameIndex = readInt(); return new FieldId(DexBuffer.this, declaringClassIndex, typeIndex, nameIndex); }
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); }
@Override public Integer get(int index) { checkBounds(index, tableOfContents.typeIds.size); return open(tableOfContents.typeIds.off + (index * SizeOf.TYPE_ID_ITEM)).readInt(); } @Override public int size() {
/** * Transform all annotations on a single type, member or parameter. */ private void transformAnnotationSet(IndexMap indexMap, DexBuffer.Section setIn) { contentsOut.annotationSets.size++; annotationSetOut.assertFourByteAligned(); indexMap.putAnnotationSetOffset(setIn.getPosition(), annotationSetOut.getPosition()); int size = setIn.readInt(); annotationSetOut.writeInt(size); for (int j = 0; j < size; j++) { annotationSetOut.writeInt(indexMap.adjustAnnotation(setIn.readInt())); } }
@Override Integer read(DexBuffer.Section in, IndexMap indexMap, int index) { int stringIndex = in.readInt(); return indexMap.adjustString(stringIndex); }