Search in sources :

Example 11 with IMethodDetails

use of jadx.core.dex.nodes.IMethodDetails in project jadx by skylot.

the class InlineMethods method processInvokeInsn.

private void processInvokeInsn(MethodNode mth, BlockNode block, InvokeNode insn) {
    IMethodDetails callMthDetails = insn.get(AType.METHOD_DETAILS);
    if (!(callMthDetails instanceof MethodNode)) {
        return;
    }
    MethodNode callMth = (MethodNode) callMthDetails;
    try {
        // TODO: sort inner classes process order by dependencies!
        MethodInlineAttr mia = MarkMethodsForInline.process(callMth);
        if (mia == null) {
            // method not yet loaded => will retry at codegen stage
            callMth.getParentClass().reloadAtCodegenStage();
            return;
        }
        if (mia.notNeeded()) {
            return;
        }
        inlineMethod(mth, callMth, mia, block, insn);
    } catch (Exception e) {
        throw new JadxRuntimeException("Failed to process method for inline: " + callMth, e);
    }
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) MethodInlineAttr(jadx.core.dex.attributes.nodes.MethodInlineAttr) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) JadxException(jadx.core.utils.exceptions.JadxException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IMethodDetails(jadx.core.dex.nodes.IMethodDetails)

Example 12 with IMethodDetails

use of jadx.core.dex.nodes.IMethodDetails in project jadx by skylot.

the class OverrideMethodVisitor method processMth.

private void processMth(MethodNode mth, SuperTypesData superData) {
    if (mth.isConstructor() || mth.getAccessFlags().isStatic() || mth.getAccessFlags().isPrivate()) {
        return;
    }
    MethodOverrideAttr attr = processOverrideMethods(mth, superData);
    if (attr != null) {
        if (attr.getBaseMethods().isEmpty()) {
            throw new JadxRuntimeException("No base methods for override attribute: " + attr.getOverrideList());
        }
        mth.addAttr(attr);
        IMethodDetails baseMth = Utils.getOne(attr.getBaseMethods());
        if (baseMth != null) {
            boolean updated = fixMethodReturnType(mth, baseMth, superData);
            updated |= fixMethodArgTypes(mth, baseMth, superData);
            if (updated) {
                // check if new signature cause method collisions
                checkMethodSignatureCollisions(mth, mth.root().getArgs().isRenameValid());
            }
        }
    }
}
Also used : JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) MethodOverrideAttr(jadx.core.dex.attributes.nodes.MethodOverrideAttr) IMethodDetails(jadx.core.dex.nodes.IMethodDetails)

Example 13 with IMethodDetails

use of jadx.core.dex.nodes.IMethodDetails in project jadx by skylot.

the class TypeUtils method getTypeVarMappingForInvoke.

public Map<ArgType, ArgType> getTypeVarMappingForInvoke(BaseInvokeNode invokeInsn) {
    IMethodDetails mthDetails = root.getMethodUtils().getMethodDetails(invokeInsn);
    if (mthDetails == null) {
        return Collections.emptyMap();
    }
    Map<ArgType, ArgType> map = new HashMap<>(1 + invokeInsn.getArgsCount());
    addTypeVarMapping(map, mthDetails.getReturnType(), invokeInsn.getResult());
    int argCount = Math.min(mthDetails.getArgTypes().size(), invokeInsn.getArgsCount());
    for (int i = 0; i < argCount; i++) {
        addTypeVarMapping(map, mthDetails.getArgTypes().get(i), invokeInsn.getArg(i));
    }
    return map;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) HashMap(java.util.HashMap) IMethodDetails(jadx.core.dex.nodes.IMethodDetails)

Example 14 with IMethodDetails

use of jadx.core.dex.nodes.IMethodDetails in project jadx by skylot.

the class TypeInferenceVisitor method makeInvokeUseBound.

private ITypeBound makeInvokeUseBound(RegisterArg regArg, BaseInvokeNode invoke) {
    InsnArg instanceArg = invoke.getInstanceArg();
    if (instanceArg == null) {
        return null;
    }
    MethodUtils methodUtils = root.getMethodUtils();
    IMethodDetails methodDetails = methodUtils.getMethodDetails(invoke);
    if (methodDetails == null) {
        return null;
    }
    if (instanceArg != regArg) {
        int argIndex = invoke.getArgIndex(regArg) - invoke.getFirstArgOffset();
        ArgType argType = methodDetails.getArgTypes().get(argIndex);
        if (!argType.containsTypeVariable()) {
            return null;
        }
        return new TypeBoundInvokeUse(root, invoke, regArg, argType);
    }
    // for override methods use origin declared class as type
    if (methodDetails instanceof MethodNode) {
        MethodNode callMth = (MethodNode) methodDetails;
        ClassInfo declCls = methodUtils.getMethodOriginDeclClass(callMth);
        return new TypeBoundConst(BoundEnum.USE, declCls.getType(), regArg);
    }
    return null;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) MethodNode(jadx.core.dex.nodes.MethodNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) MethodUtils(jadx.core.dex.nodes.utils.MethodUtils) IMethodDetails(jadx.core.dex.nodes.IMethodDetails) ClassInfo(jadx.core.dex.info.ClassInfo)

Aggregations

IMethodDetails (jadx.core.dex.nodes.IMethodDetails)14 ArgType (jadx.core.dex.instructions.args.ArgType)7 MethodNode (jadx.core.dex.nodes.MethodNode)6 ArrayList (java.util.ArrayList)4 MethodOverrideAttr (jadx.core.dex.attributes.nodes.MethodOverrideAttr)3 MethodInfo (jadx.core.dex.info.MethodInfo)2 InsnArg (jadx.core.dex.instructions.args.InsnArg)2 ClassNode (jadx.core.dex.nodes.ClassNode)2 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)2 ClspClass (jadx.core.clsp.ClspClass)1 ClspMethod (jadx.core.clsp.ClspMethod)1 MethodBridgeAttr (jadx.core.dex.attributes.nodes.MethodBridgeAttr)1 MethodInlineAttr (jadx.core.dex.attributes.nodes.MethodInlineAttr)1 SkipMethodArgsAttr (jadx.core.dex.attributes.nodes.SkipMethodArgsAttr)1 AccessInfo (jadx.core.dex.info.AccessInfo)1 ClassInfo (jadx.core.dex.info.ClassInfo)1 BaseInvokeNode (jadx.core.dex.instructions.BaseInvokeNode)1 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1 InsnNode (jadx.core.dex.nodes.InsnNode)1