Search in sources :

Example 6 with GraphSearcher

use of com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher in project binnavi by google.

the class GraphSearcherTest method testSearchVisible.

@Test
public void testSearchVisible() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException {
    final MockSqlProvider sql = new MockSqlProvider();
    final CModule module = MockCreator.createModule(sql);
    module.load();
    final CFunction function = MockCreator.createFunction(module, sql);
    final CView m_view = MockCreator.createView(sql, module);
    final CInstruction instruction1 = MockCreator.createInstruction(module, sql);
    final CInstruction instruction2 = MockCreator.createInstruction(module, sql);
    final CInstruction instruction3 = MockCreator.createInstruction(module, sql);
    m_view.load();
    final CCodeNode node1 = m_view.getContent().createCodeNode(function, Lists.newArrayList(instruction1, instruction2, instruction3));
    final CCodeNode node2 = m_view.getContent().createCodeNode(function, Lists.newArrayList(instruction1, instruction2, instruction3));
    final CCodeNode node3 = m_view.getContent().createCodeNode(function, Lists.newArrayList(instruction1, instruction2, instruction3));
    final ZyNodeRealizer<NaviNode> r1 = new ZyNormalNodeRealizer<NaviNode>(m_content);
    final ZyNodeRealizer<NaviNode> r2 = new ZyNormalNodeRealizer<NaviNode>(m_content);
    final ZyNodeRealizer<NaviNode> r3 = new ZyNormalNodeRealizer<NaviNode>(m_content);
    final Graph2D g = new Graph2D();
    g.setHierarchyManager(new HierarchyManager(g));
    final NaviNode m_node1 = new NaviNode(g.createNode(), r1, node1);
    final NaviNode m_node2 = new NaviNode(g.createNode(), r2, node2);
    final NaviNode m_node3 = new NaviNode(g.createNode(), r3, node3);
    assertTrue(m_node1.isVisible());
    final GraphSearcher searcher = new GraphSearcher();
    searcher.getSettings().setOnlyVisible(true);
    m_content.addLineContent(new ZyLineContent("Hello my Test", null));
    searcher.search(Lists.newArrayList(m_node1, m_node2, m_node3), new ArrayList<NaviEdge>(), "my");
    assertEquals(m_node1, searcher.getCursor().current().getObject());
    assertEquals(0, searcher.getCursor().current().getLine());
    assertEquals(6, searcher.getCursor().current().getPosition());
    assertEquals(2, searcher.getCursor().current().getLength());
    searcher.getCursor().next();
    assertEquals(m_node2, searcher.getCursor().current().getObject());
    assertEquals(0, searcher.getCursor().current().getLine());
    assertEquals(6, searcher.getCursor().current().getPosition());
    assertEquals(2, searcher.getCursor().current().getLength());
    searcher.getCursor().next();
    assertEquals(m_node3, searcher.getCursor().current().getObject());
    assertEquals(0, searcher.getCursor().current().getLine());
    assertEquals(6, searcher.getCursor().current().getPosition());
    assertEquals(2, searcher.getCursor().current().getLength());
    m_node2.getRawNode().setVisible(false);
    searcher.search(Lists.newArrayList(m_node1, m_node2, m_node3), new ArrayList<NaviEdge>(), "my");
    assertEquals(m_node1, searcher.getCursor().current().getObject());
    assertEquals(0, searcher.getCursor().current().getLine());
    assertEquals(6, searcher.getCursor().current().getPosition());
    assertEquals(2, searcher.getCursor().current().getLength());
    searcher.getCursor().next();
    assertEquals(m_node3, searcher.getCursor().current().getObject());
    assertEquals(0, searcher.getCursor().current().getLine());
    assertEquals(6, searcher.getCursor().current().getPosition());
    assertEquals(2, searcher.getCursor().current().getLength());
}
Also used : NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) Graph2D(y.view.Graph2D) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) HierarchyManager(y.view.hierarchy.HierarchyManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) ZyNormalNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer) GraphSearcher(com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher) ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Test(org.junit.Test)

Example 7 with GraphSearcher

use of com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher in project binnavi by google.

the class GraphSearcherTest method testBeforeFirst.

@Test
public void testBeforeFirst() {
    final ZyNodeRealizer<NaviNode> r = new ZyNormalNodeRealizer<NaviNode>(m_content);
    final NaviNode m_node1 = new NaviNode(m_ynode, r, m_codeNode1);
    final NaviNode m_node2 = 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));
    m_content.addLineContent(new ZyLineContent("Hello my Test", null));
    searcher.search(Lists.newArrayList(m_node1, m_node2), new ArrayList<NaviEdge>(), "my");
    assertFalse(searcher.getCursor().isAfterLast());
    searcher.getCursor().previous();
    assertTrue(searcher.getCursor().isBeforeFirst());
    searcher.getCursor().previous();
    assertFalse(searcher.getCursor().isBeforeFirst());
}
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 GraphSearcher

use of com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher in project binnavi by google.

the class GraphSearcherTest method testSimple.

@Test
public void testSimple() {
    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");
    assertEquals(m_node1, searcher.getCursor().current().getObject());
    assertEquals(0, searcher.getCursor().current().getLine());
    assertEquals(6, searcher.getCursor().current().getPosition());
    assertEquals(2, searcher.getCursor().current().getLength());
    // TEST: Do not move beyond the last result
    searcher.getCursor().next();
    assertEquals(m_node1, searcher.getCursor().current().getObject());
    assertEquals(0, searcher.getCursor().current().getLine());
    assertEquals(6, searcher.getCursor().current().getPosition());
    assertEquals(2, searcher.getCursor().current().getLength());
}
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 GraphSearcher

use of com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher 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 : NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) ArrayList(java.util.ArrayList) 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)

Aggregations

GraphSearcher (com.google.security.zynamics.binnavi.yfileswrap.Gui.GraphWindows.Searchers.Text.Model.GraphSearcher)9 NaviEdge (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)9 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)9 ZyLineContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent)8 ZyNormalNodeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer)8 Test (org.junit.Test)8 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)1 SearchResult (com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.SearchResult)1 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)1 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)1 CInstruction (com.google.security.zynamics.binnavi.disassembly.CInstruction)1 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)1 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)1 ArrayList (java.util.ArrayList)1 Graph2D (y.view.Graph2D)1 HierarchyManager (y.view.hierarchy.HierarchyManager)1