Search in sources :

Example 6 with MethodInfo

use of jadx.core.dex.info.MethodInfo in project jadx by skylot.

the class InsnDecoder method invoke.

private InsnNode invoke(DecodedInstruction insn, int offset, InvokeType type, boolean isRange) {
    int resReg = getMoveResultRegister(insnArr, offset);
    MethodInfo mth = MethodInfo.fromDex(dex, insn.getIndex());
    return new InvokeNode(mth, insn, type, isRange, resReg);
}
Also used : MethodInfo(jadx.core.dex.info.MethodInfo)

Example 7 with MethodInfo

use of jadx.core.dex.info.MethodInfo in project jadx by skylot.

the class InsnDecoder method invokeSpecial.

private InsnNode invokeSpecial(InsnData insn) {
    IMethodRef mthRef = InsnDataUtils.getMethodRef(insn);
    if (mthRef == null) {
        throw new JadxRuntimeException("Failed to load method reference for insn: " + insn);
    }
    MethodInfo mthInfo = MethodInfo.fromRef(root, mthRef);
    // convert 'special' to 'direct/super' same as dx
    InvokeType type;
    if (mthInfo.isConstructor() || Objects.equals(mthInfo.getDeclClass(), method.getParentClass().getClassInfo())) {
        type = InvokeType.DIRECT;
    } else {
        type = InvokeType.SUPER;
    }
    return new InvokeNode(mthInfo, insn, type, false);
}
Also used : IMethodRef(jadx.api.plugins.input.data.IMethodRef) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) MethodInfo(jadx.core.dex.info.MethodInfo)

Example 8 with MethodInfo

use of jadx.core.dex.info.MethodInfo in project jadx by skylot.

the class CustomLambdaCall method buildMethodCall.

@NotNull
private static InvokeCustomNode buildMethodCall(MethodNode mth, InsnData insn, boolean isRange, List<EncodedValue> values, IMethodHandle callMthHandle) {
    RootNode root = mth.root();
    IMethodProto lambdaProto = (IMethodProto) values.get(2).getValue();
    MethodInfo lambdaInfo = MethodInfo.fromMethodProto(root, mth.getParentClass().getClassInfo(), "", lambdaProto);
    MethodHandleType methodHandleType = callMthHandle.getType();
    InvokeCustomNode invokeCustomNode = new InvokeCustomNode(lambdaInfo, insn, false, isRange);
    invokeCustomNode.setHandleType(methodHandleType);
    ClassInfo implCls = ClassInfo.fromType(root, lambdaInfo.getReturnType());
    String implName = (String) values.get(1).getValue();
    IMethodProto implProto = (IMethodProto) values.get(3).getValue();
    MethodInfo implMthInfo = MethodInfo.fromMethodProto(root, implCls, implName, implProto);
    invokeCustomNode.setImplMthInfo(implMthInfo);
    MethodInfo callMthInfo = MethodInfo.fromRef(root, callMthHandle.getMethodRef());
    InvokeNode invokeNode = buildInvokeNode(methodHandleType, invokeCustomNode, callMthInfo);
    if (methodHandleType == MethodHandleType.INVOKE_CONSTRUCTOR) {
        ConstructorInsn ctrInsn = new ConstructorInsn(mth, invokeNode);
        invokeCustomNode.setCallInsn(ctrInsn);
    } else {
        invokeCustomNode.setCallInsn(invokeNode);
    }
    MethodNode callMth = root.resolveMethod(callMthInfo);
    if (callMth != null) {
        invokeCustomNode.getCallInsn().addAttr(callMth);
        if (callMth.getAccessFlags().isSynthetic() && callMth.getParentClass().equals(mth.getParentClass())) {
            // inline only synthetic methods from same class
            callMth.add(AFlag.DONT_GENERATE);
            invokeCustomNode.setInlineInsn(true);
        }
    }
    if (!invokeCustomNode.isInlineInsn()) {
        IMethodProto effectiveMthProto = (IMethodProto) values.get(5).getValue();
        List<ArgType> args = Utils.collectionMap(effectiveMthProto.getArgTypes(), ArgType::parse);
        boolean sameArgs = args.equals(callMthInfo.getArgumentsTypes());
        invokeCustomNode.setUseRef(sameArgs);
    }
    // prevent args inlining into not generated invoke custom node
    for (InsnArg arg : invokeCustomNode.getArguments()) {
        arg.add(AFlag.DONT_INLINE);
    }
    return invokeCustomNode;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) RootNode(jadx.core.dex.nodes.RootNode) IMethodProto(jadx.api.plugins.input.data.IMethodProto) InvokeCustomNode(jadx.core.dex.instructions.InvokeCustomNode) MethodHandleType(jadx.api.plugins.input.data.MethodHandleType) MethodNode(jadx.core.dex.nodes.MethodNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InvokeNode(jadx.core.dex.instructions.InvokeNode) MethodInfo(jadx.core.dex.info.MethodInfo) ConstructorInsn(jadx.core.dex.instructions.mods.ConstructorInsn) ClassInfo(jadx.core.dex.info.ClassInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with MethodInfo

use of jadx.core.dex.info.MethodInfo 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 10 with MethodInfo

use of jadx.core.dex.info.MethodInfo in project jadx by skylot.

the class JsonMappingGen method addMethods.

private static void addMethods(ClassNode cls, JsonClsMapping jsonCls) {
    List<MethodNode> methods = cls.getMethods();
    if (methods.isEmpty()) {
        return;
    }
    jsonCls.setMethods(new ArrayList<>(methods.size()));
    for (MethodNode method : methods) {
        JsonMthMapping jsonMethod = new JsonMthMapping();
        MethodInfo methodInfo = method.getMethodInfo();
        jsonMethod.setSignature(methodInfo.getShortId());
        jsonMethod.setName(methodInfo.getName());
        jsonMethod.setAlias(methodInfo.getAlias());
        jsonMethod.setOffset("0x" + Long.toHexString(method.getMethodCodeOffset()));
        jsonCls.getMethods().add(jsonMethod);
    }
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) MethodInfo(jadx.core.dex.info.MethodInfo) JsonMthMapping(jadx.core.codegen.json.mapping.JsonMthMapping)

Aggregations

MethodInfo (jadx.core.dex.info.MethodInfo)39 MethodNode (jadx.core.dex.nodes.MethodNode)13 ArgType (jadx.core.dex.instructions.args.ArgType)10 InvokeNode (jadx.core.dex.instructions.InvokeNode)9 InsnArg (jadx.core.dex.instructions.args.InsnArg)9 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)8 InsnNode (jadx.core.dex.nodes.InsnNode)8 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)6 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)6 ClassInfo (jadx.core.dex.info.ClassInfo)4 FieldInfo (jadx.core.dex.info.FieldInfo)4 ClassNode (jadx.core.dex.nodes.ClassNode)4 FieldNode (jadx.core.dex.nodes.FieldNode)4 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)4 ArrayList (java.util.ArrayList)4 BaseInvokeNode (jadx.core.dex.instructions.BaseInvokeNode)3 IMethodRef (jadx.api.plugins.input.data.IMethodRef)2 InvokeType (jadx.core.dex.instructions.InvokeType)2 IMethodDetails (jadx.core.dex.nodes.IMethodDetails)2 HashSet (java.util.HashSet)2