Search in sources :

Example 1 with ClspMethod

use of jadx.core.clsp.ClspMethod in project jadx by skylot.

the class OverrideMethodVisitor method processOverrideMethods.

private MethodOverrideAttr processOverrideMethods(MethodNode mth, SuperTypesData superData) {
    MethodOverrideAttr result = mth.get(AType.METHOD_OVERRIDE);
    if (result != null) {
        return result;
    }
    ClassNode cls = mth.getParentClass();
    String signature = mth.getMethodInfo().makeSignature(false);
    List<IMethodDetails> overrideList = new ArrayList<>();
    Set<IMethodDetails> baseMethods = new HashSet<>();
    for (ArgType superType : superData.getSuperTypes()) {
        ClassNode classNode = mth.root().resolveClass(superType);
        if (classNode != null) {
            MethodNode ovrdMth = searchOverriddenMethod(classNode, signature);
            if (ovrdMth != null) {
                if (isMethodVisibleInCls(ovrdMth, cls)) {
                    overrideList.add(ovrdMth);
                    MethodOverrideAttr attr = ovrdMth.get(AType.METHOD_OVERRIDE);
                    if (attr != null) {
                        addBaseMethod(superData, overrideList, baseMethods, superType);
                        return buildOverrideAttr(mth, overrideList, baseMethods, attr);
                    }
                }
            }
        } else {
            ClspClass clsDetails = mth.root().getClsp().getClsDetails(superType);
            if (clsDetails != null) {
                Map<String, ClspMethod> methodsMap = clsDetails.getMethodsMap();
                for (Map.Entry<String, ClspMethod> entry : methodsMap.entrySet()) {
                    String mthShortId = entry.getKey();
                    if (mthShortId.startsWith(signature)) {
                        overrideList.add(entry.getValue());
                        break;
                    }
                }
            }
        }
        addBaseMethod(superData, overrideList, baseMethods, superType);
    }
    return buildOverrideAttr(mth, overrideList, baseMethods, null);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ClassNode(jadx.core.dex.nodes.ClassNode) ClspClass(jadx.core.clsp.ClspClass) ClspMethod(jadx.core.clsp.ClspMethod) ArrayList(java.util.ArrayList) MethodOverrideAttr(jadx.core.dex.attributes.nodes.MethodOverrideAttr) MethodNode(jadx.core.dex.nodes.MethodNode) Map(java.util.Map) IMethodDetails(jadx.core.dex.nodes.IMethodDetails) HashSet(java.util.HashSet)

Example 2 with ClspMethod

use of jadx.core.clsp.ClspMethod in project jadx by skylot.

the class MethodUtils method processMethodArgsOverloaded.

private boolean processMethodArgsOverloaded(ArgType startCls, MethodInfo mthInfo, @Nullable List<IMethodDetails> collectedMths) {
    if (startCls == null || !startCls.isObject()) {
        return false;
    }
    boolean isMthConstructor = mthInfo.isConstructor() || mthInfo.isClassInit();
    ClassNode classNode = root.resolveClass(startCls);
    if (classNode != null) {
        for (MethodNode mth : classNode.getMethods()) {
            if (mthInfo.isOverloadedBy(mth.getMethodInfo())) {
                if (collectedMths == null) {
                    return true;
                }
                collectedMths.add(mth);
            }
        }
        if (!isMthConstructor) {
            if (processMethodArgsOverloaded(classNode.getSuperClass(), mthInfo, collectedMths)) {
                if (collectedMths == null) {
                    return true;
                }
            }
            for (ArgType parentInterface : classNode.getInterfaces()) {
                if (processMethodArgsOverloaded(parentInterface, mthInfo, collectedMths)) {
                    if (collectedMths == null) {
                        return true;
                    }
                }
            }
        }
    } else {
        ClspClass clsDetails = root.getClsp().getClsDetails(startCls);
        if (clsDetails == null) {
            // class info not available
            return false;
        }
        for (ClspMethod clspMth : clsDetails.getMethodsMap().values()) {
            if (mthInfo.isOverloadedBy(clspMth.getMethodInfo())) {
                if (collectedMths == null) {
                    return true;
                }
                collectedMths.add(clspMth);
            }
        }
        if (!isMthConstructor) {
            for (ArgType parent : clsDetails.getParents()) {
                if (processMethodArgsOverloaded(parent, mthInfo, collectedMths)) {
                    if (collectedMths == null) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ClassNode(jadx.core.dex.nodes.ClassNode) MethodNode(jadx.core.dex.nodes.MethodNode) ClspClass(jadx.core.clsp.ClspClass) ClspMethod(jadx.core.clsp.ClspMethod)

Aggregations

ClspClass (jadx.core.clsp.ClspClass)2 ClspMethod (jadx.core.clsp.ClspMethod)2 ArgType (jadx.core.dex.instructions.args.ArgType)2 ClassNode (jadx.core.dex.nodes.ClassNode)2 MethodNode (jadx.core.dex.nodes.MethodNode)2 MethodOverrideAttr (jadx.core.dex.attributes.nodes.MethodOverrideAttr)1 IMethodDetails (jadx.core.dex.nodes.IMethodDetails)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1