Search in sources :

Example 6 with NaviEdge

use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge 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)

Example 7 with NaviEdge

use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge in project binnavi by google.

the class GraphSearcherTest method testSimpleNoResult.

@Test
public void testSimpleNoResult() {
    final ZyNodeRealizer<NaviNode> r = new ZyNormalNodeRealizer<NaviNode>(m_content);
    final NaviNode m_node1 = new NaviNode(m_ynode, r, m_codeNode1);
    final GraphSearcher searcher = new GraphSearcher();
    m_content.addLineContent(new ZyLineContent("Hello my Test", null));
    searcher.search(Lists.newArrayList(m_node1), new ArrayList<NaviEdge>(), "mx");
    searcher.getCursor().next();
    assertNull(searcher.getCursor().current());
}
Also used : ZyNormalNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) GraphSearcher(com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Test(org.junit.Test)

Example 8 with NaviEdge

use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge in project binnavi by google.

the class GraphSearcherTest method testAfterLast.

@Test
public void testAfterLast() {
    final ZyNodeRealizer<NaviNode> r = new ZyNormalNodeRealizer<NaviNode>(m_content);
    final NaviNode m_node1 = new NaviNode(m_ynode, r, m_codeNode1);
    final GraphSearcher searcher = new GraphSearcher();
    searcher.search(Lists.newArrayList(m_node1), new ArrayList<NaviEdge>(), "");
    assertNull(searcher.getCursor().current());
    m_content.addLineContent(new ZyLineContent("Hello my Test", null));
    searcher.search(Lists.newArrayList(m_node1), new ArrayList<NaviEdge>(), "my");
    assertFalse(searcher.getCursor().isAfterLast());
    searcher.getCursor().next();
    assertTrue(searcher.getCursor().isAfterLast());
    searcher.getCursor().next();
    assertTrue(searcher.getCursor().isAfterLast());
}
Also used : ZyNormalNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) GraphSearcher(com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Test(org.junit.Test)

Example 9 with NaviEdge

use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge in project binnavi by google.

the class CGraphFunctions method selectNodesWithString.

/**
   * Selects all nodes of a graph that contain a given search string.
   *
   * @param graph The graph to search through and select.
   * @param searchString The search string to search for.
   */
public static void selectNodesWithString(final ZyGraph graph, final String searchString) {
    Preconditions.checkNotNull(graph, "IE02117: Graph argument can not be null");
    Preconditions.checkNotNull(searchString, "IE02118: Search string argument can not be null");
    final GraphSearcher searcher = new GraphSearcher();
    searcher.search(GraphHelpers.getNodes(graph), new ArrayList<NaviEdge>(), searchString);
    final List<SearchResult> results = searcher.getResults();
    final List<NaviNode> resultNodes = new ArrayList<NaviNode>();
    for (final SearchResult searchResult : results) {
        resultNodes.add((NaviNode) searchResult.getObject());
    }
    graph.selectNodes(resultNodes, true);
    searcher.dispose();
}
Also used : ArrayList(java.util.ArrayList) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) GraphSearcher(com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher) SearchResult(com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.SearchResult) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)

Example 10 with NaviEdge

use of com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge in project binnavi by google.

the class CGraphSearchField method jumpTo.

/**
   * Jumps to a search result of the given index.
   *
   * @param index The index of the search result to jump to.
   */
public void jumpTo(final int index) {
    m_searcher.getCursor().jumpTo(index);
    final SearchResult result = m_searcher.getCursor().current();
    if (result == null) {
        return;
    }
    if (result.getObject() instanceof NaviNode) {
        ZyGraphHelpers.centerNode(m_graph, (NaviNode) result.getObject(), false);
    } else if (result.getObject() instanceof NaviEdge) {
        ZyGraphHelpers.centerEdgeLabel(m_graph, (NaviEdge) result.getObject(), false);
    }
}
Also used : NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) SearchResult(com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.SearchResult) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)

Aggregations

NaviEdge (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)20 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)19 ZyNormalNodeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer)10 GraphSearcher (com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher)9 Test (org.junit.Test)9 ZyLineContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)8 SearchResult (com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.SearchResult)5 ZyLabelContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent)5 Edge (y.base.Edge)5 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)4 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)3 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)3 ZyGraph (com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph)3 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)3 ZyGraph2DView (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView)3 ZyEdgeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer)3 Node (y.base.Node)3 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)2 ZyGraphViewSettings (com.google.security.zynamics.binnavi.ZyGraph.ZyGraphViewSettings)2 CallGraphSettingsConfigItem (com.google.security.zynamics.binnavi.config.CallGraphSettingsConfigItem)2