Search in sources :

Example 1 with ZyEdgeRealizer

use of com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer 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);
}
Also used : ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) CEdgeUpdater(com.google.security.zynamics.binnavi.ZyGraph.Updaters.CEdgeUpdater) ZyEdgeData(com.google.security.zynamics.zylib.gui.zygraph.edges.ZyEdgeData) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Edge(y.base.Edge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 2 with ZyEdgeRealizer

use of com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer 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);
}
Also used : ZyGraphViewSettings(com.google.security.zynamics.binnavi.ZyGraph.ZyGraphViewSettings) CallGraphSettingsConfigItem(com.google.security.zynamics.binnavi.config.CallGraphSettingsConfigItem) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) Node(y.base.Node) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CModuleContainer(com.google.security.zynamics.binnavi.disassembly.Modules.CModuleContainer) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) LinkedHashMap(java.util.LinkedHashMap) View2D(com.google.security.zynamics.binnavi.yfileswrap.API.disassembly.View2D) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) ZyNormalNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) ZyGraph2DView(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Edge(y.base.Edge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) Before(org.junit.Before)

Example 3 with ZyEdgeRealizer

use of com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer in project binnavi by google.

the class ProximityNodeCreator method insertProximityEdge.

/**
   * Inserts a proximity edge between two nodes. One of the two input nodes must be a proximity
   * browsing node or an exception is thrown.
   * 
   * @param graph The graph where the node is inserted.
   * @param sourceNode The source node of the edge.
   * @param targetNode The target node of the edge.
   * 
   * @return The inserted edge.
   */
public static ZyInfoEdge insertProximityEdge(final Graph2D graph, final ZyGraphNode<?> sourceNode, final ZyGraphNode<?> targetNode) {
    Preconditions.checkNotNull(graph, "Graph argument can not be null");
    Preconditions.checkNotNull(sourceNode, "Source node argument can not be null");
    Preconditions.checkNotNull(targetNode, "Target node argument can not be null");
    Preconditions.checkArgument((sourceNode instanceof ZyProximityNode<?>) || (targetNode instanceof ZyProximityNode<?>), "One of the two arguments must be a proximity browsing node");
    final ZyEdgeRealizer<ZyInfoEdge> r = new ZyEdgeRealizer<ZyInfoEdge>(new ZyLabelContent(null), null);
    r.setLineType(LineType.LINE_2);
    final Edge edge = graph.createEdge(sourceNode.getNode(), targetNode.getNode(), r);
    final ZyInfoEdge infoEdge = new ZyInfoEdge(sourceNode, targetNode, edge, r);
    final ZyEdgeData<ZyInfoEdge> data = new ZyEdgeData<ZyInfoEdge>(infoEdge);
    r.setUserData(data);
    return infoEdge;
}
Also used : ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) ZyInfoEdge(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.edges.ZyInfoEdge) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) ZyEdgeData(com.google.security.zynamics.zylib.gui.zygraph.edges.ZyEdgeData) ZyInfoEdge(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.edges.ZyInfoEdge) Edge(y.base.Edge)

Example 4 with ZyEdgeRealizer

use of com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer in project binnavi by google.

the class TooltipGenerator method createTooltip.

/**
   * Creates the tooltip for an edge in the graph.
   * 
   * @param <NodeType> Type of the nodes in the graph.
   * 
   * @param graph The graph the edge belongs to.
   * @param edge The edge the tooltip is created for.
   * 
   * @return The generated tooltip text for the edge.
   */
public static <NodeType extends ZyGraphNode<?>> String createTooltip(final AbstractZyGraph<NodeType, ?> graph, final Edge edge) {
    Preconditions.checkNotNull(graph, "Error: Graph argument can not be null");
    Preconditions.checkNotNull(edge, "Error: Edge argument can not be null");
    // The generated tooltip has the following form:
    //
    // 1. Content of the source node
    // 2. Content of the edge label
    // 3. Content of the target node
    String text = createTooltip(graph, edge.source()).replace("</html>", "");
    final ZyEdgeRealizer<?> realizer = (ZyEdgeRealizer<?>) graph.getGraph().getRealizer(edge);
    if (realizer.labelCount() > 0) {
        final ZyEdgeLabel edgeLabel = (ZyEdgeLabel) realizer.getLabel();
        final ZyLabelContent content = edgeLabel.getLabelContent();
        text += "<hr>" + HtmlGenerator.getHtml(content, GuiHelper.getMonospaceFont(), false).replace("<html>", "").replace("</html>", "");
    }
    text += "<hr>" + createTooltip(graph, edge.target()).replace("<html>", "");
    return text;
}
Also used : ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) ZyEdgeLabel(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeLabel)

Example 5 with ZyEdgeRealizer

