use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class CView method save.
@Override
public void save() throws CouldntSaveDataException {
Preconditions.checkArgument(getType() == ViewType.NonNative, "IE00314: Native views can not be saved");
Preconditions.checkState(isLoaded(), "IE00315: View must be loaded before it can be saved");
if (m_configuration.isStored()) {
m_provider.save(this);
} else {
CView newView;
final INaviModule naviModule = m_configuration.getModule();
if (naviModule == null) {
newView = m_provider.createView(m_configuration.getProject(), this, getName(), m_configuration.getDescription());
} else {
newView = m_provider.createView(naviModule, this, getName(), m_configuration.getDescription());
}
m_configuration.setId(newView.getConfiguration().getId());
}
final IDirectedGraph<INaviViewNode, INaviEdge> graph = m_content.getGraph();
m_bbcount = graph.nodeCount();
m_edgecount = graph.edgeCount();
for (final INaviViewListener listener : m_listeners) {
listener.savedView(this);
}
m_configuration.updateModificationDate();
m_content.save();
m_lastGraphType = m_content.getGraphType();
// Update caches.
NodeCache.get(m_provider).addNodes(graph.getNodes());
EdgeCache.get(m_provider).addEdges(graph.getEdges());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class CViewContent method updateGraphType.
/**
* Calculates the new graph type of the view from the current state of the view graph.
*/
private void updateGraphType() {
boolean hasCodeNode = false;
boolean hasFunctionNode = false;
for (final INaviViewNode node : graph.getNodes()) {
if (node instanceof INaviFunctionNode) {
hasFunctionNode = true;
if (hasCodeNode) {
setGraphType(GraphType.MIXED_GRAPH);
return;
}
} else if (node instanceof INaviCodeNode) {
hasCodeNode = true;
if (hasFunctionNode) {
setGraphType(GraphType.MIXED_GRAPH);
return;
}
}
}
if (hasCodeNode) {
setGraphType(GraphType.FLOWGRAPH);
} else if (hasFunctionNode) {
setGraphType(GraphType.CALLGRAPH);
} else {
setGraphType(GraphType.MIXED_GRAPH);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class CUnInliner method getInlinedNodes.
/**
* Determines inlining information starting with a given node.
* TODO(thomasdullien): This code is pretty thoroughly broken for any form of
* nested inlining and needs to be rewritten.
*
* @param node The start node.
*
* @return Information about the inlining boundaries.
*/
public static CInlinedNodes getInlinedNodes(final INaviCodeNode node) {
Preconditions.checkNotNull(node, "IE02750: node argument can not be null");
// Performs a recursive backward search upward in the graph until it finds
// an 'enter inlined function' edge, then returns it's source node. This
// will usually be "a function layer up" from the function that is about to
// be uninlined. Please note that if, while searching up, it enters a
// different inlined subfunction, this function will return a wrong node.
final INaviCodeNode startNode = searchForSourceNodeOfEnterInlinedEdge(node);
// Performs a recursive forward search downward in the graph until it finds
// a 'leave inlined function' edge whose source node is in the same function
// as 'node'. Returns the target of this edge. Please note that if, while
// searching down a second nested inlined version of the current function is
// found, this code will return the wrong node.
final INaviCodeNode endNode = getEndNode(node);
if (startNode == null || endNode == null) {
return null;
}
// to simply carry on for now until the above functions can be fixed.
if (hasDifferentParentFunctions(startNode, endNode)) {
NaviLogger.info("Uninlining yielded almost certainly incorrect results.");
}
final Set<INaviViewNode> preds = GraphAlgorithms.getPredecessorsUpToNode(endNode, startNode);
final Set<INaviViewNode> succs = GraphAlgorithms.getSuccessorsDownToNode(startNode, endNode);
preds.retainAll(succs);
return new CInlinedNodes(startNode, endNode, ImmutableList.copyOf(preds));
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class CViewInserter method createNodes.
/**
* Clones a node of the source view and inserts it into the target view.
*
* @param target The target view where the cloned view is inserted.
* @param sourceNode The source node that is cloned and inserted into the target view.
* @param nodeMap Maps nodes of the source view to their cloned counterparts.
*/
private static void createNodes(final INaviView target, final INaviViewNode sourceNode, final Map<INaviViewNode, INaviViewNode> nodeMap) {
final INaviViewNode newNode = CNodeTypeSwitcher.switchNode(sourceNode, new INodeTypeCallback<INaviViewNode>() {
@Override
public INaviViewNode handle(final INaviCodeNode node) {
return insertCodeNode(target, node);
}
@Override
public INaviViewNode handle(final INaviFunctionNode node) {
return insertFunctionNode(target, node);
}
@Override
public INaviViewNode handle(final INaviGroupNode node) {
// Skip now, create later
return null;
}
@Override
public INaviViewNode handle(final INaviTextNode node) {
return insertTextNode(target, node);
}
});
if (newNode != null) {
newNode.setBorderColor(sourceNode.getBorderColor());
newNode.setColor(sourceNode.getColor());
newNode.setHeight(sourceNode.getHeight());
newNode.setSelected(sourceNode.isSelected());
newNode.setVisible(sourceNode.isVisible());
newNode.setWidth(sourceNode.getWidth());
newNode.setX(sourceNode.getX());
newNode.setY(sourceNode.getY());
nodeMap.put(sourceNode, newNode);
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviViewNode in project binnavi by google.
the class CViewInserter method createEdges.
/**
* Clones the edges of the source view and inserts them into the target view.
*
* @param target The target view where the cloned edges are inserted.
* @param edges The source edges that are cloned.
* @param nodeMap Maps between the source nodes and their cloned counterparts.
*/
private static void createEdges(final INaviView target, final List<INaviEdge> edges, final Map<INaviViewNode, INaviViewNode> nodeMap) {
for (final INaviEdge edge : edges) {
final INaviViewNode sourceNode = nodeMap.get(edge.getSource());
final INaviViewNode targetNode = nodeMap.get(edge.getTarget());
final CNaviViewEdge newEdge = target.getContent().createEdge(sourceNode, targetNode, edge.getType());
newEdge.setColor(edge.getColor());
newEdge.setX1(edge.getX1());
newEdge.setY1(edge.getY1());
newEdge.setX2(edge.getX2());
newEdge.setY2(edge.getY2());
for (final CBend bend : edge.getBends()) {
newEdge.addBend(bend.getX(), bend.getY());
}
}
}
Aggregations