Search in sources :

Example 31 with INaviCodeNode

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

the class PostgreSQLNotificationParserTest method testGlobalCodeNodeCommentParsingDeleteComment.

@Test
public void testGlobalCodeNodeCommentParsingDeleteComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_global_node_comments DELETE 1 4608");
    final Collection<CommentNotification> result = PostgreSQLCommentNotificationParser.processNodeGlobalCommentNotification(notification, provider);
    assertEquals(1, result.size());
    final CodeNodeCommentNotificationContainer container = (CodeNodeCommentNotificationContainer) Iterables.getFirst(result, null);
    final INaviCodeNode node = container.getNode();
    assertEquals(1111, node.getId());
    assertEquals(new CAddress(4608), node.getAddress());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
    assertEquals(CommentScope.GLOBAL, container.getScope());
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CodeNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 32 with INaviCodeNode

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

the class PostgreSQLNotificationParserTest method testGlobalCodeNodeCommentParsingAppendNewComment.

@Test
public void testGlobalCodeNodeCommentParsingAppendNewComment() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_global_node_comments UPDATE 1 4608 3333");
    final Collection<CommentNotification> result = PostgreSQLCommentNotificationParser.processNodeGlobalCommentNotification(notification, provider);
    assertEquals(1, result.size());
    final CodeNodeCommentNotificationContainer container = (CodeNodeCommentNotificationContainer) Iterables.getFirst(result, null);
    final INaviCodeNode node = container.getNode();
    assertEquals(1111, node.getId());
    assertEquals(new CAddress(4608), node.getAddress());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
    assertEquals(CommentScope.GLOBAL, container.getScope());
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CodeNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 33 with INaviCodeNode

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

the class PostgreSQLNotificationParserTest method testLocalCodeNodeCommentParsingAppend.

@Test
public void testLocalCodeNodeCommentParsingAppend() {
    new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_code_nodes UPDATE 1 1111 4608 3333");
    CommentNotification result = PostgreSQLCommentNotificationParser.processNodeLocalNodeCommentNotification(notification, provider);
    assertNotNull(result);
    final CodeNodeCommentNotificationContainer container = (CodeNodeCommentNotificationContainer) result;
    final INaviCodeNode node = container.getNode();
    assertEquals(1111, node.getId());
    assertEquals(new CAddress(4608), node.getAddress());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
    assertEquals(CommentScope.LOCAL, container.getScope());
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CodeNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 34 with INaviCodeNode

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

the class CGraphSynchronizer method updateInstructionMap.

/**
 * Updates the cached Address => Instruction map.
 */
private void updateInstructionMap() {
    m_instructionMap.clear();
    for (final INaviViewNode node : m_graph.getRawView().getGraph()) {
        if (node instanceof INaviCodeNode) {
            final INaviCodeNode cnode = (INaviCodeNode) node;
            for (final INaviInstruction instruction : cnode.getInstructions()) {
                final IAddress address = instruction.getAddress();
                m_instructionMap.put(address, instruction);
            }
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 35 with INaviCodeNode

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

the class CViewPruner method convertNodes.

/**
 * Converts the nodes from the original view to the pruned view.
 *
 * @param view The original view.
 * @param prunedView The pruned view.
 * @param keptInstructions Instructions to add to the new view.
 *
 * @return A mapping between nodes of the original view and nodes of the pruned view.
 */
private static Map<INaviViewNode, INaviViewNode> convertNodes(final INaviView view, final INaviView prunedView, final List<INaviInstruction> keptInstructions) {
    final Map<INaviViewNode, INaviViewNode> nodeMap = new HashMap<INaviViewNode, INaviViewNode>();
    for (final INaviViewNode node : view.getGraph().getNodes()) {
        if (node instanceof INaviCodeNode) {
            final INaviCodeNode cnode = (INaviCodeNode) node;
            final ArrayList<INaviInstruction> newInstructions = Lists.newArrayList(cnode.getInstructions());
            newInstructions.retainAll(keptInstructions);
            if (!newInstructions.isEmpty()) {
                CCodeNode newNode;
                try {
                    newNode = prunedView.getContent().createCodeNode(cnode.getParentFunction(), newInstructions);
                } catch (final MaybeNullException e) {
                    newNode = prunedView.getContent().createCodeNode(null, newInstructions);
                }
                newNode.setBorderColor(node.getBorderColor());
                newNode.setColor(node.getColor());
                nodeMap.put(node, newNode);
            }
        } else if (node instanceof INaviFunctionNode) {
            final INaviFunction function = ((INaviFunctionNode) node).getFunction();
            final CFunctionNode newNode = prunedView.getContent().createFunctionNode(function);
            nodeMap.put(node, newNode);
        }
    }
    return nodeMap;
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) HashMap(java.util.HashMap) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)70 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)25 Test (org.junit.Test)23 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)21 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)18 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)17 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)14 ArrayList (java.util.ArrayList)13 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)12 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)11 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)9 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)9 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)9 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)9 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)8 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)8 CodeNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer)6 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)5 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)5