Search in sources :

Example 1 with BaseInvokeNode

use of jadx.core.dex.instructions.BaseInvokeNode in project jadx by skylot.

the class InlineMethods method updateUsageInfo.

private void updateUsageInfo(MethodNode mth, MethodNode inlinedMth, InsnNode insn) {
    inlinedMth.getUseIn().remove(mth);
    insn.visitInsns(innerInsn -> {
        // TODO: share code with UsageInfoVisitor
        switch(innerInsn.getType()) {
            case INVOKE:
            case CONSTRUCTOR:
                MethodInfo callMth = ((BaseInvokeNode) innerInsn).getCallMth();
                MethodNode callMthNode = mth.root().resolveMethod(callMth);
                if (callMthNode != null) {
                    callMthNode.setUseIn(ListUtils.safeReplace(callMthNode.getUseIn(), inlinedMth, mth));
                    replaceClsUsage(mth, inlinedMth, callMthNode.getParentClass());
                }
                break;
            case IGET:
            case IPUT:
            case SPUT:
            case SGET:
                FieldInfo fieldInfo = (FieldInfo) ((IndexInsnNode) innerInsn).getIndex();
                FieldNode fieldNode = mth.root().resolveField(fieldInfo);
                if (fieldNode != null) {
                    fieldNode.setUseIn(ListUtils.safeReplace(fieldNode.getUseIn(), inlinedMth, mth));
                    replaceClsUsage(mth, inlinedMth, fieldNode.getParentClass());
                }
                break;
        }
    });
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) FieldNode(jadx.core.dex.nodes.FieldNode) BaseInvokeNode(jadx.core.dex.instructions.BaseInvokeNode) MethodInfo(jadx.core.dex.info.MethodInfo) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 2 with BaseInvokeNode

use of jadx.core.dex.instructions.BaseInvokeNode in project jadx by skylot.

the class TypeUpdate method invokeListener.

private TypeUpdateResult invokeListener(TypeUpdateInfo updateInfo, InsnNode insn, InsnArg arg, ArgType candidateType) {
    BaseInvokeNode invoke = (BaseInvokeNode) insn;
    if (isAssign(invoke, arg)) {
        // TODO: implement backward type propagation (from result to instance)
        return SAME;
    }
    if (invoke.getInstanceArg() == arg) {
        IMethodDetails methodDetails = root.getMethodUtils().getMethodDetails(invoke);
        if (methodDetails == null) {
            return SAME;
        }
        TypeUtils typeUtils = root.getTypeUtils();
        Set<ArgType> knownTypeVars = typeUtils.getKnownTypeVarsAtMethod(updateInfo.getMth());
        Map<ArgType, ArgType> typeVarsMap = typeUtils.getTypeVariablesMapping(candidateType);
        ArgType returnType = methodDetails.getReturnType();
        List<ArgType> argTypes = methodDetails.getArgTypes();
        int argsCount = argTypes.size();
        if (typeVarsMap.isEmpty()) {
            // generics can't be resolved => use as is
            return applyInvokeTypes(updateInfo, invoke, argsCount, knownTypeVars, () -> returnType, argTypes::get);
        }
        // resolve types before apply
        return applyInvokeTypes(updateInfo, invoke, argsCount, knownTypeVars, () -> typeUtils.replaceTypeVariablesUsingMap(returnType, typeVarsMap), argNum -> typeUtils.replaceClassGenerics(candidateType, argTypes.get(argNum)));
    }
    return SAME;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) BaseInvokeNode(jadx.core.dex.instructions.BaseInvokeNode) TypeUtils(jadx.core.dex.nodes.utils.TypeUtils) IMethodDetails(jadx.core.dex.nodes.IMethodDetails)

Example 3 with BaseInvokeNode

use of jadx.core.dex.instructions.BaseInvokeNode in project jadx by skylot.

the class ConstInlineVisitor method needExplicitCast.

private static boolean needExplicitCast(InsnNode insn, LiteralArg arg) {
    if (insn instanceof BaseInvokeNode) {
        BaseInvokeNode callInsn = (BaseInvokeNode) insn;
        MethodInfo callMth = callInsn.getCallMth();
        int offset = callInsn.getFirstArgOffset();
        int argIndex = insn.getArgIndex(arg);
        ArgType argType = callMth.getArgumentsTypes().get(argIndex - offset);
        if (argType.isPrimitive()) {
            arg.setType(argType);
            return argType.equals(ArgType.BYTE);
        }
    }
    return false;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) BaseInvokeNode(jadx.core.dex.instructions.BaseInvokeNode) MethodInfo(jadx.core.dex.info.MethodInfo)

Aggregations

BaseInvokeNode (jadx.core.dex.instructions.BaseInvokeNode)3 MethodInfo (jadx.core.dex.info.MethodInfo)2 ArgType (jadx.core.dex.instructions.args.ArgType)2 FieldInfo (jadx.core.dex.info.FieldInfo)1 FieldNode (jadx.core.dex.nodes.FieldNode)1 IMethodDetails (jadx.core.dex.nodes.IMethodDetails)1 MethodNode (jadx.core.dex.nodes.MethodNode)1 TypeUtils (jadx.core.dex.nodes.utils.TypeUtils)1