General cleanup

This commit is contained in:
Ben Gruver 2012-10-20 23:58:36 -07:00
parent 380ca70a2c
commit 25d385a441
22 changed files with 82 additions and 68 deletions

View File

@ -285,8 +285,8 @@ public enum Opcode
SGET_OBJECT_VOLATILE((short)0xfd, "sget-object-volatile", ReferenceType.FIELD, Format.Format21c, Opcode.ODEX_ONLY | Opcode.ODEXED_STATIC_VOLATILE | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), SGET_OBJECT_VOLATILE((short)0xfd, "sget-object-volatile", ReferenceType.FIELD, Format.Format21c, Opcode.ODEX_ONLY | Opcode.ODEXED_STATIC_VOLATILE | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER),
SPUT_OBJECT_VOLATILE((short)0xfe, "sput-object-volatile", ReferenceType.FIELD, Format.Format21c, Opcode.ODEX_ONLY | Opcode.ODEXED_STATIC_VOLATILE | Opcode.CAN_THROW | Opcode.CAN_CONTINUE); SPUT_OBJECT_VOLATILE((short)0xfe, "sput-object-volatile", ReferenceType.FIELD, Format.Format21c, Opcode.ODEX_ONLY | Opcode.ODEXED_STATIC_VOLATILE | Opcode.CAN_THROW | Opcode.CAN_CONTINUE);
private static Opcode[] opcodesByValue; private static final Opcode[] opcodesByValue;
private static HashMap<Integer, Opcode> opcodesByName; private static final HashMap<Integer, Opcode> opcodesByName;
//if the instruction can throw an exception //if the instruction can throw an exception
public static final int CAN_THROW = 0x1; public static final int CAN_THROW = 0x1;

View File

@ -67,12 +67,12 @@ public class DexBackedAnnotation implements Annotation {
return new VariableSizeList<AnnotationElement>(dexBuf, reader.getOffset()) { return new VariableSizeList<AnnotationElement>(dexBuf, reader.getOffset()) {
@Nonnull @Nonnull
@Override @Override
protected AnnotationElement readItem(DexReader reader, int index) { protected AnnotationElement readItem(@Nonnull DexReader reader, int index) {
return new DexBackedAnnotationElement(reader); return new DexBackedAnnotationElement(reader);
} }
@Override @Override
protected void skipItem(DexReader reader, int index) { protected void skipItem(@Nonnull DexReader reader, int index) {
DexBackedAnnotationElement.skipFrom(reader); DexBackedAnnotationElement.skipFrom(reader);
} }

View File

@ -41,12 +41,12 @@ public class DexBackedAnnotationElement implements AnnotationElement {
@Nonnull public final String name; @Nonnull public final String name;
@Nonnull public final EncodedValue value; @Nonnull public final EncodedValue value;
public DexBackedAnnotationElement(DexReader reader) { public DexBackedAnnotationElement(@Nonnull DexReader reader) {
this.name = reader.getString(reader.readSmallUleb128()); this.name = reader.getString(reader.readSmallUleb128());
this.value = DexBackedEncodedValue.readFrom(reader); this.value = DexBackedEncodedValue.readFrom(reader);
} }
public static void skipFrom(DexReader reader) { public static void skipFrom(@Nonnull DexReader reader) {
reader.skipUleb128(); reader.skipUleb128();
DexBackedEncodedValue.skipFrom(reader); DexBackedEncodedValue.skipFrom(reader);
} }

View File

@ -43,7 +43,7 @@ public class DexBackedCatchAllExceptionHandler extends ImmutableExceptionHandler
instructionOffsetMap.getInstructionIndexAtOffsetExact(reader.readSmallUleb128())); instructionOffsetMap.getInstructionIndexAtOffsetExact(reader.readSmallUleb128()));
} }
public static void skipFrom(DexReader reader) { public static void skipFrom(@Nonnull DexReader reader) {
reader.skipUleb128(); reader.skipUleb128();
} }
} }

View File

