Search in sources :

Example 11 with INaviTextNode

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

the class CViewInserter method createNodes.

/**
   * Clones a node of the source view and inserts it into the target view.
   *
   * @param target The target view where the cloned view is inserted.
   * @param sourceNode The source node that is cloned and inserted into the target view.
   * @param nodeMap Maps nodes of the source view to their cloned counterparts.
   */
private static void createNodes(final INaviView target, final INaviViewNode sourceNode, final Map<INaviViewNode, INaviViewNode> nodeMap) {
    final INaviViewNode newNode = CNodeTypeSwitcher.switchNode(sourceNode, new INodeTypeCallback<INaviViewNode>() {

        @Override
        public INaviViewNode handle(final INaviCodeNode node) {
            return insertCodeNode(target, node);
        }

        @Override
        public INaviViewNode handle(final INaviFunctionNode node) {
            return insertFunctionNode(target, node);
        }

        @Override
        public INaviViewNode handle(final INaviGroupNode node) {
            // Skip now, create later
            return null;
        }

        @Override
        public INaviViewNode handle(final INaviTextNode node) {
            return insertTextNode(target, node);
        }
    });
    if (newNode != null) {
        newNode.setBorderColor(sourceNode.getBorderColor());
        newNode.setColor(sourceNode.getColor());
        newNode.setHeight(sourceNode.getHeight());
        newNode.setSelected(sourceNode.isSelected());
        newNode.setVisible(sourceNode.isVisible());
        newNode.setWidth(sourceNode.getWidth());
        newNode.setX(sourceNode.getX());
        newNode.setY(sourceNode.getY());
        nodeMap.put(sourceNode, newNode);
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)

Example 12 with INaviTextNode

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

the class CGraphGrouper method determineNodeText.

/**
   * Determines the text to be displayed in a group node, if the given node is inside a collapsed
   * group node.
   * 
   * @param node The node whose text is determined.
   * 
   * @return The string to be displayed for the given node.
   */
private static String determineNodeText(final NaviNode node) {
    if (node.getRawNode() instanceof INaviCodeNode) {
        final INaviCodeNode cnode = (INaviCodeNode) node.getRawNode();
        return String.format("Basic Block: %s", cnode.getAddress().toHexString());
    } else if (node.getRawNode() instanceof INaviFunctionNode) {
        final INaviFunctionNode fnode = (INaviFunctionNode) node.getRawNode();
        return String.format("Function: %s (%s)", fnode.getFunction().getName(), fnode.getFunction().getAddress().toHexString());
    } else if (node.getRawNode() instanceof INaviTextNode) {
        // Display up to 15 characters of the first line of
        // the comment for comment nodes.
        final INaviTextNode tnode = (INaviTextNode) node.getRawNode();
        final List<IComment> comment = tnode.getComments();
        final String firstLine = (comment.isEmpty()) ? "" : comment.get(1).getComment();
        final int firstLineBreak = Math.min(firstLine.indexOf('\n'), firstLine.indexOf('\r'));
        final int toDisplay = Math.min(Math.min(15, firstLineBreak == -1 ? Integer.MAX_VALUE : firstLineBreak), firstLine.length());
        return String.format("Text: %s", firstLine.substring(0, toDisplay));
    } else if (node.getRawNode() instanceof INaviGroupNode) {
        // Display up to 15 characters of the first line of
        // the comment for group nodes.
        final INaviGroupNode gnode = (INaviGroupNode) node.getRawNode();
        final List<IComment> comment = gnode.getComments();
        final String firstLine = (comment.isEmpty()) ? "" : comment.get(0).getComment();
        final int firstLineBreak = Math.min(firstLine.indexOf('\n'), firstLine.indexOf('\r'));
        final int toDisplay = Math.min(Math.min(15, firstLineBreak == -1 ? Integer.MAX_VALUE : firstLineBreak), firstLine.length());
        return String.format("Group: %s", firstLine.substring(0, toDisplay));
    } else {
        throw new IllegalStateException("IE01150: Unknown node type");
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) ArrayList(java.util.ArrayList) List(java.util.List) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)

Example 13 with INaviTextNode

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

the class PostgreSQLNotificationParserTest method testTextNodeCommentParsingDeleteComment.

@Test
public void testTextNodeCommentParsingDeleteComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_text_nodes UPDATE 7777 null");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processTextNodeCommentNotification(notification, provider);
    assertNotNull(result);
    final TextNodeCommentNotificationContainer container = (TextNodeCommentNotificationContainer) result;
    final INaviTextNode textNode = container.getNode();
    assertEquals(7777, textNode.getId());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) TextNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TextNodeCommentNotificationContainer) Test(org.junit.Test)

Example 14 with INaviTextNode

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

the class PostgreSQLNotificationParserTest method testTextNodeCommentParsingAppendComment.

@Test
public void testTextNodeCommentParsingAppendComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_text_nodes UPDATE 7777 3333");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processTextNodeCommentNotification(notification, provider);
    assertNotNull(result);
    final TextNodeCommentNotificationContainer container = (TextNodeCommentNotificationContainer) result;
    final INaviTextNode textNode = container.getNode();
    assertEquals(7777, textNode.getId());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
}
Also used : CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) TextNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TextNodeCommentNotificationContainer) Test(org.junit.Test)

Example 15 with INaviTextNode

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

the class PostgreSQLCommentNotificationParser method processTextNodeCommentNotification.

/**
   * Parses the {@link PGNotification} notifications from the PostgreSQL database back end for text
   * node comments by using a regular expression. If the regular expression matches the supplied
   * {@link PGNotification} notification, it is determined if the text node in the notification is
   * currently loaded, and if a {@link CommentNotificationContainer} with the gathered data from the
   * notification is returned.
   *
   * @param notification The {@link PGNotification} from the PostgreSQL database server.
   * @param provider The {@link SQLProvider} which is used to communicate with the database.
   */
static CommentNotification processTextNodeCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = TEXT_NODE_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer nodeId = Integer.parseInt(matcher.group(3));
    final Integer commentId = matcher.group(4).equals("null") ? null : Integer.parseInt(matcher.group(4));
    final INaviTextNode node = (INaviTextNode) NodeCache.get(provider).getNodeById(nodeId);
    if (node == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new TextNodeCommentNotificationContainer(node, operation, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) Matcher(java.util.regex.Matcher) INaviTextNode(com.google.security.zynamics.binnavi.disassembly.INaviTextNode) TextNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TextNodeCommentNotificationContainer)

Aggregations

INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)28 Test (org.junit.Test)20 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)15 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)13 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)9 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)8 IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)8 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)7 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)5 TextNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TextNodeCommentNotificationContainer)3 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)3 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)3 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)3 ArrayList (java.util.ArrayList)3 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)2 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)2 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)2 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)2 PreparedStatement (java.sql.PreparedStatement)2 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)1