use of org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator 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.EncodedArrayItemIterator in project smali by JesusFreke.
the class DexBackedCallSiteReference method getMethodHandle.
@Nonnull
@Override
public MethodHandleReference getMethodHandle() {
EncodedArrayItemIterator iter = getCallSiteIterator();
if (iter.getItemCount() < 3) {
throw new ExceptionWithContext("Invalid call site item: must contain at least 3 entries.");
}
EncodedValue encodedValue = getCallSiteIterator().getNextOrNull();
assert encodedValue != null;
if (encodedValue.getValueType() != ValueType.METHOD_HANDLE) {
throw new ExceptionWithContext("Invalid encoded value type (%d) for the first item in call site %d", encodedValue.getValueType(), callSiteIndex);
}
return ((MethodHandleEncodedValue) encodedValue).getValue();
}
use of org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator in project smali by JesusFreke.
the class DexBackedCallSiteReference method getExtraArguments.
@Nonnull
@Override
public List<? extends EncodedValue> getExtraArguments() {
List<EncodedValue> values = Lists.newArrayList();
EncodedArrayItemIterator iter = getCallSiteIterator();
if (iter.getItemCount() < 3) {
throw new ExceptionWithContext("Invalid call site item: must contain at least 3 entries.");
}
if (iter.getItemCount() == 3) {
return values;
}
iter.skipNext();
iter.skipNext();
iter.skipNext();
EncodedValue item = iter.getNextOrNull();
while (item != null) {
values.add(item);
item = iter.getNextOrNull();
}
return values;
}
use of org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator in project smali by JesusFreke.
the class DexBackedCallSiteReference method getMethodName.
@Nonnull
@Override
public String getMethodName() {
EncodedArrayItemIterator iter = getCallSiteIterator();
if (iter.getItemCount() < 3) {
throw new ExceptionWithContext("Invalid call site item: must contain at least 3 entries.");
}
iter.skipNext();
EncodedValue encodedValue = iter.getNextOrNull();
assert encodedValue != null;
if (encodedValue.getValueType() != ValueType.STRING) {
throw new ExceptionWithContext("Invalid encoded value type (%d) for the second item in call site %d", encodedValue.getValueType(), callSiteIndex);
}
return ((StringEncodedValue) encodedValue).getValue();
}
use of org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator in project smali by JesusFreke.
the class DexBackedCallSiteReference method getMethodProto.
@Nonnull
@Override
public MethodProtoReference getMethodProto() {
EncodedArrayItemIterator iter = getCallSiteIterator();
if (iter.getItemCount() < 3) {
throw new ExceptionWithContext("Invalid call site item: must contain at least 3 entries.");
}
iter.skipNext();
iter.skipNext();
EncodedValue encodedValue = iter.getNextOrNull();
assert encodedValue != null;
if (encodedValue.getValueType() != ValueType.METHOD_TYPE) {
throw new ExceptionWithContext("Invalid encoded value type (%d) for the second item in call site %d", encodedValue.getValueType(), callSiteIndex);
}
return ((MethodTypeEncodedValue) encodedValue).getValue();
}
Aggregations