use of com.google.security.zynamics.binnavi.disassembly.CFunctionNode in project binnavi by google.
the class View method createNode.
// ! Clones an existing node.
/**
* Creates a new view node by cloning an existing view node.
*
* @param node The node to clone.
*
* @return The cloned node.
*/
public ViewNode createNode(final ViewNode node) {
Preconditions.checkNotNull(node, "Error: Node argument can not be null");
if (node instanceof CodeNode) {
final List<INaviInstruction> instructionsList = new ArrayList<INaviInstruction>();
for (final Instruction instruction : ((CodeNode) node).getInstructions()) {
Preconditions.checkNotNull(instruction, "Error: Instruction list contains a null-element");
instructionsList.add(instruction.getNative());
}
CCodeNode newNode;
try {
newNode = naviView.getContent().createCodeNode(((INaviCodeNode) node.getNative()).getParentFunction(), instructionsList);
} catch (final MaybeNullException e) {
newNode = naviView.getContent().createCodeNode(null, instructionsList);
}
adjustAttributes(node, newNode);
return cachedNodes.get(newNode);
} else if (node instanceof FunctionNode) {
final CFunctionNode newNode = naviView.getContent().createFunctionNode(((INaviFunctionNode) node.getNative()).getFunction());
adjustAttributes(node, newNode);
return cachedNodes.get(newNode);
} else if (node instanceof TextNode) {
final CTextNode newNode = naviView.getContent().createTextNode(((TextNode) node).getComments());
adjustAttributes(node, newNode);
return cachedNodes.get(newNode);
} else if (node instanceof GroupNode) {
throw new IllegalStateException("Group nodes can not be cloned");
} else {
throw new IllegalStateException("Error: Unknown node type");
}
}
use of com.google.security.zynamics.binnavi.disassembly.CFunctionNode in project binnavi by google.
the class PostgreSQLFunctionNodeLoader method load.
/**
* Loads the function nodes of a view.
*
* @param provider The connection to the database.
* @param view The view whose function nodes are loaded.
* @param nodes The loaded nodes are stored here.
*
* @throws CPartialLoadException Thrown if loading the nodes failed because a necessary module was
* not loaded.
* @throws CouldntLoadDataException
*/
public static void load(final AbstractSQLProvider provider, final INaviView view, final List<INaviViewNode> nodes) throws CPartialLoadException, CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE02510: provider argument can not be null");
Preconditions.checkNotNull(view, "IE02511: view argument can not be null");
Preconditions.checkNotNull(nodes, "IE02512: nodes argument can not be null");
// TODO (timkornau): query needs to go into the database.
final String query = "SELECT nodes.view_id, nodes.id, functions.module_id, " + " function, fnodes.comment_id as local_comment, x, y, width, height, " + " color, selected, visible FROM " + CTableNames.NODES_TABLE + " AS nodes JOIN " + CTableNames.FUNCTION_NODES_TABLE + " AS fnodes " + " ON nodes.id = fnodes.node_id JOIN " + CTableNames.FUNCTIONS_TABLE + " AS functions ON functions.address = fnodes.function " + " AND functions.module_id = fnodes.module_id WHERE view_id = ?";
final Map<Integer, INaviFunctionNode> commentIdToFunctionNode = new HashMap<Integer, INaviFunctionNode>();
try {
final PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query);
statement.setInt(1, view.getConfiguration().getId());
final ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
final int moduleId = resultSet.getInt("module_id");
final INaviModule module = provider.findModule(moduleId);
if (!module.isLoaded()) {
try {
module.load();
} catch (final CouldntLoadDataException e) {
throw new CPartialLoadException("E00064: The view could not be loaded because not all modules that form the view are loaded", module);
} catch (final LoadCancelledException e) {
throw new CPartialLoadException("E00065: The view could not be loaded because not all modules that form the view are loaded", module);
}
}
final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "function");
final INaviFunction function = module.getContent().getFunctionContainer().getFunction(address);
final int nodeId = resultSet.getInt("id");
Integer commentId = resultSet.getInt("local_comment");
if (resultSet.wasNull()) {
commentId = null;
}
final double posX = resultSet.getDouble("x");
final double posY = resultSet.getDouble("y");
final double width = resultSet.getDouble("width");
final double height = resultSet.getDouble("height");
final Color color = new Color(resultSet.getInt("color"));
final boolean selected = resultSet.getBoolean("selected");
final boolean visible = resultSet.getBoolean("visible");
final INaviFunctionNode functionNode = new CFunctionNode(nodeId, function, posX, posY, width, height, color, selected, visible, null, new HashSet<CTag>(), provider);
nodes.add(functionNode);
if (commentId != null) {
commentIdToFunctionNode.put(commentId, functionNode);
}
}
} finally {
resultSet.close();
}
if (!commentIdToFunctionNode.isEmpty()) {
final HashMap<Integer, ArrayList<IComment>> commentIdsToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToFunctionNode.keySet());
for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdsToComments.entrySet()) {
commentIdToFunctionNode.get(commentIdToComment.getKey()).initializeLocalFunctionComment(commentIdToComment.getValue());
}
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
}
use of com.google.security.zynamics.binnavi.disassembly.CFunctionNode 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