Search in sources :

Example 6 with RegisterType

use of org.jf.dexlib2.analysis.RegisterType 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 7 with RegisterType

use of org.jf.dexlib2.analysis.RegisterType 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 8 with RegisterType

use of org.jf.dexlib2.analysis.RegisterType 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 9 with RegisterType

use of org.jf.dexlib2.analysis.RegisterType in project atlas by alibaba.

the class PreInstructionRegisterInfoMethodItem method writeFullMerge.

private void writeFullMerge(IndentingWriter writer, int registerNum) throws IOException {
    registerFormatter.writeTo(writer, registerNum);
    writer.write('=');
    analyzedInstruction.getPreInstructionRegisterType(registerNum).writeTo(writer);
    writer.write(":merge{");
    boolean first = true;
    for (AnalyzedInstruction predecessor : analyzedInstruction.getPredecessors()) {
        RegisterType predecessorRegisterType = predecessor.getPostInstructionRegisterType(registerNum);
        if (!first) {
            writer.write(',');
        }
        if (predecessor.getInstructionIndex() == -1) {
            //the fake "StartOfMethod" instruction
            writer.write("Start:");
        } else {
            writer.write("0x");
            writer.printUnsignedLongAsHex(methodAnalyzer.getInstructionAddress(predecessor));
            writer.write(':');
        }
        predecessorRegisterType.writeTo(writer);
        first = false;
    }
    writer.write('}');
}
Also used : RegisterType(org.jf.dexlib2.analysis.RegisterType) AnalyzedInstruction(org.jf.dexlib2.analysis.AnalyzedInstruction)

Example 10 with RegisterType

use of org.jf.dexlib2.analysis.RegisterType in project smali by JesusFreke.

the class MethodAnalyzer method analyzeIputIgetQuick.

private boolean analyzeIputIgetQuick(@Nonnull AnalyzedInstruction analyzedInstruction) {
    Instruction22cs instruction = (Instruction22cs) analyzedInstruction.instruction;
    int fieldOffset = instruction.getFieldOffset();
    RegisterType objectRegisterType = getAndCheckSourceRegister(analyzedInstruction, instruction.getRegisterB(), ReferenceOrUninitCategories);
    if (objectRegisterType.category == RegisterType.NULL) {
        return false;
    }
    TypeProto objectRegisterTypeProto = objectRegisterType.type;
    assert objectRegisterTypeProto != null;
    TypeProto classTypeProto = classPath.getClass(objectRegisterTypeProto.getType());
    FieldReference resolvedField = classTypeProto.getFieldByOffset(fieldOffset);
    if (resolvedField == null) {
        throw new AnalysisException("Could not resolve the field in class %s at offset %d", objectRegisterType.type.getType(), fieldOffset);
    }
    ClassDef thisClass = classPath.getClassDef(method.getDefiningClass());
    if (!TypeUtils.canAccessClass(thisClass.getType(), classPath.getClassDef(resolvedField.getDefiningClass()))) {
        // the class is not accessible. So we start looking at objectRegisterTypeProto (which may be different
        // than resolvedField.getDefiningClass()), and walk up the class hierarchy.
        ClassDef fieldClass = classPath.getClassDef(objectRegisterTypeProto.getType());
        while (!TypeUtils.canAccessClass(thisClass.getType(), fieldClass)) {
            String superclass = fieldClass.getSuperclass();
            if (superclass == null) {
                throw new ExceptionWithContext("Couldn't find accessible class while resolving field %s", ReferenceUtil.getShortFieldDescriptor(resolvedField));
            }
            fieldClass = classPath.getClassDef(superclass);
        }
        // fieldClass is now the first accessible class found. Now. we need to make sure that the field is
        // actually valid for this class
        FieldReference newResolvedField = classPath.getClass(fieldClass.getType()).getFieldByOffset(fieldOffset);
        if (newResolvedField == null) {
            throw new ExceptionWithContext("Couldn't find accessible class while resolving field %s", ReferenceUtil.getShortFieldDescriptor(resolvedField));
        }
        resolvedField = new ImmutableFieldReference(fieldClass.getType(), newResolvedField.getName(), newResolvedField.getType());
    }
    String fieldType = resolvedField.getType();
    Opcode opcode = classPath.getFieldInstructionMapper().getAndCheckDeodexedOpcode(fieldType, instruction.getOpcode());
    Instruction22c deodexedInstruction = new ImmutableInstruction22c(opcode, (byte) instruction.getRegisterA(), (byte) instruction.getRegisterB(), resolvedField);
    analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
    analyzeInstruction(analyzedInstruction);
    return true;
}
Also used : FieldReference(org.jf.dexlib2.iface.reference.FieldReference) ImmutableFieldReference(org.jf.dexlib2.immutable.reference.ImmutableFieldReference) ImmutableFieldReference(org.jf.dexlib2.immutable.reference.ImmutableFieldReference) Opcode(org.jf.dexlib2.Opcode) ExceptionWithContext(org.jf.util.ExceptionWithContext)

Aggregations

RegisterType (org.jf.dexlib2.analysis.RegisterType)7 TypeReference (org.jf.dexlib2.iface.reference.TypeReference)7 Opcode (org.jf.dexlib2.Opcode)4 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)4 ImmutableFieldReference (org.jf.dexlib2.immutable.reference.ImmutableFieldReference)4 AnalyzedInstruction (org.jf.dexlib2.analysis.AnalyzedInstruction)3 BaseMethodReference (org.jf.dexlib2.base.reference.BaseMethodReference)3 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)3 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)3 Instruction22c (org.jf.dexlib2.iface.instruction.formats.Instruction22c)2 Reference (org.jf.dexlib2.iface.reference.Reference)2 ExceptionWithContext (org.jf.util.ExceptionWithContext)2 JavaCodeFragment (com.intellij.psi.JavaCodeFragment)1 JavaRecursiveElementVisitor (com.intellij.psi.JavaRecursiveElementVisitor)1 PsiElement (com.intellij.psi.PsiElement)1 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)1 LazyValue (org.jf.smalidea.debugging.value.LazyValue)1 SmaliInstruction (org.jf.smalidea.psi.impl.SmaliInstruction)1 SmaliMethod (org.jf.smalidea.psi.impl.SmaliMethod)1