use of org.jf.dexlib2.dexbacked.util.VariableSizeLookaheadIterator in project smali by JesusFreke.
the class DexBackedClassDef method getDirectMethods.
@Nonnull
public Iterable<? extends DexBackedMethod> getDirectMethods(final boolean skipDuplicates) {
if (directMethodCount > 0) {
DexReader reader = dexFile.getDataBuffer().readerAt(getDirectMethodsOffset());
final AnnotationsDirectory annotationsDirectory = getAnnotationsDirectory();
final int methodsStartOffset = reader.getOffset();
Iterator<Integer> hiddenApiRestrictionIterator = hiddenApiRestrictionsReader == null ? null : hiddenApiRestrictionsReader.getRestrictionsForDirectMethods();
return new Iterable<DexBackedMethod>() {
@Nonnull
@Override
public Iterator<DexBackedMethod> iterator() {
final AnnotationsDirectory.AnnotationIterator methodAnnotationIterator = annotationsDirectory.getMethodAnnotationIterator();
final AnnotationsDirectory.AnnotationIterator parameterAnnotationIterator = annotationsDirectory.getParameterAnnotationIterator();
return new VariableSizeLookaheadIterator<DexBackedMethod>(dexFile.getDataBuffer(), methodsStartOffset) {
private int count;
@Nullable
private MethodReference previousMethod;
private int previousIndex;
@Nullable
@Override
protected DexBackedMethod readNextItem(@Nonnull DexReader reader) {
while (true) {
if (++count > directMethodCount) {
virtualMethodsOffset = reader.getOffset();
return endOfData();
}
int hiddenApiRestrictions = NO_HIDDEN_API_RESTRICTIONS;
if (hiddenApiRestrictionIterator != null) {
hiddenApiRestrictions = hiddenApiRestrictionIterator.next();
}
DexBackedMethod item = new DexBackedMethod(dexFile, reader, DexBackedClassDef.this, previousIndex, methodAnnotationIterator, parameterAnnotationIterator, hiddenApiRestrictions);
MethodReference currentMethod = previousMethod;
MethodReference nextMethod = ImmutableMethodReference.of(item);
previousMethod = nextMethod;
previousIndex = item.methodIndex;
if (skipDuplicates && currentMethod != null && currentMethod.equals(nextMethod)) {
continue;
}
return item;
}
}
};
}
};
} else {
if (directMethodsOffset > 0) {
virtualMethodsOffset = directMethodsOffset;
}
return ImmutableSet.of();
}
}
use of org.jf.dexlib2.dexbacked.util.VariableSizeLookaheadIterator in project smali by JesusFreke.
the class DexBackedClassDef method getStaticFields.
@Nonnull
public Iterable<? extends DexBackedField> getStaticFields(final boolean skipDuplicates) {
if (staticFieldCount > 0) {
DexReader<? extends DexBuffer> reader = dexFile.getDataBuffer().readerAt(staticFieldsOffset);
final AnnotationsDirectory annotationsDirectory = getAnnotationsDirectory();
final int staticInitialValuesOffset = dexFile.getBuffer().readSmallUint(classDefOffset + ClassDefItem.STATIC_VALUES_OFFSET);
final int fieldsStartOffset = reader.getOffset();
Iterator<Integer> hiddenApiRestrictionIterator = hiddenApiRestrictionsReader == null ? null : hiddenApiRestrictionsReader.getRestrictionsForStaticFields();
return new Iterable<DexBackedField>() {
@Nonnull
@Override
public Iterator<DexBackedField> iterator() {
final AnnotationsDirectory.AnnotationIterator annotationIterator = annotationsDirectory.getFieldAnnotationIterator();
final EncodedArrayItemIterator staticInitialValueIterator = EncodedArrayItemIterator.newOrEmpty(dexFile, staticInitialValuesOffset);
return new VariableSizeLookaheadIterator<DexBackedField>(dexFile.getDataBuffer(), fieldsStartOffset) {
private int count;
@Nullable
private FieldReference previousField;
private int previousIndex;
@Nullable
@Override
protected DexBackedField readNextItem(@Nonnull DexReader reader) {
while (true) {
if (++count > staticFieldCount) {
instanceFieldsOffset = reader.getOffset();
return endOfData();
}
int hiddenApiRestrictions = NO_HIDDEN_API_RESTRICTIONS;
if (hiddenApiRestrictionIterator != null) {
hiddenApiRestrictions = hiddenApiRestrictionIterator.next();
}
DexBackedField item = new DexBackedField(dexFile, reader, DexBackedClassDef.this, previousIndex, staticInitialValueIterator, annotationIterator, hiddenApiRestrictions);
FieldReference currentField = previousField;
FieldReference nextField = ImmutableFieldReference.of(item);
previousField = nextField;
previousIndex = item.fieldIndex;
if (skipDuplicates && currentField != null && currentField.equals(nextField)) {
continue;
}
return item;
}
}
};
}
};
} else {
instanceFieldsOffset = staticFieldsOffset;
return ImmutableSet.of();
}
}
use of org.jf.dexlib2.dexbacked.util.VariableSizeLookaheadIterator in project smali by JesusFreke.
the class DexBackedClassDef method getVirtualMethods.
@Nonnull
public Iterable<? extends DexBackedMethod> getVirtualMethods(final boolean skipDuplicates) {
if (virtualMethodCount > 0) {
DexReader reader = dexFile.getDataBuffer().readerAt(getVirtualMethodsOffset());
final AnnotationsDirectory annotationsDirectory = getAnnotationsDirectory();
final int methodsStartOffset = reader.getOffset();
Iterator<Integer> hiddenApiRestrictionIterator = hiddenApiRestrictionsReader == null ? null : hiddenApiRestrictionsReader.getRestrictionsForVirtualMethods();
return new Iterable<DexBackedMethod>() {
final AnnotationsDirectory.AnnotationIterator methodAnnotationIterator = annotationsDirectory.getMethodAnnotationIterator();
final AnnotationsDirectory.AnnotationIterator parameterAnnotationIterator = annotationsDirectory.getParameterAnnotationIterator();
@Nonnull
@Override
public Iterator<DexBackedMethod> iterator() {
return new VariableSizeLookaheadIterator<DexBackedMethod>(dexFile.getDataBuffer(), methodsStartOffset) {
private int count;
@Nullable
private MethodReference previousMethod;
private int previousIndex;
@Nullable
@Override
protected DexBackedMethod readNextItem(@Nonnull DexReader reader) {
while (true) {
if (++count > virtualMethodCount) {
return endOfData();
}
int hiddenApiRestrictions = NO_HIDDEN_API_RESTRICTIONS;
if (hiddenApiRestrictionIterator != null) {
hiddenApiRestrictions = hiddenApiRestrictionIterator.next();
}
DexBackedMethod item = new DexBackedMethod(dexFile, reader, DexBackedClassDef.this, previousIndex, methodAnnotationIterator, parameterAnnotationIterator, hiddenApiRestrictions);
MethodReference currentMethod = previousMethod;
MethodReference nextMethod = ImmutableMethodReference.of(item);
previousMethod = nextMethod;
previousIndex = item.methodIndex;
if (skipDuplicates && currentMethod != null && currentMethod.equals(nextMethod)) {
continue;
}
return item;
}
}
};
}
};
} else {
return ImmutableSet.of();
}
}
use of org.jf.dexlib2.dexbacked.util.VariableSizeLookaheadIterator in project smali by JesusFreke.
the class DexBackedClassDef method getInstanceFields.
@Nonnull
public Iterable<? extends DexBackedField> getInstanceFields(final boolean skipDuplicates) {
if (instanceFieldCount > 0) {
DexReader reader = dexFile.getDataBuffer().readerAt(getInstanceFieldsOffset());
final AnnotationsDirectory annotationsDirectory = getAnnotationsDirectory();
final int fieldsStartOffset = reader.getOffset();
Iterator<Integer> hiddenApiRestrictionIterator = hiddenApiRestrictionsReader == null ? null : hiddenApiRestrictionsReader.getRestrictionsForInstanceFields();
return new Iterable<DexBackedField>() {
@Nonnull
@Override
public Iterator<DexBackedField> iterator() {
final AnnotationsDirectory.AnnotationIterator annotationIterator = annotationsDirectory.getFieldAnnotationIterator();
return new VariableSizeLookaheadIterator<DexBackedField>(dexFile.getDataBuffer(), fieldsStartOffset) {
private int count;
@Nullable
private FieldReference previousField;
private int previousIndex;
@Nullable
@Override
protected DexBackedField readNextItem(@Nonnull DexReader reader) {
while (true) {
if (++count > instanceFieldCount) {
directMethodsOffset = reader.getOffset();
return endOfData();
}
int hiddenApiRestrictions = NO_HIDDEN_API_RESTRICTIONS;
if (hiddenApiRestrictionIterator != null) {
hiddenApiRestrictions = hiddenApiRestrictionIterator.next();
}
DexBackedField item = new DexBackedField(dexFile, reader, DexBackedClassDef.this, previousIndex, annotationIterator, hiddenApiRestrictions);
FieldReference currentField = previousField;
FieldReference nextField = ImmutableFieldReference.of(item);
previousField = nextField;
previousIndex = item.fieldIndex;
if (skipDuplicates && currentField != null && currentField.equals(nextField)) {
continue;
}
return item;
}
}
};
}
};
} else {
if (instanceFieldsOffset > 0) {
directMethodsOffset = instanceFieldsOffset;
}
return ImmutableSet.of();
}
}
use of org.jf.dexlib2.dexbacked.util.VariableSizeLookaheadIterator in project smali by JesusFreke.
the class DexBackedMethodImplementation method getInstructions.
@Nonnull
@Override
public Iterable<? extends Instruction> getInstructions() {
// instructionsSize is the number of 16-bit code units in the instruction list, not the number of instructions
int instructionsSize = getInstructionsSize();
final int instructionsStartOffset = getInstructionsStartOffset();
final int endOffset = instructionsStartOffset + (instructionsSize * 2);
return new Iterable<Instruction>() {
@Override
public Iterator<Instruction> iterator() {
return new VariableSizeLookaheadIterator<Instruction>(dexFile.getDataBuffer(), instructionsStartOffset) {
@Override
protected Instruction readNextItem(@Nonnull DexReader reader) {
if (reader.getOffset() >= endOffset) {
return endOfData();
}
Instruction instruction = DexBackedInstruction.readFrom(dexFile, reader);
// Does the instruction extend past the end of the method?
int offset = reader.getOffset();
if (offset > endOffset || offset < 0) {
throw new ExceptionWithContext("The last instruction in method %s is truncated", method);
}
return instruction;
}
};
}
};
}
Aggregations