Search in sources :

Example 1 with ICallgraphEdge

use of com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge in project binnavi by google.

the class PostgreSQLCallgraphLoader method loadCallgraph.

/**
   * Loads the call graph of a module.
   * 
   * The module, the call graph ID, and all functions of the function list must refer to objects
   * stored in the database connected to by the provider argument.
   * 
   * @param provider The SQL provider that provides the connection.
   * @param module The module whose call graph is loaded.
   * @param callgraphId The view ID of the call graph to load.
   * @param functions A list that contains all functions of the module.
   * 
   * @return The loaded call graph.
   * 
   * @throws CouldntLoadDataException Thrown if the call graph could not be loaded.
   */
public static CCallgraph loadCallgraph(final AbstractSQLProvider provider, final CModule module, final int callgraphId, final List<INaviFunction> functions) throws CouldntLoadDataException {
    checkArguments(provider, module, functions);
    final CConnection connection = provider.getConnection();
    try {
        final Pair<List<ICallgraphNode>, Map<Integer, CCallgraphNode>> nodeResult = loadNodes(connection, callgraphId, functions);
        final List<ICallgraphEdge> edges = loadEdges(connection, callgraphId, nodeResult.second());
        return new CCallgraph(nodeResult.first(), edges);
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException(exception);
    }
}
Also used : CConnection(com.google.security.zynamics.binnavi.Database.CConnection) ICallgraphEdge(com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) CCallgraph(com.google.security.zynamics.binnavi.disassembly.CCallgraph)

Example 2 with ICallgraphEdge

use of com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge in project binnavi by google.

the class PostgreSQLCallgraphLoader method loadEdges.

/**
   * Loads the edges of the call graph.
   * 
   * The call graph ID and all call graph nodes must refer to objects stored in the database
   * connected to by the connection argument.
   * 
   * @param connection Connection to the database.
   * @param callgraphId ID of the call graph view to load.
   * @param nodeMap Map between call graph node IDs and call graph view objects.
   * 
   * @return The edged of the loaded call graph.
   * 
   * @throws SQLException Thrown if loading the call graph edges failed.
   */
private static List<ICallgraphEdge> loadEdges(final CConnection connection, final int callgraphId, final Map<Integer, CCallgraphNode> nodeMap) throws SQLException {
    final List<ICallgraphEdge> edges = new ArrayList<ICallgraphEdge>();
    final String edgeQuery = "SELECT source_node_id, target_node_id" + " FROM " + CTableNames.NODES_TABLE + " JOIN " + CTableNames.EDGES_TABLE + " ON " + CTableNames.NODES_TABLE + ".id = " + CTableNames.EDGES_TABLE + ".source_node_id" + " WHERE view_id = " + callgraphId;
    final ResultSet edgeResult = connection.executeQuery(edgeQuery, true);
    try {
        while (edgeResult.next()) {
            final CCallgraphNode source = nodeMap.get(edgeResult.getInt("source_node_id"));
            final CCallgraphNode target = nodeMap.get(edgeResult.getInt("target_node_id"));
            CCallgraphNode.link(source, target);
            edges.add(new CCallgraphEdge(source, target));
        }
    } finally {
        edgeResult.close();
    }
    return edges;
}
Also used : ICallgraphEdge(com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) CCallgraphNode(com.google.security.zynamics.binnavi.disassembly.CCallgraphNode) CCallgraphEdge(com.google.security.zynamics.binnavi.disassembly.CCallgraphEdge)

Example 3 with ICallgraphEdge

use of com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge in project binnavi by google.

the class Module method createCallgraph.

/**
   * Creates the native call graph.
   */
