Search in sources :

Example 6 with TypeCompare

use of jadx.core.dex.visitors.typeinference.TypeCompare 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

ArgType (jadx.core.dex.instructions.args.ArgType)6 TypeCompare (jadx.core.dex.visitors.typeinference.TypeCompare)6 TypeCompareEnum (jadx.core.dex.visitors.typeinference.TypeCompareEnum)5 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)2 CodeVar (jadx.core.dex.instructions.args.CodeVar)1 TryCatchBlockAttr (jadx.core.dex.trycatch.TryCatchBlockAttr)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1