Search in sources :

Example 6 with TypeCompareEnum

use of jadx.core.dex.visitors.typeinference.TypeCompareEnum in project jadx by skylot.

the class OverrideMethodVisitor method updateArgType.

private ArgType updateArgType(MethodNode mth, IMethodDetails baseMth, SuperTypesData superData, int argNum) {
    ArgType arg = mth.getArgTypes().get(argNum);
    ArgType baseArg = baseMth.getArgTypes().get(argNum);
    if (arg.equals(baseArg)) {
        return null;
    }
    if (!baseArg.containsTypeVariable()) {
        return null;
    }
    TypeCompare typeCompare = mth.root().getTypeUpdate().getTypeCompare();
    ArgType baseCls = baseMth.getMethodInfo().getDeclClass().getType();
    for (ArgType superType : superData.getSuperTypes()) {
        TypeCompareEnum compareResult = typeCompare.compareTypes(superType, baseCls);
        if (compareResult == TypeCompareEnum.NARROW_BY_GENERIC) {
            ArgType targetArgType = mth.root().getTypeUtils().replaceClassGenerics(superType, baseArg);
            if (targetArgType != null && !targetArgType.containsTypeVariable() && !targetArgType.equals(arg)) {
                return targetArgType;
            }
        }
    }
    return null;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) TypeCompare(jadx.core.dex.visitors.typeinference.TypeCompare) TypeCompareEnum(jadx.core.dex.visitors.typeinference.TypeCompareEnum)

Example 7 with TypeCompareEnum

use of jadx.core.dex.visitors.typeinference.TypeCompareEnum in project jadx by skylot.

the class AttachTryCatchVisitor method checkAndFilterHandlers.

private static void checkAndFilterHandlers(MethodNode mth, List<ExceptionHandler> list) {
    if (list.size() <= 1) {
        return;
    }
    // Remove shadowed handlers (with same or narrow type compared to previous)
    TypeCompare typeCompare = mth.root().getTypeCompare();
    Iterator<ExceptionHandler> it = list.iterator();
    ArgType maxType = null;
    while (it.hasNext()) {
        ExceptionHandler handler = it.next();
        ArgType maxCatch = maxCatchFromHandler(handler, typeCompare);
        if (maxType == null) {
            maxType = maxCatch;
        } else {
            TypeCompareEnum result = typeCompare.compareObjects(maxType, maxCatch);
            if (result.isWiderOrEqual()) {
                if (Consts.DEBUG_EXC_HANDLERS) {
                    LOG.debug("Removed shadowed catch handler: {}, from list: {}", handler, list);
                }
                it.remove();
            }
        }
    }
}
Also used : ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler) ArgType(jadx.core.dex.instructions.args.ArgType) TypeCompare(jadx.core.dex.visitors.typeinference.TypeCompare) TypeCompareEnum(jadx.core.dex.visitors.typeinference.TypeCompareEnum)

Example 8 with TypeCompareEnum

use of jadx.core.dex.visitors.typeinference.TypeCompareEnum in project jadx by skylot.

the class ProcessVariables method checkCodeVars.

private void checkCodeVars(MethodNode mth, List<CodeVar> codeVars) {
    int unknownTypesCount = 0;
    for (CodeVar codeVar : codeVars) {
        ArgType codeVarType = codeVar.getType();
        if (codeVarType == null) {
            codeVar.setType(ArgType.UNKNOWN);
            unknownTypesCount++;
        } else {
            codeVar.getSsaVars().forEach(ssaVar -> {
                ArgType ssaType = ssaVar.getImmutableType();
                if (ssaType != null && ssaType.isTypeKnown()) {
                    TypeCompare comparator = mth.root().getTypeUpdate().getTypeCompare();
                    TypeCompareEnum result = comparator.compareTypes(ssaType, codeVarType);
                    if (result == TypeCompareEnum.CONFLICT || result.isNarrow()) {
                        mth.addWarn("Incorrect type for immutable var: ssa=" + ssaType + ", code=" + codeVarType + ", for " + ssaVar.getDetailedVarInfo(mth));
                    }
                }
            });
        }
    }
    if (unknownTypesCount != 0) {
        mth.addWarn("Unknown variable types count: " + unknownTypesCount);
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) CodeVar(jadx.core.dex.instructions.args.CodeVar) TypeCompare(jadx.core.dex.visitors.typeinference.TypeCompare) TypeCompareEnum(jadx.core.dex.visitors.typeinference.TypeCompareEnum)

Aggregations

TypeCompareEnum (jadx.core.dex.visitors.typeinference.TypeCompareEnum)8 ArgType (jadx.core.dex.instructions.args.ArgType)7 TypeCompare (jadx.core.dex.visitors.typeinference.TypeCompare)5 AccessInfo (jadx.core.dex.info.AccessInfo)1 FieldInfo (jadx.core.dex.info.FieldInfo)1 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)1 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 CodeVar (jadx.core.dex.instructions.args.CodeVar)1 InsnArg (jadx.core.dex.instructions.args.InsnArg)1 ClassNode (jadx.core.dex.nodes.ClassNode)1 FieldNode (jadx.core.dex.nodes.FieldNode)1 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)1