Search in sources :

Example 6 with CTextNode

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

the class View method createNode.

// ! Clones an existing node.
/**
   * Creates a new view node by cloning an existing view node.
   *
   * @param node The node to clone.
   *
   * @return The cloned node.
   */
public ViewNode createNode(final ViewNode node) {
    Preconditions.checkNotNull(node, "Error: Node argument can not be null");
    if (node instanceof CodeNode) {
        final List<INaviInstruction> instructionsList = new ArrayList<INaviInstruction>();
        for (final Instruction instruction : ((CodeNode) node).getInstructions()) {
            Preconditions.checkNotNull(instruction, "Error: Instruction list contains a null-element");
            instructionsList.add(instruction.getNative());
        }
        CCodeNode newNode;
        try {
            newNode = naviView.getContent().createCodeNode(((INaviCodeNode) node.getNative()).getParentFunction(), instructionsList);
        } catch (final MaybeNullException e) {
            newNode = naviView.getContent().createCodeNode(null, instructionsList);
        }
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof FunctionNode) {
        final CFunctionNode newNode = naviView.getContent().createFunctionNode(((INaviFunctionNode) node.getNative()).getFunction());
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof TextNode) {
        final CTextNode newNode = naviView.getContent().createTextNode(((TextNode) node).getComments());
        adjustAttributes(node, newNode);
        return cachedNodes.get(newNode);
    } else if (node instanceof GroupNode) {
        throw new IllegalStateException("Group nodes can not be cloned");
    } else {
        throw new IllegalStateException("Error: Unknown node type");
    }
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ArrayList(java.util.ArrayList) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 7 with CTextNode

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

the class View method createTextNode.

// ! Creates a new text node.
/**
   * creates a new text node.
   *
   * @param comments The list of comments to fill the text node with.
   *
   * @return The newly generated text node.
   */
public TextNode createTextNode(final ArrayList<IComment> comments) {
    Preconditions.checkNotNull(comments, "Error: Text argument can not be null");
    final CTextNode newTextNode = naviView.getContent().createTextNode(comments);
    return (TextNode) cachedNodes.get(newTextNode);
}
Also used : INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode)

Example 8 with CTextNode

use of com.google.security.zynamics.binnavi.disassembly.CTextNode 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 9 with CTextNode

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

the class ViewTest method testGraph.

@Test
public void testGraph() {
    final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
    final List<INaviEdge> edges = new ArrayList<INaviEdge>();
    final MutableDirectedGraph<INaviViewNode, INaviEdge> graph = new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
    final int viewId = new BigInteger(31, new SecureRandom()).intValue();
    final INaviView internalView = new CView(viewId, internalModule, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, m_creationDate, m_modificationDate, graph, new HashSet<CTag>(), false, m_provider);
    final INaviFunction internalFunction = internalModule.getContent().getFunctionContainer().getFunctions().get(0);
    final CCodeNode codeNode = internalView.getContent().createCodeNode(internalFunction, Lists.newArrayList(new MockInstruction()));
    final CFunctionNode functionNode = internalView.getContent().createFunctionNode(internalFunction);
    @SuppressWarnings("unused") final CTextNode textNode = internalView.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo")));
    @SuppressWarnings("unused") final CGroupNode groupNode = internalView.getContent().createGroupNode(internalView.getGraph().getNodes());
    internalView.getContent().createEdge(codeNode, functionNode, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL);
    final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
    final MockViewListener listener = new MockViewListener();
    final View view = new View(module, internalView, tagManager, m_viewTagManager);
    view.addListener(listener);
    assertEquals(4, view.getGraph().getNodes().size());
    assertEquals(1, view.getGraph().getEdges().size());
    internalView.getContent().deleteNodes(internalView.getContent().getGraph().getNodes());
    assertEquals("deletedEdge;deletedNode;deletedNode;deletedNode;", listener.events);
}
Also used : ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) SecureRandom(java.security.SecureRandom) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) BigInteger(java.math.BigInteger) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph) Test(org.junit.Test)

