Search in sources :

Example 11 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.

the class CNodeFunctions method createCommentNode.

/**
   * Attaches a comment node to a given view node.
   * 
   * @param parent Parent used for dialogs.
   * @param view The view where the new comment node is created.
   * @param node The node the new comment node is attached to.
   */
public static void createCommentNode(final JFrame parent, final INaviView view, final INaviViewNode node) {
    Preconditions.checkNotNull(parent, "IE02128: Parent argument can not be null");
    Preconditions.checkNotNull(view, "IE02129: View argument can not be null");
    Preconditions.checkNotNull(node, "IE01726: Node argument can not be null");
    // TODO (timkornau): this is just transposed from the old code
    // needs to be checked to if we still want this to be like this.
    final CTextNode source = view.getContent().createTextNode(null);
    final CNaviViewEdge edge = view.getContent().createEdge(source, node, EdgeType.TEXTNODE_EDGE);
    final DialogTextNodeComment dlg = new DialogTextNodeComment(parent, source);
    GuiHelper.centerChildToParent(parent, dlg, true);
    dlg.setVisible(true);
    final List<IComment> newComment = dlg.getComment();
    if (newComment == null) {
        view.getContent().deleteEdge(edge);
        view.getContent().deleteNode(source);
    }
}
Also used : CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) DialogTextNodeComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.TextNodeComments.DialogTextNodeComment)

Example 12 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.

the class PostgreSQLEdgeLoader method loadEdges.

/**
   * Loads the edges of a view.
   *
   * @param provider The connection to the database.
   * @param view The view whose edges are loaded.
   * @param nodeLookup Maps between node IDs and their corresponding node objects.
   * @param edgeToGlobalCommentMap Maps between edge IDs and their associated comments.
   *
   * @return The loaded edges.
   *
   * @throws CouldntLoadDataException
   */
private static List<INaviEdge> loadEdges(final AbstractSQLProvider provider, final INaviView view, final Map<Integer, INaviViewNode> nodeLookup, final Map<Integer, ArrayList<IComment>> edgeToGlobalCommentMap) throws CouldntLoadDataException {
    final String query = "SELECT * FROM load_view_edges(" + view.getConfiguration().getId() + ")";
    List<CBend> currentPaths = new ArrayList<CBend>();
    final Map<Integer, INaviEdge> commentIdToEdge = new HashMap<Integer, INaviEdge>();
    final Map<Integer, INaviEdge> edgeIdToEdge = new HashMap<Integer, INaviEdge>();
    try {
        final CConnection connection = provider.getConnection();
        final PreparedStatement statement = connection.getConnection().prepareStatement(query);
        final ResultSet resultSet = statement.executeQuery();
        try {
            while (resultSet.next()) {
                final int edgeId = resultSet.getInt("id");
                if (edgeIdToEdge.containsKey(edgeId)) {
                    final INaviEdge edge = edgeIdToEdge.get(edgeId);
                    final double pathX = resultSet.getDouble("x");
                    final double pathY = resultSet.getDouble("y");
                    if (!resultSet.wasNull()) {
                        edge.addBend(pathX, pathY);
                    }
                    continue;
                }
                final int sourceNode = resultSet.getInt("source_node_id");
                final int targetNode = resultSet.getInt("target_node_id");
                Integer localCommentId = resultSet.getInt("comment_id");
                if (resultSet.wasNull()) {
                    localCommentId = null;
                }
                final double x1 = resultSet.getDouble("x1");
                final double y1 = resultSet.getDouble("y1");
                final double x2 = resultSet.getDouble("x2");
                final double y2 = resultSet.getDouble("y2");
                final EdgeType type = EdgeType.valueOf(resultSet.getString("type").toUpperCase());
                final Color color = new Color(resultSet.getInt("color"));
                final boolean visible = resultSet.getBoolean("visible");
                final boolean selected = resultSet.getBoolean("selected");
                final INaviViewNode source = nodeLookup.get(sourceNode);
                final INaviViewNode target = nodeLookup.get(targetNode);
                final double pathX = resultSet.getDouble("x");
                final double pathY = resultSet.getDouble("y");
                if (!resultSet.wasNull()) {
                    currentPaths.add(new CBend(pathX, pathY));
                }
                final CNaviViewEdge edge = new CNaviViewEdge(edgeId, source, target, type, x1, y1, x2, y2, color, selected, visible, null, currentPaths, provider);
                if (localCommentId != null) {
                    commentIdToEdge.put(localCommentId, edge);
                }
                final ArrayList<IComment> globalComments = edgeToGlobalCommentMap.containsKey(edgeId) ? edgeToGlobalCommentMap.get(edgeId) : null;
                if ((globalComments != null) && (globalComments.size() != 0)) {
                    initializeGlobalComment(edge, globalComments, provider);
                }
                source.addOutgoingEdge(edge);
                target.addIncomingEdge(edge);
                edgeIdToEdge.put(edge.getId(), edge);
                currentPaths = new ArrayList<CBend>();
            }
            if (!commentIdToEdge.isEmpty()) {
                final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToEdge.keySet());
                for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
                    commentIdToEdge.get(commentIdToComment.getKey()).initializeLocalComment(commentIdToComment.getValue());
                }
            }
        } finally {
            resultSet.close();
        }
    } catch (final SQLException exception) {
        throw new CouldntLoadDataException("Error: Loading of view edges failed");
    }
    return Lists.newArrayList(edgeIdToEdge.values());
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) ResultSet(java.sql.ResultSet) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) Color(java.awt.Color) PreparedStatement(java.sql.PreparedStatement) EdgeType(com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType) CConnection(com.google.security.zynamics.binnavi.Database.CConnection) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)

