use of com.google.security.zynamics.binnavi.disassembly.INaviEdge 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());
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class CGraphInliner method inlineAll.
/**
* Inlines all function calls of a given graph.
*
* @param parent Parent window used for dialogs.
* @param container Contains the functions to be inlined.
* @param graph Graph where the inline operation takes place.
*/
public static void inlineAll(final JFrame parent, final IViewContainer container, final ZyGraph graph) {
Preconditions.checkNotNull(parent, "IE02285: Parent argument can not be null");
Preconditions.checkNotNull(container, "IE02286: Container argument can not be null");
Preconditions.checkNotNull(graph, "IE02287: Graph Argument can not be null");
final MutableDirectedGraph<INaviViewNode, INaviEdge> mutableGraph = (MutableDirectedGraph<INaviViewNode, INaviEdge>) graph.getRawView().getGraph();
final List<INaviViewNode> nodes = mutableGraph.getNodes();
final HashMap<INaviInstruction, INaviFunction> instructionToFunctionMap = new HashMap<INaviInstruction, INaviFunction>();
for (final INaviViewNode iNaviViewNode : nodes) {
if (iNaviViewNode instanceof INaviCodeNode) {
instructionToFunctionMap.putAll(CReferenceFinder.getCodeReferenceMap((INaviCodeNode) iNaviViewNode));
}
}
for (final INaviInstruction iNaviInstruction : instructionToFunctionMap.keySet()) {
INaviCodeNode updatedNode = null;
for (final INaviViewNode iNaviViewNode2 : graph.getRawView().getGraph().getNodes()) {
final INaviCodeNode codeNode = (INaviCodeNode) iNaviViewNode2;
if (codeNode.hasInstruction(iNaviInstruction)) {
updatedNode = codeNode;
}
}
if (updatedNode != null) {
inlineFunctionSilently(parent, container, graph, updatedNode, iNaviInstruction, instructionToFunctionMap.get(iNaviInstruction));
} else {
throw new IllegalStateException("IE01174: Graph final has been rendered final to an final inconsitant state");
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class ZyEdgeBuilder method convertEdge.
/**
* Creates a graph node from a raw edge.
*
* @param edge The raw edge that provides the underlying data.
* @param sourceNode Source node of the edge.
* @param targetNode Target node of the edge.
* @param graph2D The graph object where the edge is created.
* @param adjustColors Flag that indicates whether the initial color of all edges should be
* recalculated according to their type.
*
* @return The created YNode/NaviNode pair.
*/
public static Pair<Edge, NaviEdge> convertEdge(final INaviEdge edge, final NaviNode sourceNode, final NaviNode targetNode, final Graph2D graph2D, final boolean adjustColors) {
// Build the edge label if necessary
final ZyLabelContent content = ZyEdgeBuilder.buildContent(edge);
// Create the edge realizer of the new edge
final ZyEdgeRealizer<NaviEdge> realizer = new ZyEdgeRealizer<NaviEdge>(content, new CEdgeUpdater(edge));
// Create the edge
final Edge g2dEdge = graph2D.createEdge(sourceNode.getNode(), targetNode.getNode(), realizer);
if (adjustColors) {
EdgeInitializer.adjustColor(edge);
}
EdgeInitializer.initializeEdgeType(edge, realizer);
graph2D.getRealizer(g2dEdge).setLineColor(edge.getColor());
// Associate user data with the edge
final NaviEdge zyEdge = new NaviEdge(sourceNode, targetNode, g2dEdge, realizer, edge);
NaviNode.link(sourceNode, targetNode);
final ZyEdgeData<NaviEdge> data = new ZyEdgeData<NaviEdge>(zyEdge);
realizer.setUserData(data);
return new Pair<Edge, NaviEdge>(g2dEdge, zyEdge);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class ZyGraph method saveAs.
/**
* Creates a copy of the current native view and transfers the copied native view into the graph
* object. That means that the graph object changes its underlying raw view when this function is
* called.
*
* @param container The view container where the view is copied to.
* @param name The new name of the raw view.
* @param description The new description of the raw view.
*
* @return The new raw view.
*
* @throws CouldntSaveDataException Thrown if the view could not be saved.
*/
public INaviView saveAs(final IViewContainer container, final String name, final String description) throws CouldntSaveDataException {
Preconditions.checkNotNull(container, "IE00871: Container argument can not be null");
Preconditions.checkNotNull(name, "IE00872: Name argument can not be null");
Preconditions.checkNotNull(description, "IE00899: Description argument can not be null");
final INaviView oldView = m_rawView;
final INaviView newView = container.createView(name, description);
CViewInserter.insertView(oldView, newView);
final List<INaviViewNode> oldNodes = oldView.getGraph().getNodes();
final List<INaviViewNode> newNodes = newView.getGraph().getNodes();
for (int i = 0; i < oldNodes.size(); i++) {
final INaviViewNode newNode = newNodes.get(i);
final NaviNode oldNode = getMappings().getNode(oldNodes.get(i));
getMappings().setNode(newNode, oldNode);
oldNode.setRawNode(newNode);
for (final INaviGraphListener listener : m_listeners) {
try {
listener.changedModel(this, oldNode);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
}
final List<INaviEdge> oldEdges = oldView.getGraph().getEdges();
final List<INaviEdge> newEdges = newView.getGraph().getEdges();
for (int i = 0; i < oldEdges.size(); i++) {
final INaviEdge newEdge = newEdges.get(i);
final NaviEdge oldEdge = getMappings().getEdge(oldEdges.get(i));
assert oldEdge != null;
getMappings().setEdge(newEdge, oldEdge);
final ZyEdgeRealizer<NaviEdge> realizer = oldEdge.getRealizer();
realizer.setUpdater(new CEdgeUpdater(newEdge));
oldEdge.setRawEdge(newEdge);
}
removeListeners();
newView.save();
CSettingsFunctions.saveSettings(newView, getView(), m_settings);
m_rawView = newView;
initializeListeners();
m_synchronizer.reset();
for (final INaviGraphListener listener : m_listeners) {
// ESCA-JAVA0166: Catch Exception here because we are calling a listener function.
try {
listener.changedView(oldView, newView);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
oldView.close();
return m_rawView;
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class View2DTest method setUp.
@Before
public void setUp() throws CouldntLoadDataException, LoadCancelledException, FileReadException {
ConfigManager.instance().read();
final MockDatabase database = new MockDatabase();
final CModule module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, new MockSqlProvider());
database.getContent().addModule(module);
manager.addDatabase(database);
module.load();
m_view = module.getContent().getViewContainer().createView("name", "description");
final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
final ZyGraph2DView g2dView = new ZyGraph2DView();
final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
final Node node1 = g2dView.getGraph2D().createNode();
final CTextNode rawNode1 = m_view.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " TEXT NODE ")));
nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(new ZyLabelContent(null)), rawNode1));
final Node node2 = g2dView.getGraph2D().createNode();
final CTextNode rawNode2 = m_view.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, " TEXT COMMENT ")));
nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(new ZyLabelContent(null)), rawNode2));
final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_CONDITIONAL_FALSE);
edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
final ZyGraph graph = new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
m_view2d = new View2D(database, new CModuleContainer(database, module), graph, pluginInterface);
}
Aggregations