Search in sources :

Example 76 with INaviFunction

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

the class ZyFunctionNodeBuilder method buildNameLine.

/**
   * Builds the name line of a function node.
   *
   * @param node The function node which provides the raw data.
   * @param content The node content object where the name line is added.
   * @param showFunctionInformation True, to show function information in the node. False, to hide
   *        it.
   */
private static void buildNameLine(final INaviFunctionNode node, final ZyLabelContent content, final boolean showFunctionInformation) {
    final INaviFunction function = node.getFunction();
    String informationString = "";
    if (function.getBasicBlockCount() > 0) {
        final StringBuilder builder = new StringBuilder();
        builder.append(" (");
        builder.append(function.getBasicBlockCount());
        builder.append(" basic block");
        if (function.getBasicBlockCount() > 1) {
            builder.append('s');
        }
        if (function.getEdgeCount() > 0) {
            builder.append(", ");
            builder.append(function.getEdgeCount());
            builder.append(" edge");
            if (function.getEdgeCount() > 1) {
                builder.append('s');
            }
        }
        builder.append(')');
        informationString = builder.toString();
    }
    final ZyLineContent nameLine = new ZyLineContent(function.getName() + informationString, NORMAL_FONT, null);
    content.addLineContent(nameLine);
}
Also used : ZyLineContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 77 with INaviFunction

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

the class CNodeFunctions method splitAfter.

/**
   * Splits a node.
   * 
   * @param view View the node belongs to.
   * @param originalNode Node to split.
   * @param instruction Instruction after which the node is split.
   */
public static void splitAfter(final INaviView view, final INaviCodeNode originalNode, final INaviInstruction instruction) {
    final Iterable<INaviInstruction> oldInstructions = originalNode.getInstructions();
    if (instruction == Iterables.getLast(oldInstructions)) {
        return;
    }
    // Step I: Find out what instructions belong to the new upper block and what
    // instructions belong to the new lower block.
    final List<INaviInstruction> upperInstructions = new ArrayList<INaviInstruction>();
    final List<INaviInstruction> lowerInstructions = new ArrayList<INaviInstruction>();
    List<INaviInstruction> currentInstructions = upperInstructions;
    for (final INaviInstruction oldInstruction : oldInstructions) {
        currentInstructions.add(oldInstruction);
        if (oldInstruction == instruction) {
            currentInstructions = lowerInstructions;
        }
    }
    // Step II: Create the two new code nodes.
    INaviFunction parentFunction = null;
    try {
        parentFunction = originalNode.getParentFunction();
    } catch (final MaybeNullException e) {
    // No parent function
    }
    final INaviCodeNode newNode1 = view.getContent().createCodeNode(parentFunction, upperInstructions);
    final INaviCodeNode newNode2 = view.getContent().createCodeNode(parentFunction, lowerInstructions);
    newNode1.setColor(originalNode.getColor());
    newNode1.setBorderColor(originalNode.getBorderColor());
    newNode2.setColor(originalNode.getColor());
    // Step III: Transfer node comments and instruction comments from the old node
    // to the new nodes.
    transferLocalCodeNodeComments(originalNode, newNode1, newNode2);
    // Step IV: Connect the two new nodes.
    view.getContent().createEdge(newNode1, newNode2, EdgeType.JUMP_UNCONDITIONAL);
    for (final INaviEdge incomingEdge : originalNode.getIncomingEdges()) {
        view.getContent().createEdge(incomingEdge.getSource(), newNode1, incomingEdge.getType());
    }
    for (final INaviEdge outgoingEdge : originalNode.getOutgoingEdges()) {
        view.getContent().createEdge(newNode2, outgoingEdge.getTarget(), outgoingEdge.getType());
    }
    // Step VI: Get rid of the old node.
    view.getContent().deleteNode(originalNode);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ArrayList(java.util.ArrayList) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 78 with INaviFunction

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

the class CMenuBuilder method addSelectionMenus.

/**
   * Adds menus related to node selection to a given node context menu.
   *
   * @param menu The node context menu to extend.
   * @param graph The graph the clicked node belongs to.
   * @param node The clicked node.
   */
public static void addSelectionMenus(final JPopupMenu menu, final ZyGraph graph, final NaviNode node) {
    Preconditions.checkNotNull(menu, "IE02144: Menu argument can not be null");
    Preconditions.checkNotNull(graph, "IE02145: Graph argument can not be null");
    Preconditions.checkNotNull(node, "IE02146: Node argument can not be null");
    final JMenu selectionMenu = new JMenu("Selection");
    selectionMenu.add(CActionProxy.proxy(new CActionSelectNodePredecessors(graph, node)));
    selectionMenu.add(CActionProxy.proxy(new CActionSelectNodeSuccessors(graph, node)));
    if (graph.getSelectedNodes().size() > 0) {
        selectionMenu.add(CActionProxy.proxy(new CGroupAction(graph)));
    }
    if (node.getRawNode() instanceof INaviCodeNode) {
        try {
            final INaviFunction parentFunction = ((INaviCodeNode) node.getRawNode()).getParentFunction();
            selectionMenu.add(CActionProxy.proxy(new CActionSelectSameParentFunction(graph, parentFunction)));
        } catch (final MaybeNullException exception) {
        // Obviously we can not select nodes of the same parent function if there
        // is no parent function.
        }
    } else if (node.getRawNode() instanceof INaviFunctionNode) {
        final INaviFunction function = ((INaviFunctionNode) node.getRawNode()).getFunction();
        selectionMenu.add(CActionProxy.proxy(new CActionSelectSameFunctionType(graph, function.getType())));
    }
    menu.add(selectionMenu);
    menu.addSeparator();
}
Also used : CActionSelectNodeSuccessors(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectNodeSuccessors) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CActionSelectSameParentFunction(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectSameParentFunction) CGroupAction(com.google.security.zynamics.binnavi.Gui.GraphWindows.Actions.CGroupAction) CActionSelectSameFunctionType(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectSameFunctionType) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) JMenu(javax.swing.JMenu) CActionSelectNodePredecessors(com.google.security.zynamics.binnavi.ZyGraph.Menus.Actions.CActionSelectNodePredecessors)