private void createCallgraph() {
    final DirectedGraph<ICallgraphNode, ICallgraphEdge> graph = m_module.getContent().getNativeCallgraph();
    final List<FunctionBlock> blocks = new ArrayList<FunctionBlock>();
    final List<FunctionEdge> edges = new ArrayList<FunctionEdge>();
    final HashMap<ICallgraphNode, FunctionBlock> blockMap = new HashMap<ICallgraphNode, FunctionBlock>();
    final HashMap<INaviFunction, Function> functionMap = new HashMap<INaviFunction, Function>();
    for (final Function function : m_functions) {
        functionMap.put(function.getNative(), function);
    }
    for (final ICallgraphNode block : graph.getNodes()) {
        final FunctionBlock newBlock = new FunctionBlock(functionMap.get(block.getFunction()));
        blockMap.put(block, newBlock);
        blocks.add(newBlock);
    }
    for (final ICallgraphEdge edge : graph.getEdges()) {
        final FunctionBlock source = blockMap.get(edge.getSource());
        final FunctionBlock target = blockMap.get(edge.getTarget());
        edges.add(new FunctionEdge(source, target));
    }
    m_callgraph = new Callgraph(blocks, edges);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ICallgraphEdge(com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge) ICallgraphNode(com.google.security.zynamics.binnavi.disassembly.ICallgraphNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 4 with ICallgraphEdge

use of com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge in project binnavi by google.

the class CCallgraphCombiner method createCombinedCallgraph.

/**
   * Combines the call graphs of the modules of an address space.
   * 
   * @param project The project where the combined view is created.
   * @param addressSpace Provides the modules whose call graphs are combined.
   * 
   * @return The view that contains the combined call graph.
   */
public static INaviView createCombinedCallgraph(final INaviProject project, final INaviAddressSpace addressSpace) {
    final INaviView view = project.getContent().createView("Combined Callgraph", "");
    final Map<INaviFunction, CFunctionNode> nodeMap = new HashMap<INaviFunction, CFunctionNode>();
    final Map<INaviFunction, INaviFunction> resolvedMap = new HashMap<INaviFunction, INaviFunction>();
    final List<INaviModule> modules = addressSpace.getContent().getModules();
    // functions that are not forwarded.
    for (final INaviModule module : modules) {
        final CCallgraph callgraph = module.getContent().getNativeCallgraph();
        for (final ICallgraphNode callgraphNode : callgraph) {
            final INaviFunction function = callgraphNode.getFunction();
            final INaviFunction resolvedFunction = getResolvedFunction(function, modules);
            if (resolvedFunction == null) {
                final CFunctionNode node = view.getContent().createFunctionNode(function);
                node.setColor(CFunctionNodeColorizer.getFunctionColor(function.getType()));
                nodeMap.put(function, node);
            } else {
                resolvedMap.put(function, resolvedFunction);
            }
        }
    }
    // for the forwarded functions.
    for (final INaviModule module : modules) {
        final CCallgraph callgraph = module.getContent().getNativeCallgraph();
        for (final ICallgraphEdge callgraphEdge : callgraph.getEdges()) {
            final INaviFunction source = resolvedMap.containsKey(callgraphEdge.getSource().getFunction()) ? resolvedMap.get(callgraphEdge.getSource().getFunction()) : callgraphEdge.getSource().getFunction();
            final INaviFunction target = resolvedMap.containsKey(callgraphEdge.getTarget().getFunction()) ? resolvedMap.get(callgraphEdge.getTarget().getFunction()) : callgraphEdge.getTarget().getFunction();
            view.getContent().createEdge(nodeMap.get(source), nodeMap.get(target), EdgeType.JUMP_UNCONDITIONAL);
        }
    }
    return view;
}
Also used : ICallgraphEdge(com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) ICallgraphNode(com.google.security.zynamics.binnavi.disassembly.ICallgraphNode) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) HashMap(java.util.HashMap) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CCallgraph(com.google.security.zynamics.binnavi.disassembly.CCallgraph)

Aggregations

ICallgraphEdge (com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CCallgraph (com.google.security.zynamics.binnavi.disassembly.CCallgraph)2 ICallgraphNode (com.google.security.zynamics.binnavi.disassembly.ICallgraphNode)2 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)2 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)1 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1 CCallgraphEdge (com.google.security.zynamics.binnavi.disassembly.CCallgraphEdge)1 CCallgraphNode (com.google.security.zynamics.binnavi.disassembly.CCallgraphNode)1 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)1 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)1 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 Map (java.util.Map)1