Example 10 with CTextNode

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

the class PostgreSQLNodeSaver method saveNodes.

/**
   * Saves the nodes to the nodes table. As a side effect, this function also fills index lists that
   * store the indices into the nodes list for all node types. TODO: This method should probably be
   * split into two methods.
   *
   * @param provider Provides the connection to the database.
   * @param newViewId ID of the new view that is being saved.
   * @param nodes The nodes to save.
   * @param functionNodeIndices Index into the nodes list that identifies the function nodes.
   * @param codeNodeIndices Index into the nodes list that identifies the code nodes.
   * @param textNodeIndices Index into the nodes list that identifies the text nodes.
   * @param groupNodeIndices Index into the nodes list that identifies the group nodes.
   * @param groupNodeMap Maps between node IDs and group node objects.
   * @return The ID of the first node saved to the database.
   * @throws SQLException Thrown if saving the nodes failed.
   */
private static int saveNodes(final AbstractSQLProvider provider, final int newViewId, final List<INaviViewNode> nodes, final List<Integer> functionNodeIndices, final List<Integer> codeNodeIndices, final List<Integer> textNodeIndices, final List<Integer> groupNodeIndices, final BiMap<Integer, INaviGroupNode> groupNodeMap) throws SQLException {
    final String query = "INSERT INTO " + CTableNames.NODES_TABLE + "( view_id, parent_id, type, x, y, width, height, color, bordercolor, " + " selected, visible) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query, java.sql.Statement.RETURN_GENERATED_KEYS);
    int counter = 0;
    for (final INaviViewNode node : nodes) {
        String nodeType = null;
        if (node instanceof CCodeNode) {
            nodeType = CODE;
            codeNodeIndices.add(counter);
        } else if (node instanceof CFunctionNode) {
            nodeType = FUNCTION;
            functionNodeIndices.add(counter);
        } else if (node instanceof INaviGroupNode) {
            nodeType = GROUP;
            groupNodeIndices.add(counter);
            groupNodeMap.put(counter, (INaviGroupNode) node);
        } else if (node instanceof CTextNode) {
            nodeType = TEXT;
            textNodeIndices.add(counter);
        }
        counter++;
        preparedStatement.setInt(1, newViewId);
        preparedStatement.setNull(2, Types.INTEGER);
        preparedStatement.setObject(3, nodeType, Types.OTHER);
        preparedStatement.setDouble(4, node.getX());
        preparedStatement.setDouble(5, node.getY());
        preparedStatement.setDouble(6, node.getWidth());
        preparedStatement.setDouble(7, node.getHeight());
        preparedStatement.setInt(8, node.getColor().getRGB());
        preparedStatement.setInt(9, node.getBorderColor().getRGB());
        preparedStatement.setBoolean(10, node.isSelected());
        preparedStatement.setBoolean(11, node.isVisible());
        preparedStatement.addBatch();
    }
    preparedStatement.executeBatch();
    final ResultSet resultSet = preparedStatement.getGeneratedKeys();
    int lastId = 0;
    try {
        while (resultSet.next()) {
            if (resultSet.isFirst()) {
                lastId = resultSet.getInt(1);
                break;
            }
        }
    } finally {
        preparedStatement.close();
        resultSet.close();
    }
    return lastId;
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) ResultSet(java.sql.ResultSet) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) PreparedStatement(java.sql.PreparedStatement) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode)

Aggregations

CTextNode (com.google.security.zynamics.binnavi.disassembly.CTextNode)12 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)5 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)5 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)4 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)4 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)4 Test (org.junit.Test)4 CGroupNode (com.google.security.zynamics.binnavi.disassembly.CGroupNode)3 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)3 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)3 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)3 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)3 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)3 ArrayList (java.util.ArrayList)3 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)2 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)2 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)2 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)2 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)2 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)2