Search in sources :

Example 6 with INaviCodeNode

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

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

the class CSteppingHelper method getAddress.

/**
 * Determines the start address of a node.
 *
 * @param node Node whose address is determined.
 *
 * @return The start address of the given node or null if the node does not have an address.
 */
private static BreakpointAddress getAddress(final INaviViewNode node) {
    if (node instanceof INaviCodeNode) {
        final INaviCodeNode ccnode = (INaviCodeNode) node;
        final INaviInstruction instruction = Iterables.getFirst(ccnode.getInstructions(), null);
        return new BreakpointAddress(instruction.getModule(), new UnrelocatedAddress(instruction.getAddress()));
    } else if (node instanceof INaviFunctionNode) {
        final INaviFunction function = ((INaviFunctionNode) node).getFunction();
        final INaviModule module = function.getModule();
        return new BreakpointAddress(module, new UnrelocatedAddress(function.getAddress()));
    } else {
        // Node types we can not step to
        return null;
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 8 with INaviCodeNode

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

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

the class CGraphInliner method inlineAll.

/**
 * Inlines all function calls of a given graph.
 *
 * @param parent Parent window used for dialogs.
 * @param container Contains the functions to be inlined.
 * @param graph Graph where the inline operation takes place.
 */
public static void inlineAll(final JFrame parent, final IViewContainer container, final ZyGraph graph) {
    Preconditions.checkNotNull(parent, "IE02285: Parent argument can not be null");
    Preconditions.checkNotNull(container, "IE02286: Container argument can not be null");
    Preconditions.checkNotNull(graph, "IE02287: Graph Argument can not be null");
    final MutableDirectedGraph<INaviViewNode, INaviEdge> mutableGraph = (MutableDirectedGraph<INaviViewNode, INaviEdge>) graph.getRawView().getGraph();
    final List<INaviViewNode> nodes = mutableGraph.getNodes();
    final HashMap<INaviInstruction, INaviFunction> instructionToFunctionMap = new HashMap<INaviInstruction, INaviFunction>();
    for (final INaviViewNode iNaviViewNode : nodes) {
        if (iNaviViewNode instanceof INaviCodeNode) {
            instructionToFunctionMap.putAll(CReferenceFinder.getCodeReferenceMap((INaviCodeNode) iNaviViewNode));
        }
    }
    for (final INaviInstruction iNaviInstruction : instructionToFunctionMap.keySet()) {
        INaviCodeNode updatedNode = null;
        for (final INaviViewNode iNaviViewNode2 : graph.getRawView().getGraph().getNodes()) {
            final INaviCodeNode codeNode = (INaviCodeNode) iNaviViewNode2;
            if (codeNode.hasInstruction(iNaviInstruction)) {
                updatedNode = codeNode;
            }
        }
        if (updatedNode != null) {
            inlineFunctionSilently(parent, container, graph, updatedNode, iNaviInstruction, instructionToFunctionMap.get(iNaviInstruction));
        } else {
            throw new IllegalStateException("IE01174: Graph final has been rendered final to an final inconsitant state");
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) HashMap(java.util.HashMap) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 10 with INaviCodeNode

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

the class CCodeNodeMenu method addOperandTreeNodeMenu.

/**
 * Adds menus for the clicked operand.
 *
 * @param model The graph model that provides information about the graph.
 * @param treeNode The clicked operand node.
 * @param extensions The extension menu items for the "Operands" menu.
 * @param instruction The instruction that was clicked.
 * @param node The basic block that contains the clicked instruction.
 */
private void addOperandTreeNodeMenu(final CGraphModel model, final COperandTreeNode treeNode, final NaviNode node, final INaviInstruction instruction, final List<ICodeNodeExtension> extensions) {
    final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
    final INaviModule module = model.getViewContainer().getModules().get(0);
    // We only show the goto address if we have no associated type instance for the given immediate.
    if (treeNode.getType() == ExpressionType.IMMEDIATE_INTEGER && treeNode.getTypeInstanceReferences().isEmpty()) {
        addImmediateOperandMenu(treeNode, module.getContent().getSections(), module);
    }
    if (treeNode.getType() == ExpressionType.REGISTER) {
        addRegisterOperandMenu(model, treeNode, instruction, extensions, codeNode);
    }
    final INaviReplacement replacement = treeNode.getReplacement();
    // precedence over type instances.
    if (!treeNode.getTypeInstanceReferences().isEmpty() && !(replacement instanceof CFunctionReplacement)) {
        addInstanceReferenceMenu(model, treeNode);
    }
    if (replacement instanceof CFunctionReplacement) {
        addFunctionOperandMenu(model, replacement);
    }
}
Also used : CFunctionReplacement(com.google.security.zynamics.binnavi.disassembly.CFunctionReplacement) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) INaviReplacement(com.google.security.zynamics.binnavi.disassembly.INaviReplacement)

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