Search in sources :

Example 11 with DexReader

use of org.jf.dexlib2.dexbacked.DexReader in project smali by JesusFreke.

the class DexBackedInstruction method readFrom.

@Nonnull
public static Instruction readFrom(@Nonnull DexReader reader) {
    int opcodeValue = reader.peekUbyte();
    if (opcodeValue == 0) {
        opcodeValue = reader.peekUshort();
    }
    Opcode opcode = reader.dexBuf.getOpcodes().getOpcodeByValue(opcodeValue);
    Instruction instruction = buildInstruction(reader.dexBuf, opcode, reader.getOffset());
    reader.moveRelative(instruction.getCodeUnits() * 2);
    return instruction;
}
Also used : Opcode(org.jf.dexlib2.Opcode) Instruction(org.jf.dexlib2.iface.instruction.Instruction) Nonnull(javax.annotation.Nonnull)

Example 12 with DexReader

use of org.jf.dexlib2.dexbacked.DexReader in project android-classyshark by google.

the class DexReader method main.

public static void main(String[] args) {
    DexReader dxr = new DexReader(new File("//Users//bfarber//Desktop//classes.dex"));
    dxr.read();
    System.out.println(dxr.getClassNames());
}
Also used : DexFile(org.jf.dexlib2.iface.DexFile) File(java.io.File)

Example 13 with DexReader

use of org.jf.dexlib2.dexbacked.DexReader in project smali by JesusFreke.

the class DexBackedInstruction method readFrom.

@Nonnull
public static Instruction readFrom(DexBackedDexFile dexFile, @Nonnull DexReader reader) {
    int opcodeValue = reader.peekUbyte();
    if (opcodeValue == 0) {
        opcodeValue = reader.peekUshort();
    }
    Opcode opcode = dexFile.getOpcodes().getOpcodeByValue(opcodeValue);
    Instruction instruction = buildInstruction(dexFile, opcode, reader.getOffset() + reader.dexBuf.getBaseOffset() - dexFile.getBuffer().getBaseOffset() - dexFile.getBaseDataOffset());
    reader.moveRelative(instruction.getCodeUnits() * 2);
    return instruction;
}
Also used : Opcode(org.jf.dexlib2.Opcode) Instruction(org.jf.dexlib2.iface.instruction.Instruction) Nonnull(javax.annotation.Nonnull)

Example 14 with DexReader

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

Example 15 with DexReader

use of org.jf.dexlib2.dexbacked.DexReader in project smali by JesusFreke.

the class DexBackedMethod method getSize.

/**
 * Calculate and return the private size of a method definition.
 *
 * Calculated as: method_idx_diff + access_flags + code_off +
 * implementation size + reference size
 *
 * @return size in bytes
 */
public int getSize() {
    int size = 0;
    DexReader reader = dexFile.getDataBuffer().readerAt(startOffset);
    // method_idx_diff
    reader.readLargeUleb128();
    // access_flags
    reader.readSmallUleb128();
    // code_off
    reader.readSmallUleb128();
    size += reader.getOffset() - startOffset;
    DexBackedMethodImplementation impl = getImplementation();
    if (impl != null) {
        size += impl.getSize();
    }
    DexBackedMethodReference methodRef = new DexBackedMethodReference(dexFile, methodIndex);
    size += methodRef.getSize();
    return size;
}
Also used : DexBackedMethodReference(org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference)

Aggregations

Nonnull (javax.annotation.Nonnull)15 DexReader (org.jf.dexlib2.dexbacked.DexReader)9 Nullable (javax.annotation.Nullable)7 AnnotatedBytes (org.jf.dexlib2.util.AnnotatedBytes)7 AnnotationsDirectory (org.jf.dexlib2.dexbacked.util.AnnotationsDirectory)5 VariableSizeLookaheadIterator (org.jf.dexlib2.dexbacked.util.VariableSizeLookaheadIterator)5 Instruction (org.jf.dexlib2.iface.instruction.Instruction)3 Opcode (org.jf.dexlib2.Opcode)2 DexBackedInstruction (org.jf.dexlib2.dexbacked.instruction.DexBackedInstruction)2 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)2 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)2 ImmutableFieldReference (org.jf.dexlib2.immutable.reference.ImmutableFieldReference)2 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)2 ExceptionWithContext (org.jf.util.ExceptionWithContext)2 File (java.io.File)1 CDexBackedDexFile (org.jf.dexlib2.dexbacked.CDexBackedDexFile)1 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)1 DexBackedFieldReference (org.jf.dexlib2.dexbacked.reference.DexBackedFieldReference)1 DexBackedMethodReference (org.jf.dexlib2.dexbacked.reference.DexBackedMethodReference)1 EncodedArrayItemIterator (org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator)1