Search in sources :

Example 11 with ClassPath

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

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

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

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

the class MethodAnalyzer method analyzeMoveResult.

private void analyzeMoveResult(@Nonnull AnalyzedInstruction analyzedInstruction) {
    AnalyzedInstruction previousInstruction = null;
    if (analyzedInstruction.instructionIndex > 0) {
        previousInstruction = analyzedInstructions.valueAt(analyzedInstruction.instructionIndex - 1);
    }
    if (previousInstruction == null || !previousInstruction.instruction.getOpcode().setsResult()) {
        throw new AnalysisException(analyzedInstruction.instruction.getOpcode().name + " must occur after an " + "invoke-*/fill-new-array instruction");
    }
    RegisterType resultRegisterType;
    ReferenceInstruction invokeInstruction = (ReferenceInstruction) previousInstruction.instruction;
    Reference reference = invokeInstruction.getReference();
    if (reference instanceof MethodReference) {
        resultRegisterType = RegisterType.getRegisterType(classPath, ((MethodReference) reference).getReturnType());
    } else {
        resultRegisterType = RegisterType.getRegisterType(classPath, (TypeReference) reference);
    }
    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, resultRegisterType);
}
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) BaseMethodReference(org.jf.dexlib2.base.reference.BaseMethodReference) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) MethodReference(org.jf.dexlib2.iface.reference.MethodReference) TypeReference(org.jf.dexlib2.iface.reference.TypeReference)

Example 15 with ClassPath

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

the class AnalysisTest method runTest.

public void runTest(String test, boolean registerInfo, boolean isArt) throws IOException, URISyntaxException {
    String dexFilePath = String.format("%s%sclasses.dex", test, File.separatorChar);
    DexFile dexFile = DexFileFactory.loadDexFile(findResource(dexFilePath), Opcodes.getDefault());
    BaksmaliOptions options = new BaksmaliOptions();
    if (registerInfo) {
        options.registerInfo = BaksmaliOptions.ALL | BaksmaliOptions.FULLMERGE;
        if (isArt) {
            options.classPath = new ClassPath(new ArrayList<ClassProvider>(), true, 56);
        } else {
            options.classPath = new ClassPath();
        }
    }
    options.implicitReferences = false;
    for (ClassDef classDef : dexFile.getClasses()) {
        StringWriter stringWriter = new StringWriter();
        IndentingWriter writer = new IndentingWriter(stringWriter);
        ClassDefinition classDefinition = new ClassDefinition(options, classDef);
        classDefinition.writeTo(writer);
        writer.close();
        String className = classDef.getType();
        String smaliPath = String.format("%s%s%s.smali", test, File.separatorChar, className.substring(1, className.length() - 1));
        String smaliContents = readResource(smaliPath);
        Assert.assertEquals(TextUtils.normalizeWhitespace(smaliContents), TextUtils.normalizeWhitespace((stringWriter.toString())));
    }
}
Also used : ClassPath(org.jf.dexlib2.analysis.ClassPath) ClassDef(org.jf.dexlib2.iface.ClassDef) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) IndentingWriter(org.jf.util.IndentingWriter) ClassDefinition(org.jf.baksmali.Adaptors.ClassDefinition) DexFile(org.jf.dexlib2.iface.DexFile)

Aggregations

DexFile (org.jf.dexlib2.iface.DexFile)14 ClassDef (org.jf.dexlib2.iface.ClassDef)13 Test (org.junit.Test)13 ImmutableDexFile (org.jf.dexlib2.immutable.ImmutableDexFile)11 ImmutableClassDef (org.jf.dexlib2.immutable.ImmutableClassDef)9 ImmutableMethod (org.jf.dexlib2.immutable.ImmutableMethod)9 ClassPath (org.jf.dexlib2.analysis.ClassPath)6 MethodImplementationBuilder (org.jf.dexlib2.builder.MethodImplementationBuilder)6 BuilderInstruction10x (org.jf.dexlib2.builder.instruction.BuilderInstruction10x)6 BuilderInstruction21t (org.jf.dexlib2.builder.instruction.BuilderInstruction21t)6 BuilderInstruction22c (org.jf.dexlib2.builder.instruction.BuilderInstruction22c)6 Method (org.jf.dexlib2.iface.Method)6 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)6 ImmutableMethodParameter (org.jf.dexlib2.immutable.ImmutableMethodParameter)6 ImmutableTypeReference (org.jf.dexlib2.immutable.reference.ImmutableTypeReference)6 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)5 TypeReference (org.jf.dexlib2.iface.reference.TypeReference)5 DexClassProvider (org.jf.dexlib2.analysis.DexClassProvider)4 Instruction (org.jf.dexlib2.iface.instruction.Instruction)3 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)3