Example 13 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.

the class PostgreSQLLocalEdgeCommentTests method appendLocalEdgeComment4.

@Test
public void appendLocalEdgeComment4() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException, CPartialLoadException {
    final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
    final List<IComment> storedComments = edge.getLocalComment() == null ? new ArrayList<IComment>() : edge.getLocalComment();
    final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
    final String firstCommentString = " PASS LOCAL EDGE COMMENT WITHOUT PARENT ID ";
    final int firstCommentId = getProvider().appendLocalEdgeComment(edge, firstCommentString, user.getUserId());
    final IComment firstComment = new CComment(firstCommentId, user, lastComment, firstCommentString);
    final String secondCommentString = " PASS LOCAL EDGE COMMENT WITH PARENT ID ";
    final int secondCommentId = getProvider().appendLocalEdgeComment(edge, secondCommentString, user.getUserId());
    final IComment secondComment = new CComment(secondCommentId, user, firstComment, secondCommentString);
    final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(secondCommentId);
    assertNotNull(commentsFromDatabase);
    assertEquals(storedComments.size() + 2, commentsFromDatabase.size());
    assertTrue(commentsFromDatabase.contains(firstComment));
    assertTrue(commentsFromDatabase.contains(secondComment));
    final CNaviViewEdge callgraphEdge = (CNaviViewEdge) loadCallGraphEdge(getKernel32Module());
    getProvider().appendLocalEdgeComment(callgraphEdge, " PASS LOCAL CALLGRAPH EDGE COMMENT WITHOUT PARENT ID ", user.getUserId());
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) UniqueTestUserGenerator(com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 14 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.

the class CUnInlinerTest method testUninlineSingleBlockNested.

@Test
public void testUninlineSingleBlockNested() {
    final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
    final List<INaviEdge> edges = new FilledList<INaviEdge>();
    final INaviFunction mockFunction = new MockFunction(m_provider);
    final INaviFunction mockFunction2 = new MockFunction(m_provider);
    final MockInstruction mi1 = new MockInstruction(0x123);
    final MockInstruction mi2 = new MockInstruction(0x124);
    final MockInstruction mi3 = new MockInstruction(0x125);
    final CCodeNode parentNode = new CCodeNode(1, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode upperNode = new CCodeNode(2, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode inlinedNode = new CCodeNode(3, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
    final CCodeNode lowerNode = new CCodeNode(4, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode childNode = new CCodeNode(5, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    upperNode.addInstruction(mi1, null);
    inlinedNode.addInstruction(mi2, null);
    lowerNode.addInstruction(mi3, null);
    nodes.add(parentNode);
    nodes.add(upperNode);
    nodes.add(inlinedNode);
    nodes.add(lowerNode);
    nodes.add(childNode);
    final CNaviViewEdge parentEdge = new CNaviViewEdge(0, parentNode, upperNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge enteringEdge = new CNaviViewEdge(1, upperNode, inlinedNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge leavingEdge = new CNaviViewEdge(2, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge childEdge1 = new CNaviViewEdge(3, lowerNode, childNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    edges.add(parentEdge);
    edges.add(enteringEdge);
    edges.add(leavingEdge);
    edges.add(childEdge1);
    connect(parentNode, upperNode, parentEdge);
    connect(upperNode, inlinedNode, enteringEdge);
    connect(inlinedNode, lowerNode, leavingEdge);
    connect(lowerNode, childNode, childEdge1);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, inlinedNode);
    assertEquals(3, view.getNodeCount());
    assertEquals(2, view.getEdgeCount());
    assertEquals(EdgeType.ENTER_INLINED_FUNCTION, view.getGraph().getEdges().get(0).getType());
    assertEquals(EdgeType.LEAVE_INLINED_FUNCTION, view.getGraph().getEdges().get(1).getType());
    final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(2);
    assertEquals(2, Iterables.size(cnode.getInstructions()));
    assertEquals(mi1.toString(), Iterables.get(cnode.getInstructions(), 0).toString());
    assertEquals(mi3.toString(), Iterables.get(cnode.getInstructions(), 1).toString());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Example 15 with CNaviViewEdge

use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.

the class CUnInlinerTest method testUninlineSingleBlockLoop.

@Test
public void testUninlineSingleBlockLoop() {
    final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
    final List<INaviEdge> edges = new FilledList<INaviEdge>();
    final INaviFunction mockFunction = new MockFunction(m_provider);
    final INaviFunction mockFunction2 = new MockFunction(m_provider);
    final MockInstruction mi1 = new MockInstruction(0x111);
    final MockInstruction mi2 = new MockInstruction(0x222);
    final MockInstruction mi3 = new MockInstruction(0x333);
    final MockInstruction mi4 = new MockInstruction(0x444);
    final MockInstruction mi5 = new MockInstruction(0x555);
    final MockInstruction mi6 = new MockInstruction(0x666);
    final CCodeNode parentNode = new CCodeNode(1, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode upperNode = new CCodeNode(2, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode inlinedNode = new CCodeNode(3, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
    final CCodeNode lowerNode = new CCodeNode(4, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode childNode1 = new CCodeNode(5, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    final CCodeNode childNode2 = new CCodeNode(6, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
    parentNode.addInstruction(mi1, null);
    upperNode.addInstruction(mi2, null);
    inlinedNode.addInstruction(mi3, null);
    lowerNode.addInstruction(mi4, null);
    childNode1.addInstruction(mi5, null);
    childNode2.addInstruction(mi6, null);
    nodes.add(parentNode);
    nodes.add(upperNode);
    nodes.add(inlinedNode);
    nodes.add(lowerNode);
    nodes.add(childNode1);
    nodes.add(childNode2);
    final CNaviViewEdge parentUpperEdge = new CNaviViewEdge(1, parentNode, upperNode, EdgeType.JUMP_UNCONDITIONAL, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge upperInlinedEdge = new CNaviViewEdge(2, upperNode, inlinedNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge inlingedLowerEdge = new CNaviViewEdge(3, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge lowerChild1Edge = new CNaviViewEdge(4, lowerNode, childNode1, EdgeType.JUMP_CONDITIONAL_TRUE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge lowerChild2Edge = new CNaviViewEdge(5, lowerNode, childNode2, EdgeType.JUMP_CONDITIONAL_FALSE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    final CNaviViewEdge child1UpperEdge = new CNaviViewEdge(6, childNode1, upperNode, EdgeType.JUMP_UNCONDITIONAL_LOOP, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
    edges.add(parentUpperEdge);
    edges.add(upperInlinedEdge);
    edges.add(inlingedLowerEdge);
    edges.add(lowerChild1Edge);
    edges.add(lowerChild2Edge);
    edges.add(child1UpperEdge);
    connect(parentNode, upperNode, parentUpperEdge);
    connect(upperNode, inlinedNode, upperInlinedEdge);
    connect(inlinedNode, lowerNode, inlingedLowerEdge);
    connect(lowerNode, childNode1, lowerChild1Edge);
    connect(lowerNode, childNode2, lowerChild2Edge);
    connect(childNode1, upperNode, child1UpperEdge);
    final MockView view = new MockView(nodes, edges, m_provider);
    CUnInliner.unInline(view, inlinedNode);
    assertEquals(4, view.getNodeCount());
    assertEquals(4, view.getEdgeCount());
    assertEquals(EdgeType.JUMP_UNCONDITIONAL, view.getGraph().getEdges().get(0).getType());
    assertEquals(EdgeType.JUMP_UNCONDITIONAL_LOOP, view.getGraph().getEdges().get(1).getType());
    assertEquals(EdgeType.JUMP_CONDITIONAL_TRUE, view.getGraph().getEdges().get(2).getType());
    assertEquals(EdgeType.JUMP_CONDITIONAL_FALSE, view.getGraph().getEdges().get(3).getType());
    final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(3);
    assertEquals(2, Iterables.size(cnode.getInstructions()));
    assertEquals(mi2.toString(), Iterables.get(cnode.getInstructions(), 0).toString());
    assertEquals(mi4.toString(), Iterables.get(cnode.getInstructions(), 1).toString());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) FilledList(com.google.security.zynamics.zylib.types.lists.FilledList) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CBend(com.google.security.zynamics.zylib.gui.zygraph.edges.CBend) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Aggregations

CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)18 Test (org.junit.Test)11 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)8 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)7 CBend (com.google.security.zynamics.zylib.gui.zygraph.edges.CBend)7 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)6 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)6 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)5 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)5 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)5 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)5 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)4 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)4 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)4 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)3 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)3 CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)3 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)3 ArrayList (java.util.ArrayList)3 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)2