Search in sources :

Example 1 with EncodedArrayItemIterator

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();
    }
}
Also used : ImmutableFieldReference(org.jf.dexlib2.immutable.reference.ImmutableFieldReference) FieldReference(org.jf.dexlib2.iface.reference.FieldReference) Nonnull(javax.annotation.Nonnull) AnnotationsDirectory(org.jf.dexlib2.dexbacked.util.AnnotationsDirectory) VariableSizeLookaheadIterator(org.jf.dexlib2.dexbacked.util.VariableSizeLookaheadIterator) EncodedArrayItemIterator(org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator) Nonnull(javax.annotation.Nonnull)

Example 2 with EncodedArrayItemIterator

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();
}
Also used : MethodHandleEncodedValue(org.jf.dexlib2.iface.value.MethodHandleEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) MethodTypeEncodedValue(org.jf.dexlib2.iface.value.MethodTypeEncodedValue) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) MethodHandleEncodedValue(org.jf.dexlib2.iface.value.MethodHandleEncodedValue) ExceptionWithContext(org.jf.util.ExceptionWithContext) EncodedArrayItemIterator(org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator) Nonnull(javax.annotation.Nonnull)

Example 3 with EncodedArrayItemIterator

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;
}
Also used : EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) MethodTypeEncodedValue(org.jf.dexlib2.iface.value.MethodTypeEncodedValue) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) MethodHandleEncodedValue(org.jf.dexlib2.iface.value.MethodHandleEncodedValue) ExceptionWithContext(org.jf.util.ExceptionWithContext) EncodedArrayItemIterator(org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator) Nonnull(javax.annotation.Nonnull)

Example 4 with EncodedArrayItemIterator

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();
}
Also used : EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) MethodTypeEncodedValue(org.jf.dexlib2.iface.value.MethodTypeEncodedValue) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) MethodHandleEncodedValue(org.jf.dexlib2.iface.value.MethodHandleEncodedValue) ExceptionWithContext(org.jf.util.ExceptionWithContext) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) EncodedArrayItemIterator(org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator) Nonnull(javax.annotation.Nonnull)

Example 5 with EncodedArrayItemIterator

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();
}
Also used : EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) MethodTypeEncodedValue(org.jf.dexlib2.iface.value.MethodTypeEncodedValue) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) MethodHandleEncodedValue(org.jf.dexlib2.iface.value.MethodHandleEncodedValue) ExceptionWithContext(org.jf.util.ExceptionWithContext) MethodTypeEncodedValue(org.jf.dexlib2.iface.value.MethodTypeEncodedValue) EncodedArrayItemIterator(org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)5 EncodedArrayItemIterator (org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator)5 EncodedValue (org.jf.dexlib2.iface.value.EncodedValue)4 MethodHandleEncodedValue (org.jf.dexlib2.iface.value.MethodHandleEncodedValue)4 MethodTypeEncodedValue (org.jf.dexlib2.iface.value.MethodTypeEncodedValue)4 StringEncodedValue (org.jf.dexlib2.iface.value.StringEncodedValue)4 ExceptionWithContext (org.jf.util.ExceptionWithContext)4 AnnotationsDirectory (org.jf.dexlib2.dexbacked.util.AnnotationsDirectory)1 VariableSizeLookaheadIterator (org.jf.dexlib2.dexbacked.util.VariableSizeLookaheadIterator)1 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)1 ImmutableFieldReference (org.jf.dexlib2.immutable.reference.ImmutableFieldReference)1