Search in sources :

Example 1 with NaviEdge

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

the class CSearchResultsDialog method setResults.

/**
   * Fills the search results table model with search results data.
   *
   * @param results The search results data.
   */
private void setResults(final List<SearchResult> results) {
    final Object[][] data = new Object[results.size()][1];
    int counter = 0;
    for (final SearchResult result : results) {
        if (result.getObject() instanceof NaviNode) {
            final NaviNode node = (NaviNode) result.getObject();
            final ZyLabelContent labelContent = node.getRealizer().getNodeContent();
            final String lineText = labelContent.getLineContent(result.getLine()).getText();
            data[counter++][0] = lineText;
        } else if (result.getObject() instanceof NaviEdge) {
            final NaviEdge edge = (NaviEdge) result.getObject();
            final ZyLabelContent labelContent = edge.getLabelContent();
            final String lineText = labelContent.getLineContent(result.getLine()).getText();
            data[counter++][0] = lineText;
        }
    }
    m_table.setModel(new CResultsTableModel(data, new String[] { "Result" }));
    m_resultsLabel.setText(String.format("%d search results", data.length));
}
Also used : ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) 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)

Example 2 with NaviEdge

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

the class GraphSearcher method search.

/**
   * Searches through a list of nodes and edges while considering the active search settings.
   *
   * @param nodes The nodes to search through.
   * @param edges The edges to search through.
   * @param searchString The string to search for.
   */
public void search(final List<NaviNode> nodes, final List<NaviEdge> edges, final String searchString) {
    m_lastSearchString = searchString;
    clearResults();
    final List<NaviNode> filteredNodes = CResultFilter.filteredNodes(nodes, m_settings.isOnlySelected(), m_settings.isOnlyVisible());
    final List<NaviEdge> filteredEdges = CResultFilter.filteredEdges(edges, m_settings.isOnlySelected(), m_settings.isOnlyVisible());
    searchAll(filteredNodes, filteredEdges, searchString);
    Collections.sort(m_results, new CSearchResultComparator());
    m_cursor.setResults(m_results);
}
Also used : NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) CSearchResultComparator(com.google.security.zynamics.binnavi.Gui.GraphWindows.Searchers.Text.Model.CSearchResultComparator) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge)

Example 3 with NaviEdge

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

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

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

the class CSearchExecuter method startNewSearch.

/**
   * Cycles through an existing search operation.
   *
   * @param parent Parent window used for dialogs.
   * @param editor Combobox editor whose color is changed depending on the search result.
   * @param graph Graph to search through.
   * @param searcher Executes the search over the graph.
   * @param searchString The string to search for.
   * @param zoomToResult True, to zoom to a result. False, to move without zooming.
   */
private static void startNewSearch(final Window parent, final ComboBoxEditor editor, final ZyGraph graph, final GraphSearcher searcher, final String searchString, final boolean zoomToResult) {
    try {
        // Search for all occurrences
        searcher.search(GraphHelpers.getNodes(graph), GraphHelpers.getEdges(graph), searchString);
        if (searcher.getResults().isEmpty()) {
            editor.getEditorComponent().setBackground(BACKGROUND_COLOR_FAIL);
        } else {
            editor.getEditorComponent().setBackground(BACKGROUND_COLOR_SUCCESS);
        }
        // Immediately display all search occurrences
        for (final SearchResult result : searcher.getResults()) {
            if (result.getObject() instanceof NaviNode) {
                final NaviNode node = (NaviNode) result.getObject();
                node.setBackgroundColor(result.getLine(), result.getPosition(), result.getLength(), Color.YELLOW);
            } else if (result.getObject() instanceof NaviEdge) {
                final NaviEdge edge = (NaviEdge) result.getObject();
                edge.getLabelContent().getLineContent(result.getLine()).setBackgroundColor(result.getPosition(), result.getLength(), Color.YELLOW);
            }
        }
        final SearchResult result = searcher.getCursor().current();
        if (result != null) {
            if (result.getObject() instanceof NaviNode) {
                ZyGraphHelpers.centerNode(graph, (NaviNode) result.getObject(), zoomToResult);
            } else if (result.getObject() instanceof NaviEdge) {
                ZyGraphHelpers.centerEdgeLabel(graph, (NaviEdge) result.getObject(), zoomToResult);
            }
        }
        graph.updateGraphViews();
    } catch (final PatternSyntaxException exception) {
        // Do not bother to log this
        CMessageBox.showInformation(parent, String.format("Invalid Regular Expression '%s'", searchString));
    }
}
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) PatternSyntaxException(java.util.regex.PatternSyntaxException)

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