Search in sources :

Example 1 with CCallgraphNode

use of com.google.security.zynamics.binnavi.disassembly.CCallgraphNode 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 2 with CCallgraphNode

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

the class PostgreSQLCallgraphLoader method loadNodes.

/**
 * Loads the nodes of a call graph.
 *
 * @param connection Connection to the database.
 * @param callgraphId ID of the call graph view to load.
 * @param functions List of functions in the module whose call graph is loaded.
 *
 * @return <Call graph nodes, Call graph node IDs => Call graph nodes>
 *
 * @throws SQLException Thrown if loading the nodes failed.
 */
private static Pair<List<ICallgraphNode>, Map<Integer, CCallgraphNode>> loadNodes(final CConnection connection, final int callgraphId, final Collection<INaviFunction> functions) throws SQLException {
    // TODO: Simplify the return value of this method.
    // For performance reasons, we need a quick way to look up functions by their address.
    final Map<IAddress, INaviFunction> functionMap = getFunctionMap(functions);
    final List<ICallgraphNode> nodes = new ArrayList<ICallgraphNode>();
    final String nodeQuery = "SELECT nodes.id, function FROM " + CTableNames.NODES_TABLE + " AS nodes JOIN " + CTableNames.FUNCTION_NODES_TABLE + " AS function_nodes ON nodes.id = function_nodes.node_id WHERE nodes.view_id = " + callgraphId;
    final ResultSet nodeResult = connection.executeQuery(nodeQuery, true);
    final HashMap<Integer, CCallgraphNode> nodeMap = new HashMap<Integer, CCallgraphNode>();
    try {
        while (nodeResult.next()) {
            final int nodeId = nodeResult.getInt("id");
            final IAddress functionAddress = PostgreSQLHelpers.loadAddress(nodeResult, "function");
            final INaviFunction function = functionMap.get(functionAddress);
            final CCallgraphNode cgnode = new CCallgraphNode(function);
            nodeMap.put(nodeId, cgnode);
            nodes.add(cgnode);
        }
    } finally {
        nodeResult.close();
    }
    return new Pair<List<ICallgraphNode>, Map<Integer, CCallgraphNode>>(nodes, nodeMap);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CCallgraphNode(com.google.security.zynamics.binnavi.disassembly.CCallgraphNode) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) ICallgraphNode(com.google.security.zynamics.binnavi.disassembly.ICallgraphNode) ResultSet(java.sql.ResultSet) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Pair(com.google.security.zynamics.zylib.general.Pair)

Aggregations

CCallgraphNode (com.google.security.zynamics.binnavi.disassembly.CCallgraphNode)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 CCallgraphEdge (com.google.security.zynamics.binnavi.disassembly.CCallgraphEdge)1 ICallgraphEdge (com.google.security.zynamics.binnavi.disassembly.ICallgraphEdge)1 ICallgraphNode (com.google.security.zynamics.binnavi.disassembly.ICallgraphNode)1 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)1 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)1 Pair (com.google.security.zynamics.zylib.general.Pair)1 HashMap (java.util.HashMap)1