use of com.google.security.zynamics.binnavi.disassembly.ICallgraphNode 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);
}
use of com.google.security.zynamics.binnavi.disassembly.ICallgraphNode 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);
}
use of com.google.security.zynamics.binnavi.disassembly.ICallgraphNode 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;
}
Aggregations