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);
}
}
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;
}
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);
}
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;
}
Aggregations