Example 79 with INaviFunction

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

the class ViewNodeTest method setUp.

@Before
public void setUp() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException, FileReadException {
    ConfigManager.instance().read();
    final MockSqlProvider provider = new MockSqlProvider();
    final Database database = new Database(new MockDatabase());
    final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
    internalModule.load();
    final CTagManager mockTagManager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Root", "", TagType.NODE_TAG, provider))), TagType.NODE_TAG, provider);
    m_nodeTagManager = new TagManager(mockTagManager);
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    final Function function = new Function(ModuleFactory.get(), parentFunction);
    final Module module = new Module(database, internalModule, m_nodeTagManager, viewTagManager) {

        @Override
        public Function getFunction(final INaviFunction internalFunction) {
            return function;
        }

        @Override
        public boolean isLoaded() {
            return true;
        }
    };
    final CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "", "", "", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    final ITreeNode<CTag> tag = mockTagManager.addTag(mockTagManager.getRootTag(), "Initial Tag");
    m_initialTag = m_nodeTagManager.getRootTags().get(0);
    final CView internalView = internalModule.getContent().getViewContainer().createView("", "");
    final CFunctionNode node = internalView.getContent().createFunctionNode(internalFunction);
    node.setColor(Color.MAGENTA);
    node.setX(10);
    node.setY(20);
    node.tagNode(tag.getObject());
    m_view = module.getViews().get(2);
    m_node = (FunctionNode) m_view.getGraph().getNodes().get(0);
    final CFunctionNode node2 = internalView.getContent().createFunctionNode(internalFunction);
    internalView.getContent().createEdge(node, node2, EdgeType.INTER_MODULE);
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Before(org.junit.Before)

Example 80 with INaviFunction

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

the class FunctionNodeTest method testSetComment.

@Test
public void testSetComment() throws CouldntLoadDataException, CouldntLoadDataException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException, LoadCancelledException {
    final MockSqlProvider provider = new MockSqlProvider();
    final Database database = new Database(new MockDatabase());
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
    internalModule.load();
    final CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    final CView internalView = internalModule.getContent().getViewContainer().createView("", "");
    @SuppressWarnings("unused") final CFunctionNode internalFunctionNode = internalView.getContent().createFunctionNode(internalFunction);
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Function function = new Function(ModuleFactory.get(), internalFunction);
    final Module module = new Module(database, internalModule, nodeTagManager, viewTagManager) {

        @Override
        public Function getFunction(final INaviFunction internalFunction) {
            return function;
        }

        @Override
        public boolean isLoaded() {
            return true;
        }
    };
    module.load();
    final View view = module.getViews().get(2);
    final FunctionNode node = (FunctionNode) view.getGraph().getNodes().get(0);
    final MockFunctionNodeListener listener = new MockFunctionNodeListener();
    node.addListener(listener);
    final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Fark"));
    node.initializeComment(comment);
    assertEquals("initializedComment;", listener.events);
    assertEquals(comment, node.getComment());
    node.removeListener(listener);
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Test(org.junit.Test)

Aggregations

INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)94 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)39 Test (org.junit.Test)38 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)26 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)20 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)16 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)16 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)14 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)14 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)12 ArrayList (java.util.ArrayList)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)11 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)10 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)9 HashMap (java.util.HashMap)9 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)8 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)8 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)8