Search in sources :

Example 46 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class LoopRegionVisitor method fixIterableType.

private static boolean fixIterableType(MethodNode mth, InsnArg iterableArg, RegisterArg iterVar) {
    ArgType iterableType = iterableArg.getType();
    ArgType varType = iterVar.getType();
    if (iterableType.isGeneric()) {
        ArgType[] genericTypes = iterableType.getGenericTypes();
        if (genericTypes == null || genericTypes.length != 1) {
            return false;
        }
        ArgType gType = genericTypes[0];
        if (gType.equals(varType)) {
            return true;
        }
        if (gType.isGenericType()) {
            iterVar.setType(gType);
            return true;
        }
        if (ArgType.isInstanceOf(mth.dex(), gType, varType)) {
            return true;
        }
        ArgType wildcardType = gType.getWildcardType();
        if (wildcardType != null && gType.getWildcardBounds() == 1 && ArgType.isInstanceOf(mth.dex(), wildcardType, varType)) {
            return true;
        }
        LOG.warn("Generic type differs: '{}' and '{}' in {}", gType, varType, mth);
        return false;
    }
    if (!iterableArg.isRegister()) {
        return true;
    }
    // TODO: add checks
    iterableType = ArgType.generic(iterableType.getObject(), new ArgType[] { varType });
    iterableArg.setType(iterableType);
    return true;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType)

Example 47 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class TypeInference method visit.

@Override
public void visit(MethodNode mth) throws JadxException {
    if (mth.isNoCode()) {
        return;
    }
    DexNode dex = mth.dex();
    for (SSAVar var : mth.getSVars()) {
        // inference variable type
        ArgType type = processType(dex, var);
        if (type == null) {
            type = ArgType.UNKNOWN;
        }
        var.setType(type);
        // search variable name
        String name = processVarName(var);
        var.setName(name);
    }
    // fix type for vars used only in Phi nodes
    for (SSAVar sVar : mth.getSVars()) {
        PhiInsn phi = sVar.getUsedInPhi();
        if (phi != null) {
            processPhiNode(phi);
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) SSAVar(jadx.core.dex.instructions.args.SSAVar) PhiInsn(jadx.core.dex.instructions.PhiInsn) DexNode(jadx.core.dex.nodes.DexNode)

Example 48 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class TypeInference method processPhiNode.

private static void processPhiNode(PhiInsn phi) {
    ArgType type = phi.getResult().getType();
    if (!type.isTypeKnown()) {
        for (InsnArg arg : phi.getArguments()) {
            if (arg.getType().isTypeKnown()) {
                type = arg.getType();
                break;
            }
        }
    }
    phi.getResult().setType(type);
    for (int i = 0; i < phi.getArgsCount(); i++) {
        RegisterArg arg = phi.getArg(i);
        arg.setType(type);
        SSAVar sVar = arg.getSVar();
        if (sVar != null) {
            sVar.setName(phi.getResult().getName());
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar) InsnArg(jadx.core.dex.instructions.args.InsnArg)

Aggregations

ArgType (jadx.core.dex.instructions.args.ArgType)48 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)12 InsnNode (jadx.core.dex.nodes.InsnNode)11 InsnArg (jadx.core.dex.instructions.args.InsnArg)9 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)8 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)6 SSAVar (jadx.core.dex.instructions.args.SSAVar)6 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)5 ArrayList (java.util.ArrayList)5 FieldNode (jadx.core.dex.nodes.FieldNode)4 MethodNode (jadx.core.dex.nodes.MethodNode)4 Annotation (jadx.core.dex.attributes.annotations.Annotation)3 FieldInfo (jadx.core.dex.info.FieldInfo)3 FilledNewArrayNode (jadx.core.dex.instructions.FilledNewArrayNode)3 InvokeNode (jadx.core.dex.instructions.InvokeNode)3 BlockNode (jadx.core.dex.nodes.BlockNode)3 ClassNode (jadx.core.dex.nodes.ClassNode)3 DexNode (jadx.core.dex.nodes.DexNode)3 List (java.util.List)3 MethodInfo (jadx.core.dex.info.MethodInfo)2