Search in sources :

Example 1 with ClassTree

use of org.mapleir.app.service.ClassTree in project maple-ir by LLVM-but-worse.

the class SimpleApplicationContext method isLibraryInheritedMethod.

private boolean isLibraryInheritedMethod(MethodNode m) {
    if (Modifier.isStatic(m.node.access) || m.getName().equals("<init>")) {
        return false;
    }
    ClassTree tree = app.getClassTree();
    // TODO: could probably optimise with dfs instead of getAll
    Collection<ClassNode> parents = tree.getAllParents(m.owner);
    for (ClassNode cn : parents) {
        if (app.isLibraryClass(cn.getName())) {
            for (MethodNode cnM : cn.getMethods()) {
                if (!Modifier.isStatic(cnM.node.access) && cnM.getName().equals(m.getName()) && cnM.getDesc().equals(m.getDesc())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ClassNode(org.mapleir.asm.ClassNode) MethodNode(org.mapleir.asm.MethodNode) ClassTree(org.mapleir.app.service.ClassTree)

Example 2 with ClassTree

use of org.mapleir.app.service.ClassTree in project maple-ir by LLVM-but-worse.

the class HierarchyMethods method getHierarchyMethodChain.

public Set<MethodNode> getHierarchyMethodChain(ClassNode cn, String name, String desc, boolean exact) {
    ClassTree structures = app.getClassTree();
    Set<MethodNode> foundMethods = new HashSet<>();
    Collection<ClassNode> toSearch = structures.getAllBranches(cn);
    for (ClassNode viable : toSearch) {
        foundMethods.addAll(findMethods(viable, name, desc, exact ? EXACT_TYPES : CONGRUENT_TYPES, VIRTUAL_METHOD | Modifier.ABSTRACT | Opcodes.ACC_BRIDGE, 0));
    }
    return foundMethods;
}
Also used : ClassNode(org.mapleir.asm.ClassNode) MethodNode(org.mapleir.asm.MethodNode) ClassTree(org.mapleir.app.service.ClassTree) HashSet(java.util.HashSet)

Example 3 with ClassTree

use of org.mapleir.app.service.ClassTree in project maple-ir by LLVM-but-worse.

the class HierarchyMethods method areTypesCongruent.

/**
 * Two types are congruent if they are primitive and the same, or if one is a subclass of another.
 * @param a type A
 * @param b type B
 * @return true if type A and B are congruent
 */
private boolean areTypesCongruent(Type a, Type b) {
    if (a.equals(b)) {
        return true;
    }
    boolean eArr = a.getSort() == Type.ARRAY;
    boolean aArr = b.getSort() == Type.ARRAY;
    if (eArr != aArr) {
        return false;
    }
    if (eArr) {
        a = a.getElementType();
        b = b.getElementType();
    }
    if (TypeUtils.isPrimitive(a) || TypeUtils.isPrimitive(b)) {
        return false;
    }
    if (a == Type.VOID_TYPE || b == Type.VOID_TYPE) {
        return false;
    }
    ClassNode cnA = app.findClassNode(a.getInternalName());
    ClassNode cnB = app.findClassNode(b.getInternalName());
    ClassTree tree = app.getClassTree();
    return tree.getAllParents(cnB).contains(cnA) || tree.getAllParents(cnA).contains(cnB);
}
Also used : ClassNode(org.mapleir.asm.ClassNode) ClassTree(org.mapleir.app.service.ClassTree)

Aggregations

ClassTree (org.mapleir.app.service.ClassTree)3 ClassNode (org.mapleir.asm.ClassNode)3 MethodNode (org.mapleir.asm.MethodNode)2 HashSet (java.util.HashSet)1