use of com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer in project binnavi by google.

the class ZyGraphFactory method generateTestGraph.

public static ZyGraph generateTestGraph() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
    ConfigManager.instance().read();
    final MockDatabase database = new MockDatabase();
    final SQLProvider provider = new MockSqlProvider();
    final CModule module = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
    settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
    database.getContent().addModule(module);
    final MockDatabaseManager manager = new MockDatabaseManager();
    manager.addDatabase(database);
    module.load();
    final CView m_view = module.getContent().getViewContainer().createView("name", "description");
    final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
    final ZyGraph2DView g2dView = new ZyGraph2DView();
    final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
    final Node node1 = g2dView.getGraph2D().createNode();
    final COperandTreeNode rootNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode1, childNode1);
    final COperandTreeNode rootNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode2, childNode2);
    final COperandTree operand1 = new COperandTree(rootNode1, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    final ArrayList<COperandTree> operands1 = Lists.newArrayList(operand1, operand2);
    final List<INaviInstruction> instructions1 = Lists.newArrayList((INaviInstruction) new MockInstruction(new CAddress(0x123456), "mov", operands1, null, module));
    final INaviCodeNode rawNode1 = m_view.getContent().createCodeNode(null, instructions1);
    final ZyLabelContent content = ZyCodeNodeBuilder.buildContent(rawNode1, settings, null);
    nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(content), rawNode1));
    final Node node2 = g2dView.getGraph2D().createNode();
    final List<INaviInstruction> instructions2 = Lists.newArrayList((INaviInstruction) new MockInstruction());
    final INaviCodeNode rawNode2 = m_view.getContent().createCodeNode(null, instructions2);
    final ZyLabelContent content2 = ZyCodeNodeBuilder.buildContent(rawNode2, settings, null);
    nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(content2), rawNode2));
    rawNode2.setColor(Color.RED);
    rawNode2.setVisible(false);
    final CTag tag = new CTag(0, "Tag", "Description", TagType.NODE_TAG, new MockSqlProvider());
    rawNode2.tagNode(tag);
    final Node node3 = g2dView.getGraph2D().createNode();
    final String mnemonicName = "call";
    final List<COperandTree> operandTrees = new ArrayList<COperandTree>();
    final int type = ExpressionType.REGISTER.ordinal();
    final CReference reference = new CReference(new CAddress(0x123), ReferenceType.CALL_DIRECT);
    final List<IReference> referencea = new ArrayList<IReference>();
    referencea.add(reference);
    final COperandTreeNode root = new COperandTreeNode(0, type, "eax", null, referencea, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    final COperandTree operandTree = new COperandTree(root, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
    operandTrees.add(0, operandTree);
    final List<INaviInstruction> instructions3 = Lists.newArrayList((INaviInstruction) new MockInstruction(mnemonicName, operandTrees, m_globalComment));
    final INaviCodeNode rawNode3 = m_view.getContent().createCodeNode(null, instructions3);
    final ZyLabelContent content3 = ZyCodeNodeBuilder.buildContent(rawNode3, settings, null);
    nodeMap.put(node3, new NaviNode(node3, new ZyNormalNodeRealizer<NaviNode>(content3), rawNode3));
    final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
    final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, EdgeType.JUMP_UNCONDITIONAL);
    edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
    final Edge edge2 = g2dView.getGraph2D().createEdge(node2, node3);
    final INaviEdge rawEdge2 = m_view.getContent().createEdge(rawNode2, rawNode3, EdgeType.JUMP_UNCONDITIONAL);
    edgeMap.put(edge2, new NaviEdge(nodeMap.get(node2), nodeMap.get(node3), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge2));
    return new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
}
Also used : CallGraphSettingsConfigItem(com.google.security.zynamics.binnavi.config.CallGraphSettingsConfigItem) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) Node(y.base.Node) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) CReference(com.google.security.zynamics.binnavi.disassembly.CReference) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) LinkedHashMap(java.util.LinkedHashMap) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) ZyGraph2DView(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) Date(java.util.Date) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) ZyNormalNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer) MockDatabaseManager(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabaseManager) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Edge(y.base.Edge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge)

Aggregations

ZyLabelContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent)5 ZyEdgeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer)5 Edge (y.base.Edge)4 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)3 NaviEdge (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)3 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)2 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)2 CallGraphSettingsConfigItem (com.google.security.zynamics.binnavi.config.CallGraphSettingsConfigItem)2 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)2 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)2 ZyGraph (com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph)2 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)2 ZyEdgeData (com.google.security.zynamics.zylib.gui.zygraph.edges.ZyEdgeData)2 ZyGraph2DView (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView)2 ZyNormalNodeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 Node (y.base.Node)2 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)1 MockDatabaseManager (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabaseManager)1