Search in sources :

Example 36 with Instruction

use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.

the class MethodAnalyzer method analyzeNewInstance.

private void analyzeNewInstance(@Nonnull AnalyzedInstruction analyzedInstruction) {
    ReferenceInstruction instruction = (ReferenceInstruction) analyzedInstruction.instruction;
    int register = ((OneRegisterInstruction) analyzedInstruction.instruction).getRegisterA();
    RegisterType destRegisterType = analyzedInstruction.getPostInstructionRegisterType(register);
    if (destRegisterType.category != RegisterType.UNKNOWN) {
        //successors and nothing else needs to be done.
        assert destRegisterType.category == RegisterType.UNINIT_REF;
        return;
    }
    TypeReference typeReference = (TypeReference) instruction.getReference();
    RegisterType classType = RegisterType.getRegisterType(classPath, typeReference);
    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, RegisterType.getRegisterType(RegisterType.UNINIT_REF, classType.type));
}
Also used : TypeReference(org.jf.dexlib2.iface.reference.TypeReference)

Example 37 with Instruction

use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.

the class MethodAnalyzer method canPropagateTypeAfterInstanceOf.

static boolean canPropagateTypeAfterInstanceOf(AnalyzedInstruction analyzedInstanceOfInstruction, AnalyzedInstruction analyzedIfInstruction, ClassPath classPath) {
    if (!classPath.isArt()) {
        return false;
    }
    Instruction ifInstruction = analyzedIfInstruction.instruction;
    if (((Instruction21t) ifInstruction).getRegisterA() == analyzedInstanceOfInstruction.getDestinationRegister()) {
        Reference reference = ((Instruction22c) analyzedInstanceOfInstruction.getInstruction()).getReference();
        RegisterType registerType = RegisterType.getRegisterType(classPath, (TypeReference) reference);
        try {
            if (registerType.type != null && !registerType.type.isInterface()) {
                int objectRegister = ((TwoRegisterInstruction) analyzedInstanceOfInstruction.getInstruction()).getRegisterB();
                RegisterType originalType = analyzedIfInstruction.getPreInstructionRegisterType(objectRegister);
                return isNotWideningConversion(originalType, registerType);
            }
        } catch (UnresolvedClassException ex) {
            return false;
        }
    }
    return false;
}
Also used : BaseMethodReference(org.jf.dexlib2.base.reference.BaseMethodReference) TypeReference(org.jf.dexlib2.iface.reference.TypeReference) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) Reference(org.jf.dexlib2.iface.reference.Reference) FieldReference(org.jf.dexlib2.iface.reference.FieldReference) ImmutableFieldReference(org.jf.dexlib2.immutable.reference.ImmutableFieldReference) MethodReference(org.jf.dexlib2.iface.reference.MethodReference)

Example 38 with Instruction

use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.

the class MethodAnalyzer method analyzeNewArray.

private void analyzeNewArray(@Nonnull AnalyzedInstruction analyzedInstruction) {
    ReferenceInstruction instruction = (ReferenceInstruction) analyzedInstruction.instruction;
    TypeReference type = (TypeReference) instruction.getReference();
    if (type.getType().charAt(0) != '[') {
        throw new AnalysisException("new-array used with non-array type");
    }
    RegisterType arrayType = RegisterType.getRegisterType(classPath, type);
    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, arrayType);
}
Also used : TypeReference(org.jf.dexlib2.iface.reference.TypeReference)

Example 39 with Instruction

use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.

the class MethodAnalyzer method analyzeCheckCast.

private void analyzeCheckCast(@Nonnull AnalyzedInstruction analyzedInstruction) {
    ReferenceInstruction instruction = (ReferenceInstruction) analyzedInstruction.instruction;
    TypeReference reference = (TypeReference) instruction.getReference();
    RegisterType castRegisterType = RegisterType.getRegisterType(classPath, reference);
    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, castRegisterType);
}
Also used : TypeReference(org.jf.dexlib2.iface.reference.TypeReference)

Example 40 with Instruction

use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.

the class MethodAnalyzer method analyzePutGetVolatile.

private boolean analyzePutGetVolatile(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult) {
    FieldReference field = (FieldReference) ((ReferenceInstruction) analyzedInstruction.instruction).getReference();
    String fieldType = field.getType();
    Opcode originalOpcode = analyzedInstruction.instruction.getOpcode();
    Opcode opcode = classPath.getFieldInstructionMapper().getAndCheckDeodexedOpcode(fieldType, originalOpcode);
    Instruction deodexedInstruction;
    if (originalOpcode.isStaticFieldAccessor()) {
        OneRegisterInstruction instruction = (OneRegisterInstruction) analyzedInstruction.instruction;
        deodexedInstruction = new ImmutableInstruction21c(opcode, instruction.getRegisterA(), field);
    } else {
        TwoRegisterInstruction instruction = (TwoRegisterInstruction) analyzedInstruction.instruction;
        deodexedInstruction = new ImmutableInstruction22c(opcode, instruction.getRegisterA(), instruction.getRegisterB(), field);
    }
    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    if (analyzeResult) {
        analyzeInstruction(analyzedInstruction);
    }
    return true;
}
Also used : FieldReference(org.jf.dexlib2.iface.reference.FieldReference) ImmutableFieldReference(org.jf.dexlib2.immutable.reference.ImmutableFieldReference) Opcode(org.jf.dexlib2.Opcode)

Aggregations

Instruction (org.jf.dexlib2.iface.instruction.Instruction)35 Test (org.junit.Test)20 Opcode (org.jf.dexlib2.Opcode)16 ReferenceInstruction (org.jf.dexlib2.iface.instruction.ReferenceInstruction)16 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)15 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)13 OffsetInstruction (org.jf.dexlib2.iface.instruction.OffsetInstruction)12 AnalyzedInstruction (org.jf.dexlib2.analysis.AnalyzedInstruction)11 ExceptionWithContext (org.jf.util.ExceptionWithContext)11 TypeReference (org.jf.dexlib2.iface.reference.TypeReference)10 Nonnull (javax.annotation.Nonnull)7 ClassDef (org.jf.dexlib2.iface.ClassDef)7 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)7 IOException (java.io.IOException)6 BuilderInstruction10x (org.jf.dexlib2.builder.instruction.BuilderInstruction10x)6 Reference (org.jf.dexlib2.iface.reference.Reference)6 ImmutableFieldReference (org.jf.dexlib2.immutable.reference.ImmutableFieldReference)5 BuilderInstruction10t (org.jf.dexlib2.builder.instruction.BuilderInstruction10t)4 InvalidItemIndex (org.jf.dexlib2.dexbacked.DexBackedDexFile.InvalidItemIndex)4 DexFile (org.jf.dexlib2.iface.DexFile)4