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 Code.CatchHandler readCatchHandler() { int size = readSleb128(); int handlersCount = Math.abs(size); int[] typeIndexes = new int[handlersCount]; int[] addresses = new int[handlersCount]; for (int i = 0; i < handlersCount; i++) { typeIndexes[i] = readUleb128(); addresses[i] = readUleb128(); } int catchAllAddress = size <= 0 ? readUleb128() : -1; return new Code.CatchHandler(typeIndexes, addresses, catchAllAddress); }
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 Annotation readAnnotation() { byte visibility = readByte(); int typeIndex = readUleb128(); int size = readUleb128(); int[] names = new int[size]; EncodedValue[] values = new EncodedValue[size]; for (int i = 0; i < size; i++) { names[i] = readUleb128(); values[i] = readEncodedValue(); } return new Annotation(DexBuffer.this, visibility, typeIndex, names, values); }
private ClassData.Method[] readMethods(int count) { ClassData.Method[] result = new ClassData.Method[count]; int methodIndex = 0; for (int i = 0; i < count; i++) { methodIndex += readUleb128(); // method index diff int accessFlags = readUleb128(); int codeOff = readUleb128(); result[i] = new ClassData.Method(methodIndex, accessFlags, codeOff); } return result; }
private ClassData readClassData() { int staticFieldsSize = readUleb128(); int instanceFieldsSize = readUleb128(); int directMethodsSize = readUleb128(); int virtualMethodsSize = readUleb128(); ClassData.Field[] staticFields = readFields(staticFieldsSize); ClassData.Field[] instanceFields = readFields(instanceFieldsSize); ClassData.Method[] directMethods = readMethods(directMethodsSize); ClassData.Method[] virtualMethods = readMethods(virtualMethodsSize); return new ClassData(staticFields, instanceFields, directMethods, virtualMethods); }
private ClassData.Field[] readFields(int count) { ClassData.Field[] result = new ClassData.Field[count]; int fieldIndex = 0; for (int i = 0; i < count; i++) { fieldIndex += readUleb128(); // field index diff int accessFlags = readUleb128(); result[i] = new ClassData.Field(fieldIndex, accessFlags); } return result; }