Search in sources :

Example 1 with ClspClass

use of jadx.core.clsp.ClspClass 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 ClspClass

use of jadx.core.clsp.ClspClass 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)

Example 3 with ClspClass

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

the class TypeUtils method visitSuperTypes.

public void visitSuperTypes(ArgType type, BiConsumer<ArgType, ArgType> consumer) {
    ClassNode cls = root.resolveClass(type);
    if (cls != null) {
        cls.visitSuperTypes(consumer);
    } else {
        ClspClass clspClass = root.getClsp().getClsDetails(type);
        if (clspClass != null) {
            for (ArgType superType : clspClass.getParents()) {
                if (!superType.equals(ArgType.OBJECT)) {
                    consumer.accept(type, superType);
                    visitSuperTypes(superType, consumer);
                }
            }
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ClassNode(jadx.core.dex.nodes.ClassNode) ClspClass(jadx.core.clsp.ClspClass)

Example 4 with ClspClass

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

the class OverrideMethodVisitor method addSuperType.

private int addSuperType(RootNode root, List<ArgType> superTypesMap, Set<String> endTypes, ArgType superType) {
    if (Objects.equals(superType, ArgType.OBJECT)) {
        return 0;
    }
    superTypesMap.add(superType);
    ClassNode classNode = root.resolveClass(superType);
    if (classNode != null) {
        collectSuperTypes(classNode, superTypesMap, endTypes);
        return 1;
    }
    ClspClass clsDetails = root.getClsp().getClsDetails(superType);
    if (clsDetails != null) {
        int k = 0;
        for (ArgType parentType : clsDetails.getParents()) {
            k += addSuperType(root, superTypesMap, endTypes, parentType);
        }
        if (k == 0) {
            endTypes.add(superType.getObject());
        }
        return 1;
    }
    // no info found => treat as hierarchy end
    endTypes.add(superType.getObject());
    return 1;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ClassNode(jadx.core.dex.nodes.ClassNode) ClspClass(jadx.core.clsp.ClspClass)

Example 5 with ClspClass

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

the class TypeUtils method getClassGenerics.

public List<ArgType> getClassGenerics(ArgType type) {
    ClassNode classNode = root.resolveClass(type);
    if (classNode != null) {
        return classNode.getGenericTypeParameters();
    }
    ClspClass clsDetails = root.getClsp().getClsDetails(type);
    if (clsDetails == null || clsDetails.getTypeParameters().isEmpty()) {
        return Collections.emptyList();
    }
    List<ArgType> generics = clsDetails.getTypeParameters();
    return generics == null ? Collections.emptyList() : generics;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ClassNode(jadx.core.dex.nodes.ClassNode) ClspClass(jadx.core.clsp.ClspClass)

Aggregations

ClspClass (jadx.core.clsp.ClspClass)5 ArgType (jadx.core.dex.instructions.args.ArgType)5 ClassNode (jadx.core.dex.nodes.ClassNode)5 ClspMethod (jadx.core.clsp.ClspMethod)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