Search in sources :

Example 1 with ClassNode

use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.

the class ClassTree method addVertex.

@Override
public boolean addVertex(ClassNode cn) {
    if (cn == null) {
        LOGGER.error("Received null to ClassTree.addVertex");
        return false;
    }
    if (!super.addVertex(cn))
        return false;
    if (cn != rootNode) {
        Set<InheritanceEdge> edges = new HashSet<>();
        ClassNode sup = cn.node.superName != null ? requestClass0(cn.node.superName, cn.getName()) : rootNode;
        if (sup == null) {
            LOGGER.error(String.format("No superclass %s for %s", cn.node.superName, cn.getName()));
            removeVertex(cn);
            return false;
        }
        edges.add(new ExtendsEdge(cn, sup));
        for (String s : cn.node.interfaces) {
            ClassNode iface = requestClass0(s, cn.getName());
            if (iface == null) {
                LOGGER.error(String.format("No superinterface %s for %s", s, cn.getName()));
                removeVertex(cn);
                return false;
            }
            edges.add(new ImplementsEdge(cn, iface));
        }
        for (InheritanceEdge e : edges) {
            super.addEdge(e);
        }
    }
    return true;
}
Also used : InheritanceEdge(org.mapleir.app.service.ClassTree.InheritanceEdge) ClassNode(org.mapleir.asm.ClassNode)

Example 2 with ClassNode

use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.

the class ClassTree method getAllBranches.

/**
 * @param cn classnode to search out from
 * @return every class connected to the class in any way.
 */
public Collection<ClassNode> getAllBranches(ClassNode cn) {
    Collection<ClassNode> results = new HashSet<>();
    Queue<ClassNode> queue = new LinkedList<>();
    queue.add(cn);
    while (!queue.isEmpty()) {
        ClassNode next = queue.remove();
        if (results.add(next) && next != rootNode) {
            queue.addAll(getAllChildren(next));
        }
    }
    queue.add(cn);
    while (!queue.isEmpty()) {
        ClassNode next = queue.remove();
        if (results.add(next) && next != rootNode) {
            queue.addAll(getAllParents(next));
        }
    }
    return results;
}
Also used : ClassNode(org.mapleir.asm.ClassNode)

Example 3 with ClassNode

use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.

the class ClassTree method getCommonSuperType.

public ClassNode getCommonSuperType(String type1, String type2) {
    ClassNode ccn = source.findClassNode(type1);
    ClassNode dcn = source.findClassNode(type2);
    if (ccn == null) {
        ClassNode c;
        try {
            c = ClassHelper.create(type1);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        this.addVertex(ccn = c);
    }
    if (dcn == null) {
        ClassNode c;
        try {
            c = ClassHelper.create(type2);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        this.addVertex(dcn = c);
    }
    Collection<ClassNode> c = this.getAllParents(ccn);
    Collection<ClassNode> d = this.getAllParents(dcn);
    if (c.contains(dcn))
        return dcn;
    if (d.contains(ccn))
        return ccn;
    Stack<ClassNode> stack = new Stack<>();
    List<ClassNode> cached = new ArrayList<>(c);
    Collections.reverse(cached);
    stack.addAll(cached);
    while (!stack.isEmpty()) {
        final ClassNode peek = stack.pop();
        if (d.contains(peek))
            return peek;
    }
    return null;
}
Also used : ClassNode(org.mapleir.asm.ClassNode) IOException(java.io.IOException)

Example 4 with ClassNode

use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.

the class ClassSource method rebuildTable.

protected void rebuildTable() {
    Set<ClassNode> cset = new HashSet<>();
    cset.addAll(nodeMap.values());
    nodeMap.clear();
    for (ClassNode cn : cset) {
        nodeMap.put(cn.getName(), cn);
    }
}
Also used : ClassNode(org.mapleir.asm.ClassNode) HashSet(java.util.HashSet)

Example 5 with ClassNode

use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.

the class CompleteResolvingJarDumper method buildClassWriter.

public ClassWriter buildClassWriter(ClassTree tree, int flags) {
    return new ClassWriter(flags) {

        // this method in ClassWriter uses the systemclassloader as
        // a stream location to load the super class, however, most of
        // the time the class is loaded/read and parsed by us so it
        // isn't defined in the system classloader. in certain cases
        // we may not even want it to be loaded/resolved and we can
        // bypass this by implementing the hierarchy scanning algorithm
        // with ClassNodes rather than Classes.
        @Override
        protected String getCommonSuperClass(String type1, String type2) {
            ClassNode ccn = source.findClassNode(type1);
            ClassNode dcn = source.findClassNode(type2);
            if (ccn == null) {
                // return "java/lang/Object";
                ClassNode c;
                try {
                    c = ClassHelper.create(type1);
                } catch (IOException e) {
                    e.printStackTrace();
                    return "java/lang/Object";
                }
                if (c == null) {
                    return "java/lang/Object";
                }
                tree.addVertex(ccn = c);
            // classTree.build(c);
            // return getCommonSuperClass(type1, type2);
            }
            if (dcn == null) {
                // return "java/lang/Object";
                ClassNode c;
                try {
                    c = ClassHelper.create(type2);
                } catch (IOException e) {
                    e.printStackTrace();
                    return "java/lang/Object";
                }
                if (c == null) {
                    return "java/lang/Object";
                }
                tree.addVertex(dcn = c);
            // classTree.build(c)
            // return getCommonSuperClass(type1, type2);
            }
            Collection<ClassNode> c = tree.getAllParents(ccn);
            Collection<ClassNode> d = tree.getAllParents(dcn);
            if (c.contains(dcn))
                return type1;
            if (d.contains(ccn))
                return type2;
            if (Modifier.isInterface(ccn.node.access) || Modifier.isInterface(dcn.node.access)) {
                // enums as well?
                return "java/lang/Object";
            } else {
                do {
                    ClassNode nccn = source.findClassNode(ccn.node.superName);
                    if (nccn == null)
                        break;
                    ccn = nccn;
                    c = tree.getAllParents(ccn);
                } while (!c.contains(dcn));
                return ccn.getName();
            }
        }
    };
}
Also used : ClassNode(org.mapleir.asm.ClassNode) IOException(java.io.IOException) ClassWriter(org.objectweb.asm.ClassWriter)

Aggregations

ClassNode (org.mapleir.asm.ClassNode)45 MethodNode (org.mapleir.asm.MethodNode)24 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)16 AnalysisContext (org.mapleir.context.AnalysisContext)13 ApplicationClassSource (org.mapleir.app.service.ApplicationClassSource)11 JarInfo (org.topdank.byteengineer.commons.data.JarInfo)11 SingleJarDownloader (org.topdank.byteio.in.SingleJarDownloader)11 IRCache (org.mapleir.context.IRCache)8 ControlFlowGraphBuilder (org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder)8 SimpleApplicationContext (org.mapleir.app.client.SimpleApplicationContext)7 LibraryClassSource (org.mapleir.app.service.LibraryClassSource)7 BasicAnalysisContext (org.mapleir.context.BasicAnalysisContext)7 IPass (org.mapleir.deob.IPass)7 PassGroup (org.mapleir.deob.PassGroup)7 LiveDataFlowAnalysisImpl (org.mapleir.deob.dataflow.LiveDataFlowAnalysisImpl)7 ControlFlowGraphDumper (org.mapleir.ir.codegen.ControlFlowGraphDumper)7 BasicBlock (org.mapleir.ir.cfg.BasicBlock)6 JarOutputStream (java.util.jar.JarOutputStream)5 Expr (org.mapleir.ir.code.Expr)5 Stmt (org.mapleir.ir.code.Stmt)5