@ -92,6 +92,7 @@ public class DexBackedClassDef implements ClassDef {
if (interfacesOffset > 0) { if (interfacesOffset > 0) {
final int size = dexBuf.readSmallUint(interfacesOffset); final int size = dexBuf.readSmallUint(interfacesOffset);
return new FixedSizeList<String>() { return new FixedSizeList<String>() {
@Nonnull
@Override @Override
public String readItem(int index) { public String readItem(int index) {
return dexBuf.getString(dexBuf.readSmallUint(interfacesOffset + 4 + (2*index))); return dexBuf.getString(dexBuf.readSmallUint(interfacesOffset + 4 + (2*index)));
@ -136,7 +137,7 @@ public class DexBackedClassDef implements ClassDef {
@Nonnull @Nonnull
@Override @Override
protected DexBackedField readItem(DexReader reader, int index) { protected DexBackedField readItem(@Nonnull DexReader reader, int index) {
DexBackedField item = new DexBackedField(reader, previousFieldIndex, DexBackedField item = new DexBackedField(reader, previousFieldIndex,
staticInitialValueIterator, annotationIterator); staticInitialValueIterator, annotationIterator);
previousFieldIndex = item.fieldIndex; previousFieldIndex = item.fieldIndex;
@ -144,7 +145,7 @@ public class DexBackedClassDef implements ClassDef {
} }
@Override @Override
protected void skipItem(DexReader reader, int index) { protected void skipItem(@Nonnull DexReader reader, int index) {
previousFieldIndex = DexBackedField.skipEncodedField(reader, previousFieldIndex); previousFieldIndex = DexBackedField.skipEncodedField(reader, previousFieldIndex);
staticInitialValueIterator.skipNext(); staticInitialValueIterator.skipNext();
} }
@ -188,7 +189,7 @@ public class DexBackedClassDef implements ClassDef {
@Nonnull @Nonnull
@Override @Override
protected DexBackedMethod readItem(DexReader reader, int index) { protected DexBackedMethod readItem(@Nonnull DexReader reader, int index) {
DexBackedMethod item = new DexBackedMethod(reader, previousMethodIndex, DexBackedMethod item = new DexBackedMethod(reader, previousMethodIndex,
methodAnnotationIterator, parameterAnnotationIterator); methodAnnotationIterator, parameterAnnotationIterator);
previousMethodIndex = item.methodIndex; previousMethodIndex = item.methodIndex;
@ -196,7 +197,7 @@ public class DexBackedClassDef implements ClassDef {
} }
@Override @Override
protected void skipItem(DexReader reader, int index) { protected void skipItem(@Nonnull DexReader reader, int index) {
previousMethodIndex = DexBackedMethod.skipEncodedMethod(reader, previousMethodIndex); previousMethodIndex = DexBackedMethod.skipEncodedMethod(reader, previousMethodIndex);
staticInitialValueIterator.skipNext(); staticInitialValueIterator.skipNext();
} }

View File

@ -41,9 +41,7 @@ import java.util.List;
public class DexBackedDexFile implements DexFile { public class DexBackedDexFile implements DexFile {
@Nonnull public final DexBuffer dexBuf; @Nonnull public final DexBuffer dexBuf;
private static final int CLASS_DEF_SIZE = 32; public DexBackedDexFile(@Nonnull DexBuffer dexBuf) {
public DexBackedDexFile(DexBuffer dexBuf) {
this.dexBuf = dexBuf; this.dexBuf = dexBuf;
} }
@ -53,6 +51,7 @@ public class DexBackedDexFile implements DexFile {
final int classCount = dexBuf.getClassCount(); final int classCount = dexBuf.getClassCount();
return new FixedSizeList<ClassDef>() { return new FixedSizeList<ClassDef>() {
@Nonnull
@Override @Override
public ClassDef readItem(int index) { public ClassDef readItem(int index) {
int classOffset = dexBuf.getClassDefOffset(index); int classOffset = dexBuf.getClassDefOffset(index);

View File

@ -44,7 +44,7 @@ public class DexBackedExceptionHandler extends ImmutableExceptionHandler {
instructionOffsetMap.getInstructionIndexAtOffsetExact(reader.readSmallUleb128())); instructionOffsetMap.getInstructionIndexAtOffsetExact(reader.readSmallUleb128()));
} }
public static void skipFrom(DexReader reader) { public static void skipFrom(@Nonnull DexReader reader) {
reader.skipUleb128(); reader.skipUleb128();
reader.skipUleb128(); reader.skipUleb128();
} }

View File

@ -73,7 +73,6 @@ public class DexBackedField implements Field {
this.name = reader.getString(reader.readSmallUint(fieldIdItemOffset + NAME_OFFSET)); this.name = reader.getString(reader.readSmallUint(fieldIdItemOffset + NAME_OFFSET));
} }
@Nonnull @Override public String getName() { return name; } @Nonnull @Override public String getName() { return name; }
@Nonnull @Override public String getType() { return type; } @Nonnull @Override public String getType() { return type; }
@Override public int getAccessFlags() { return accessFlags; } @Override public int getAccessFlags() { return accessFlags; }

View File

@ -103,6 +103,7 @@ public class DexBackedMethod implements Method {
final int size = dexBuf.readSmallUint(parametersOffset); final int size = dexBuf.readSmallUint(parametersOffset);
return new FixedSizeList<MethodParameter>() { return new FixedSizeList<MethodParameter>() {
@Nonnull
@Override @Override
public MethodParameter readItem(final int index) { public MethodParameter readItem(final int index) {
return new MethodParameter() { return new MethodParameter() {

View File

@ -83,6 +83,7 @@ public class DexBackedMethodImplementation implements MethodImplementation {
final int handlersStartOffset = triesStartOffset + triesSize*TRY_ITEM_SIZE; final int handlersStartOffset = triesStartOffset + triesSize*TRY_ITEM_SIZE;
return new FixedSizeList<TryBlock>() { return new FixedSizeList<TryBlock>() {
@Nonnull
@Override @Override
public TryBlock readItem(int index) { public TryBlock readItem(int index) {
return new DexBackedTryBlock(dexBuf, return new DexBackedTryBlock(dexBuf,
@ -100,6 +101,7 @@ public class DexBackedMethodImplementation implements MethodImplementation {
return ImmutableList.of(); return ImmutableList.of();
} }
@Nonnull
private ImmutableList<? extends Instruction> buildInstructionList() { private ImmutableList<? extends Instruction> buildInstructionList() {
// instructionsSize is the number of 16-bit code units in the instruction list, not the number of instructions // instructionsSize is the number of 16-bit code units in the instruction list, not the number of instructions
int instructionsSize = dexBuf.readSmallUint(codeOffset + INSTRUCTIONS_SIZE_OFFSET); int instructionsSize = dexBuf.readSmallUint(codeOffset + INSTRUCTIONS_SIZE_OFFSET);
@ -124,6 +126,7 @@ public class DexBackedMethodImplementation implements MethodImplementation {
* *
* @return An InstructionOffsetMap object * @return An InstructionOffsetMap object
*/ */
@Nonnull
private InstructionOffsetMap buildInstructionOffsetMap() { private InstructionOffsetMap buildInstructionOffsetMap() {
int[] offsets = new int[instructions.size()]; int[] offsets = new int[instructions.size()];
int currentOffset = 0; int currentOffset = 0;

View File

@ -40,8 +40,8 @@ import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
public class DexBackedTryBlock implements TryBlock { public class DexBackedTryBlock implements TryBlock {
public final DexBuffer dexBuf; @Nonnull public final DexBuffer dexBuf;
private final InstructionOffsetMap instructionOffsetMap; @Nonnull private final InstructionOffsetMap instructionOffsetMap;
public final int startIndex; public final int startIndex;
public final int instructionCount; public final int instructionCount;
@ -52,10 +52,10 @@ public class DexBackedTryBlock implements TryBlock {
private static final int CODE_UNIT_COUNT_OFFSET = 4; private static final int CODE_UNIT_COUNT_OFFSET = 4;
private static final int HANDLER_OFFSET_OFFSET = 6; private static final int HANDLER_OFFSET_OFFSET = 6;
public DexBackedTryBlock(DexBuffer dexBuf, public DexBackedTryBlock(@Nonnull DexBuffer dexBuf,
int tryItemOffset, int tryItemOffset,
int handlersStartOffset, int handlersStartOffset,
InstructionOffsetMap instructionOffsetMap) { @Nonnull InstructionOffsetMap instructionOffsetMap) {
this.dexBuf = dexBuf; this.dexBuf = dexBuf;
this.instructionOffsetMap = instructionOffsetMap; this.instructionOffsetMap = instructionOffsetMap;
@ -89,12 +89,12 @@ public class DexBackedTryBlock implements TryBlock {
return new VariableSizeList<ExceptionHandler>(dexBuf, reader.getOffset()) { return new VariableSizeList<ExceptionHandler>(dexBuf, reader.getOffset()) {
@Nonnull @Nonnull
@Override @Override
protected ExceptionHandler readItem(DexReader reader, int index) { protected ExceptionHandler readItem(@Nonnull DexReader reader, int index) {
return new DexBackedExceptionHandler(reader, instructionOffsetMap); return new DexBackedExceptionHandler(reader, instructionOffsetMap);
} }
@Override @Override
protected void skipItem(DexReader dexReader, int index) { protected void skipItem(@Nonnull DexReader dexReader, int index) {
DexBackedExceptionHandler.skipFrom(dexReader); DexBackedExceptionHandler.skipFrom(dexReader);
} }
@ -106,7 +106,7 @@ public class DexBackedTryBlock implements TryBlock {
return new VariableSizeList<ExceptionHandler>(dexBuf, reader.getOffset()) { return new VariableSizeList<ExceptionHandler>(dexBuf, reader.getOffset()) {
@Nonnull @Nonnull
@Override @Override
protected ExceptionHandler readItem(DexReader dexReader, int index) { protected ExceptionHandler readItem(@Nonnull DexReader dexReader, int index) {
if (index == sizeWithCatchAll-1) { if (index == sizeWithCatchAll-1) {
return new DexBackedCatchAllExceptionHandler(dexReader, instructionOffsetMap); return new DexBackedCatchAllExceptionHandler(dexReader, instructionOffsetMap);
} else { } else {
@ -115,7 +115,7 @@ public class DexBackedTryBlock implements TryBlock {
} }
@Override @Override
protected void skipItem(DexReader dexReader, int index) { protected void skipItem(@Nonnull DexReader dexReader, int index) {
if (index == sizeWithCatchAll-1) { if (index == sizeWithCatchAll-1) {
DexBackedCatchAllExceptionHandler.skipFrom(dexReader); DexBackedCatchAllExceptionHandler.skipFrom(dexReader);
} else { } else {

View File

@ -293,7 +293,7 @@ public class DexReader {
int o = offset; int o = offset;
byte[] buf = dexBuf.buf; byte[] buf = dexBuf.buf;
int result = 0; int result;
switch (bytes) { switch (bytes) {
case 4: case 4:
result = (buf[o] & 0xff) | result = (buf[o] & 0xff) |
@ -325,7 +325,7 @@ public class DexReader {
int o = offset; int o = offset;
byte[] buf = dexBuf.buf; byte[] buf = dexBuf.buf;
long result = 0; long result;
switch (bytes) { switch (bytes) {
case 8: case 8:
result = (buf[o] & 0xff) | result = (buf[o] & 0xff) |
@ -391,7 +391,7 @@ public class DexReader {
int o = offset; int o = offset;
byte[] buf = dexBuf.buf; byte[] buf = dexBuf.buf;
long result = 0; long result;
switch (bytes) { switch (bytes) {
case 8: case 8:
result = (buf[o] & 0xff) | result = (buf[o] & 0xff) |

View File

@ -42,7 +42,8 @@ import org.jf.util.NibbleUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public abstract class DexBackedInstruction { public abstract class DexBackedInstruction {
public static Instruction readFrom(DexReader reader) { @Nonnull
public static Instruction readFrom(@Nonnull DexReader reader) {
int opcodeValue = reader.readUbyte(); int opcodeValue = reader.readUbyte();
Opcode opcode = Opcode.getOpcodeByValue(opcodeValue); Opcode opcode = Opcode.getOpcodeByValue(opcodeValue);
@ -106,19 +107,19 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction10t instruction10t(Opcode opcode, DexReader reader) { private static Instruction10t instruction10t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int offset = reader.readByte(); int offset = reader.readByte();
return new ImmutableInstruction10t(opcode, offset); return new ImmutableInstruction10t(opcode, offset);
} }
@Nonnull @Nonnull
private static Instruction10x instruction10x(Opcode opcode, DexReader reader) { private static Instruction10x instruction10x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
reader.skipByte(); reader.skipByte();
return new ImmutableInstruction10x(opcode); return new ImmutableInstruction10x(opcode);
} }
@Nonnull @Nonnull
private static Instruction11n instruction11n(Opcode opcode, DexReader reader) { private static Instruction11n instruction11n(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int b = reader.readUbyte(); int b = reader.readUbyte();
int registerA = NibbleUtils.extractLowUnsignedNibble(b); int registerA = NibbleUtils.extractLowUnsignedNibble(b);
int literal = NibbleUtils.extractHighSignedNibble(b); int literal = NibbleUtils.extractHighSignedNibble(b);
@ -126,13 +127,13 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction11x instruction11x(Opcode opcode, DexReader reader) { private static Instruction11x instruction11x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
return new ImmutableInstruction11x(opcode, registerA); return new ImmutableInstruction11x(opcode, registerA);
} }
@Nonnull @Nonnull
private static Instruction12x instruction12x(Opcode opcode, DexReader reader) { private static Instruction12x instruction12x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int b = reader.readUbyte(); int b = reader.readUbyte();
int registerA = NibbleUtils.extractLowUnsignedNibble(b); int registerA = NibbleUtils.extractLowUnsignedNibble(b);
int registerB = NibbleUtils.extractHighUnsignedNibble(b); int registerB = NibbleUtils.extractHighUnsignedNibble(b);
@ -140,14 +141,14 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction20t instruction20t(Opcode opcode, DexReader reader) { private static Instruction20t instruction20t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
reader.skipByte(); reader.skipByte();
int offset = reader.readShort(); int offset = reader.readShort();
return new ImmutableInstruction20t(opcode, offset); return new ImmutableInstruction20t(opcode, offset);
} }
@Nonnull @Nonnull
private static Instruction21c instruction21c(Opcode opcode, DexReader reader) { private static Instruction21c instruction21c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int referenceIndex = reader.readUshort(); int referenceIndex = reader.readUshort();
String reference = reader.getReference(opcode.referenceType, referenceIndex); String reference = reader.getReference(opcode.referenceType, referenceIndex);
@ -155,35 +156,35 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction21ih instruction21ih(Opcode opcode, DexReader reader) { private static Instruction21ih instruction21ih(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int literalHat = reader.readShort(); int literalHat = reader.readShort();
return new ImmutableInstruction21ih(opcode, registerA, literalHat << 16); return new ImmutableInstruction21ih(opcode, registerA, literalHat << 16);
} }
@Nonnull @Nonnull
private static Instruction21lh instruction21lh(Opcode opcode, DexReader reader) { private static Instruction21lh instruction21lh(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int literalHat = reader.readShort(); int literalHat = reader.readShort();
return new ImmutableInstruction21lh(opcode, registerA, ((long)literalHat) << 48); return new ImmutableInstruction21lh(opcode, registerA, ((long)literalHat) << 48);
} }
@Nonnull @Nonnull
private static Instruction21s instruction21s(Opcode opcode, DexReader reader) { private static Instruction21s instruction21s(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int literal = reader.readShort(); int literal = reader.readShort();
return new ImmutableInstruction21s(opcode, registerA, literal); return new ImmutableInstruction21s(opcode, registerA, literal);
} }
@Nonnull @Nonnull
private static Instruction21t instruction21t(Opcode opcode, DexReader reader) { private static Instruction21t instruction21t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int offset = reader.readShort(); int offset = reader.readShort();
return new ImmutableInstruction21t(opcode, registerA, offset); return new ImmutableInstruction21t(opcode, registerA, offset);
} }
@Nonnull @Nonnull
private static Instruction22b instruction22b(Opcode opcode, DexReader reader) { private static Instruction22b instruction22b(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int registerB = reader.readUbyte(); int registerB = reader.readUbyte();
int literal = reader.readByte(); int literal = reader.readByte();
@ -191,7 +192,7 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction22c instruction22c(Opcode opcode, DexReader reader) { private static Instruction22c instruction22c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int b = reader.readUbyte(); int b = reader.readUbyte();
int registerA = NibbleUtils.extractLowUnsignedNibble(b); int registerA = NibbleUtils.extractLowUnsignedNibble(b);
int registerB = NibbleUtils.extractHighUnsignedNibble(b); int registerB = NibbleUtils.extractHighUnsignedNibble(b);
@ -202,7 +203,7 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction22s instruction22s(Opcode opcode, DexReader reader) { private static Instruction22s instruction22s(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int b = reader.readUbyte(); int b = reader.readUbyte();
int registerA = NibbleUtils.extractLowUnsignedNibble(b); int registerA = NibbleUtils.extractLowUnsignedNibble(b);
int registerB = NibbleUtils.extractHighUnsignedNibble(b); int registerB = NibbleUtils.extractHighUnsignedNibble(b);
@ -211,7 +212,7 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction22t instruction22t(Opcode opcode, DexReader reader) { private static Instruction22t instruction22t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int b = reader.readUbyte(); int b = reader.readUbyte();
int registerA = NibbleUtils.extractLowUnsignedNibble(b); int registerA = NibbleUtils.extractLowUnsignedNibble(b);
int registerB = NibbleUtils.extractHighUnsignedNibble(b); int registerB = NibbleUtils.extractHighUnsignedNibble(b);
@ -220,14 +221,14 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction22x instruction22x(Opcode opcode, DexReader reader) { private static Instruction22x instruction22x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int registerB = reader.readUshort(); int registerB = reader.readUshort();
return new ImmutableInstruction22x(opcode, registerA, registerB); return new ImmutableInstruction22x(opcode, registerA, registerB);
} }
@Nonnull @Nonnull
private static Instruction23x instruction23x(Opcode opcode, DexReader reader) { private static Instruction23x instruction23x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int registerB = reader.readUbyte(); int registerB = reader.readUbyte();
int registerC = reader.readUbyte(); int registerC = reader.readUbyte();
@ -235,14 +236,14 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction30t instruction30t(Opcode opcode, DexReader reader) { private static Instruction30t instruction30t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
reader.skipByte(); reader.skipByte();
int offset = reader.readInt(); int offset = reader.readInt();
return new ImmutableInstruction30t(opcode, offset); return new ImmutableInstruction30t(opcode, offset);
} }
@Nonnull @Nonnull
private static Instruction31c instruction31c(Opcode opcode, DexReader reader) { private static Instruction31c instruction31c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int referenceIndex = reader.readSmallUint(); int referenceIndex = reader.readSmallUint();
String reference = reader.getReference(opcode.referenceType, referenceIndex); String reference = reader.getReference(opcode.referenceType, referenceIndex);
@ -250,21 +251,21 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction31i instruction31i(Opcode opcode, DexReader reader) { private static Instruction31i instruction31i(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int literal = reader.readInt(); int literal = reader.readInt();
return new ImmutableInstruction31i(opcode, registerA, literal); return new ImmutableInstruction31i(opcode, registerA, literal);
} }
@Nonnull @Nonnull
private static Instruction31t instruction31t(Opcode opcode, DexReader reader) { private static Instruction31t instruction31t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
int offset = reader.readInt(); int offset = reader.readInt();
return new ImmutableInstruction31t(opcode, registerA, offset); return new ImmutableInstruction31t(opcode, registerA, offset);
} }
@Nonnull @Nonnull
private static Instruction32x instruction32x(Opcode opcode, DexReader reader) { private static Instruction32x instruction32x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
reader.skipByte(); reader.skipByte();
int registerA = reader.readUshort(); int registerA = reader.readUshort();
int registerB = reader.readUshort(); int registerB = reader.readUshort();
@ -272,7 +273,7 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction35c instruction35c(Opcode opcode, DexReader reader) { private static Instruction35c instruction35c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int b = reader.readUbyte(); int b = reader.readUbyte();
int registerCount = NibbleUtils.extractHighUnsignedNibble(b); int registerCount = NibbleUtils.extractHighUnsignedNibble(b);
int registerG = NibbleUtils.extractLowUnsignedNibble(b); int registerG = NibbleUtils.extractLowUnsignedNibble(b);
@ -293,7 +294,7 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction3rc instruction3rc(Opcode opcode, DexReader reader) { private static Instruction3rc instruction3rc(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerCount = reader.readUbyte(); int registerCount = reader.readUbyte();
int referenceIndex = reader.readUshort(); int referenceIndex = reader.readUshort();
String reference = reader.getReference(opcode.referenceType, referenceIndex); String reference = reader.getReference(opcode.referenceType, referenceIndex);
@ -302,7 +303,7 @@ public abstract class DexBackedInstruction {
} }
@Nonnull @Nonnull
private static Instruction51l instruction51l(Opcode opcode, DexReader reader) { private static Instruction51l instruction51l(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte(); int registerA = reader.readUbyte();
long literal = reader.readLong(); long literal = reader.readLong();
return new ImmutableInstruction51l(opcode, registerA, literal); return new ImmutableInstruction51l(opcode, registerA, literal);

View File

@ -53,6 +53,7 @@ public abstract class AnnotationsDirectory {
@Nonnull public abstract AnnotationIterator getMethodAnnotationIterator(); @Nonnull public abstract AnnotationIterator getMethodAnnotationIterator();
@Nonnull public abstract AnnotationIterator getParameterAnnotationIterator(); @Nonnull public abstract AnnotationIterator getParameterAnnotationIterator();
@Nonnull
public static AnnotationsDirectory newOrEmpty(@Nonnull DexBuffer dexBuf, public static AnnotationsDirectory newOrEmpty(@Nonnull DexBuffer dexBuf,
int directoryAnnotationsOffset) { int directoryAnnotationsOffset) {
if (directoryAnnotationsOffset == 0) { if (directoryAnnotationsOffset == 0) {
@ -76,6 +77,7 @@ public abstract class AnnotationsDirectory {
if (annotationSetOffset != 0) { if (annotationSetOffset != 0) {
final int size = dexBuf.readSmallUint(annotationSetOffset); final int size = dexBuf.readSmallUint(annotationSetOffset);
return new FixedSizeList<DexBackedAnnotation>() { return new FixedSizeList<DexBackedAnnotation>() {
@Nonnull
@Override @Override
public DexBackedAnnotation readItem(int index) { public DexBackedAnnotation readItem(int index) {
int annotationOffset = dexBuf.readSmallUint(annotationSetOffset + 4 + (4*index)); int annotationOffset = dexBuf.readSmallUint(annotationSetOffset + 4 + (4*index));
@ -89,12 +91,14 @@ public abstract class AnnotationsDirectory {
return ImmutableList.of(); return ImmutableList.of();
} }
@Nonnull
public static List<List<? extends DexBackedAnnotation>> getParameterAnnotations(@Nonnull final DexBuffer dexBuf, public static List<List<? extends DexBackedAnnotation>> getParameterAnnotations(@Nonnull final DexBuffer dexBuf,
final int annotationSetListOffset) { final int annotationSetListOffset) {
if (annotationSetListOffset > 0) { if (annotationSetListOffset > 0) {
final int size = dexBuf.readSmallUint(annotationSetListOffset); final int size = dexBuf.readSmallUint(annotationSetListOffset);
return new FixedSizeList<List<? extends DexBackedAnnotation>>() { return new FixedSizeList<List<? extends DexBackedAnnotation>>() {
@Nonnull
@Override @Override
public List<? extends DexBackedAnnotation> readItem(int index) { public List<? extends DexBackedAnnotation> readItem(int index) {
int annotationSetOffset = dexBuf.readSmallUint(annotationSetListOffset + 4 + index * 4); int annotationSetOffset = dexBuf.readSmallUint(annotationSetListOffset + 4 + index * 4);

View File

@ -31,6 +31,7 @@
package org.jf.dexlib2.dexbacked.util; package org.jf.dexlib2.dexbacked.util;
import javax.annotation.Nonnull;
import java.util.AbstractList; import java.util.AbstractList;
/** /**
@ -51,5 +52,6 @@ public abstract class FixedSizeList<T> extends AbstractList<T> {
* @param index The index of the item. This is guaranteed to be in [0, size) * @param index The index of the item. This is guaranteed to be in [0, size)
* @return The item at the given index * @return The item at the given index
*/ */
@Nonnull
public abstract T readItem(int index); public abstract T readItem(int index);
} }

View File

@ -33,12 +33,13 @@ package org.jf.dexlib2.dexbacked.util;
import org.jf.util.ExceptionWithContext; import org.jf.util.ExceptionWithContext;
import javax.annotation.Nonnull;
import java.util.Arrays; import java.util.Arrays;
public class InstructionOffsetMap { public class InstructionOffsetMap {
private final int[] instructionOffsets; @Nonnull private final int[] instructionOffsets;
public InstructionOffsetMap(int[] instructionOffsets) { public InstructionOffsetMap(@Nonnull int[] instructionOffsets) {
this.instructionOffsets = instructionOffsets; this.instructionOffsets = instructionOffsets;
} }

View File

@ -41,7 +41,7 @@ import javax.annotation.Nullable;
public abstract class StaticInitialValueIterator { public abstract class StaticInitialValueIterator {
public static final StaticInitialValueIterator EMPTY = new StaticInitialValueIterator() { public static final StaticInitialValueIterator EMPTY = new StaticInitialValueIterator() {
@Override public EncodedValue getNextOrNull() { return null; } @Nullable @Override public EncodedValue getNextOrNull() { return null; }
@Override public void skipNext() {} @Override public void skipNext() {}
}; };

View File

@ -53,9 +53,9 @@ public abstract class VariableSizeList<T> extends AbstractSequentialList<T> {
} }
@Nonnull @Nonnull
protected abstract T readItem(DexReader reader, int index); protected abstract T readItem(@Nonnull DexReader reader, int index);
protected void skipItem(DexReader reader, int index) { protected void skipItem(@Nonnull DexReader reader, int index) {
readItem(reader, index); readItem(reader, index);
} }

View File

@ -68,7 +68,7 @@ public abstract class VariableSizeListWithContext<T> extends AbstractSequentialL
private int index = 0; private int index = 0;
@Nonnull private final DexReader reader; @Nonnull private final DexReader reader;
public Iterator(DexBuffer dexBuf, int offset) { public Iterator(@Nonnull DexBuffer dexBuf, int offset) {
this.reader = dexBuf.readerAt(offset); this.reader = dexBuf.readerAt(offset);
} }
@ -79,7 +79,7 @@ public abstract class VariableSizeListWithContext<T> extends AbstractSequentialL
* *
* @return The next item that was read from {@code reader} * @return The next item that was read from {@code reader}
*/ */
@Nonnull protected abstract T readItem(DexReader reader, int index); @Nonnull protected abstract T readItem(@Nonnull DexReader reader, int index);
/** /**
* Skip the next item in {@code reader}. * Skip the next item in {@code reader}.
@ -88,7 +88,7 @@ public abstract class VariableSizeListWithContext<T> extends AbstractSequentialL
* can be overridden if skipping an item can be implemented more efficiently than reading * can be overridden if skipping an item can be implemented more efficiently than reading
* the same item. * the same item.
*/ */
protected void skipItem(DexReader reader, int index) { protected void skipItem(@Nonnull DexReader reader, int index) {
readItem(reader, index); readItem(reader, index);
} }

View File

@ -54,12 +54,12 @@ public class DexBackedAnnotationEncodedValue implements AnnotationEncodedValue {
skipElements(reader); skipElements(reader);
} }
public static void skipFrom(DexReader reader) { public static void skipFrom(@Nonnull DexReader reader) {
reader.skipUleb128(); reader.skipUleb128();
skipElements(reader); skipElements(reader);
} }
private static void skipElements(DexReader reader) { private static void skipElements(@Nonnull DexReader reader) {
int elementCount = reader.readSmallUleb128(); int elementCount = reader.readSmallUleb128();
for (int i=0; i<elementCount; i++) { for (int i=0; i<elementCount; i++) {
reader.skipUleb128(); reader.skipUleb128();
@ -79,12 +79,12 @@ public class DexBackedAnnotationEncodedValue implements AnnotationEncodedValue {
return new VariableSizeList<AnnotationElement>(dexBuf, reader.getOffset()) { return new VariableSizeList<AnnotationElement>(dexBuf, reader.getOffset()) {
@Nonnull @Nonnull
@Override @Override
protected AnnotationElement readItem(DexReader dexReader, int index) { protected AnnotationElement readItem(@Nonnull DexReader dexReader, int index) {
return new DexBackedAnnotationElement(dexReader); return new DexBackedAnnotationElement(dexReader);
} }
@Override @Override
protected void skipItem(DexReader reader, int index) { protected void skipItem(@Nonnull DexReader reader, int index) {
DexBackedAnnotationElement.skipFrom(reader); DexBackedAnnotationElement.skipFrom(reader);
} }

View File

@ -74,7 +74,7 @@ public class DexBackedArrayEncodedValue implements ArrayEncodedValue {
} }
@Override @Override
protected void skipItem(DexReader reader, int index) { protected void skipItem(@Nonnull DexReader reader, int index) {
DexBackedEncodedValue.skipFrom(reader); DexBackedEncodedValue.skipFrom(reader);
} }

View File

@ -38,8 +38,11 @@ import org.jf.dexlib2.immutable.value.*;
import org.jf.dexlib2.util.Preconditions; import org.jf.dexlib2.util.Preconditions;
import org.jf.util.ExceptionWithContext; import org.jf.util.ExceptionWithContext;
import javax.annotation.Nonnull;
public abstract class DexBackedEncodedValue { public abstract class DexBackedEncodedValue {
public static EncodedValue readFrom(DexReader reader) { @Nonnull
public static EncodedValue readFrom(@Nonnull DexReader reader) {
int startOffset = reader.getOffset(); int startOffset = reader.getOffset();
try { try {
@ -105,7 +108,7 @@ public abstract class DexBackedEncodedValue {
} }
} }
public static void skipFrom(DexReader reader) { public static void skipFrom(@Nonnull DexReader reader) {
int startOffset = reader.getOffset(); int startOffset = reader.getOffset();
try { try {