Search in sources :

Example 1 with InvokeType

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

the class InsnGen method makeInvoke.

private void makeInvoke(InvokeNode insn, CodeWriter code) throws CodegenException {
    MethodInfo callMth = insn.getCallMth();
    // inline method
    MethodNode callMthNode = mth.dex().deepResolveMethod(callMth);
    if (callMthNode != null) {
        if (inlineMethod(callMthNode, insn, code)) {
            return;
        }
        callMth = callMthNode.getMethodInfo();
    }
    int k = 0;
    InvokeType type = insn.getInvokeType();
    switch(type) {
        case DIRECT:
        case VIRTUAL:
        case INTERFACE:
            InsnArg arg = insn.getArg(0);
            // FIXME: add 'this' for equals methods in scope
            if (!arg.isThis()) {
                addArgDot(code, arg);
            }
            k++;
            break;
        case SUPER:
            // use 'super' instead 'this' in 0 arg
            code.add("super").add('.');
            k++;
            break;
        case STATIC:
            ClassInfo insnCls = mth.getParentClass().getAlias();
            ClassInfo declClass = callMth.getDeclClass();
            if (!insnCls.equals(declClass)) {
                useClass(code, declClass);
                code.add('.');
            }
            break;
    }
    if (callMthNode != null) {
        code.attachAnnotation(callMthNode);
    }
    code.add(callMth.getAlias());
    generateMethodArguments(code, insn, k, callMthNode);
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InvokeType(jadx.core.dex.instructions.InvokeType) MethodInfo(jadx.core.dex.info.MethodInfo) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 2 with InvokeType

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

the class CustomLambdaCall method buildInvokeNode.

@NotNull
private static InvokeNode buildInvokeNode(MethodHandleType methodHandleType, InvokeCustomNode invokeCustomNode, MethodInfo callMthInfo) {
    InvokeType invokeType = convertInvokeType(methodHandleType);
    int callArgsCount = callMthInfo.getArgsCount();
    boolean instanceCall = invokeType != InvokeType.STATIC;
    if (instanceCall) {
        callArgsCount++;
    }
    InvokeNode invokeNode = new InvokeNode(callMthInfo, invokeType, callArgsCount);
    // copy insn args
    int argsCount = invokeCustomNode.getArgsCount();
    for (int i = 0; i < argsCount; i++) {
        InsnArg arg = invokeCustomNode.getArg(i);
        invokeNode.addArg(arg.duplicate());
    }
    if (callArgsCount > argsCount) {
        // fill remaining args with NamedArg
        int callArgNum = argsCount;
        if (instanceCall) {
            // start from instance type
            callArgNum--;
        }
        List<ArgType> callArgTypes = callMthInfo.getArgumentsTypes();
        for (int i = argsCount; i < callArgsCount; i++) {
            ArgType argType;
            if (callArgNum < 0) {
                // instance arg type
                argType = callMthInfo.getDeclClass().getType();
            } else {
                argType = callArgTypes.get(callArgNum++);
            }
            invokeNode.addArg(new NamedArg("v" + i, argType));
        }
    }
    return invokeNode;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) InsnArg(jadx.core.dex.instructions.args.InsnArg) InvokeType(jadx.core.dex.instructions.InvokeType) InvokeNode(jadx.core.dex.instructions.InvokeNode) NamedArg(jadx.core.dex.instructions.args.NamedArg) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with InvokeType

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

the class InsnGen method makeInvoke.

private void makeInvoke(InvokeNode insn, ICodeWriter code) throws CodegenException {
    InvokeType type = insn.getInvokeType();
    if (type == InvokeType.CUSTOM) {
        makeInvokeLambda(code, (InvokeCustomNode) insn);
        return;
    }
    MethodInfo callMth = insn.getCallMth();
    MethodNode callMthNode = mth.root().resolveMethod(callMth);
    int k = 0;
    switch(type) {
        case DIRECT:
        case VIRTUAL:
        case INTERFACE:
            InsnArg arg = insn.getArg(0);
            if (needInvokeArg(arg)) {
                addArgDot(code, arg);
            }
            k++;
            break;
        case SUPER:
            ClassInfo superCallCls = getClassForSuperCall(code, callMth);
            if (superCallCls != null) {
                useClass(code, superCallCls);
                code.add('.');
            }
            // use 'super' instead 'this' in 0 arg
            code.add("super").add('.');
            k++;
            break;
        case STATIC:
            ClassInfo insnCls = mth.getParentClass().getClassInfo();
            ClassInfo declClass = callMth.getDeclClass();
            if (!insnCls.equals(declClass)) {
                useClass(code, declClass);
                code.add('.');
            }
            break;
    }
    if (callMthNode != null) {
        code.attachAnnotation(callMthNode);
        code.add(callMthNode.getAlias());
    } else {
        code.add(callMth.getAlias());
    }
    generateMethodArguments(code, insn, k, callMthNode);
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InvokeType(jadx.core.dex.instructions.InvokeType) MethodInfo(jadx.core.dex.info.MethodInfo) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 4 with InvokeType

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

the class TypeInferenceVisitor method makeAssignInvokeBound.

private ITypeBound makeAssignInvokeBound(InvokeNode invokeNode) {
    ArgType boundType = invokeNode.getCallMth().getReturnType();
    ArgType genericReturnType = root.getMethodUtils().getMethodGenericReturnType(invokeNode);
    if (genericReturnType != null) {
        if (genericReturnType.containsTypeVariable()) {
            InvokeType invokeType = invokeNode.getInvokeType();
            if (invokeNode.getArgsCount() != 0 && invokeType != InvokeType.STATIC && invokeType != InvokeType.SUPER) {
                return new TypeBoundInvokeAssign(root, invokeNode, genericReturnType);
            }
        } else {
            boundType = genericReturnType;
        }
    }
    return new TypeBoundConst(BoundEnum.ASSIGN, boundType);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) InvokeType(jadx.core.dex.instructions.InvokeType)

Aggregations

InvokeType (jadx.core.dex.instructions.InvokeType)4 InsnArg (jadx.core.dex.instructions.args.InsnArg)3 ClassInfo (jadx.core.dex.info.ClassInfo)2 MethodInfo (jadx.core.dex.info.MethodInfo)2 ArgType (jadx.core.dex.instructions.args.ArgType)2 MethodNode (jadx.core.dex.nodes.MethodNode)2 InvokeNode (jadx.core.dex.instructions.InvokeNode)1 NamedArg (jadx.core.dex.instructions.args.NamedArg)1 NotNull (org.jetbrains.annotations.NotNull)1